Write a program step by step. Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance.

Slides:



Advertisements
Similar presentations
C++ Introduction.
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 1 Engineering Problem Solving.
An Introduction to Programming By :- Vishal Hirani B.Tech II year (CSE)
C Language.
Fundamentals of Computer and programming in C Programming Languages, Programs and Programming Rohit Khokher.
Software Development Method. Assignments Due – Homework 0, Warmup Reading – Chapter 2 –
Chapter 6: User-Defined Functions I
CS211 Data Structures Sami Rollins Fall 2004.
Guide To UNIX Using Linux Third Edition
CS 101 Problem Solving and Structured Programming in C Sami Rollins Spring 2003.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
6 Steps of the Programming Process
Chapter Introduction to Computers and Programming 1.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
Basics Programming Concepts. Basics A computer program is a set of instructions to tell a computer what to do Machine language = circuit level language.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
CSCI 171 Presentation 1. Computer Software System Software –Operating systems –Utility programs –Language compilers Application Software.
CSCI 130 Chapter 1. History of C Bell Telephone Laboratories (1972) Dennis Ritchie (also created UNIX) A - B - C.
CMSC 104, Version 9/011 Incremental Programming Topics Review of Incremental Programming Example of Incremental Programming Reading None.
Computer Programming A program is a set of instructions a computer follows in order to perform a task. solve a problem Collectively, these instructions.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Creating your first C++ program
Computer Science 101 Introduction to Programming.
1 Programming in C Hello World! Soon I will control the world! Soon I will control the world!
I Power Higher Computing Software Development Development Languages and Environments.
Chapter Three The UNIX Editors.
CGS3460 Summer 2011 Programming Using C Andrei Todor.
Khalid Rasheed Shaikh Computer Programming Theory 1.
Agenda Computer Languages How to Write a Simple C Program
How to Program? -- Part 1 Part 1: Problem Solving –Analyze a problem –Decide what steps need to be taken to solve it. –Take into consideration any special.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 6: User-Defined Functions I.
CPS120: Introduction to Computer Science Compiling a C++ Program From The Command Line.
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
Chapter 3: User-Defined Functions I
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 6: User-Defined Functions I.
Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Computer Programming A simple example /* HelloWorld: A simple C program */ #include int main (void) { printf (“Hello world!\n”); return.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 1: Introduction to Computers and Programming.
Software Engineering Algorithms, Compilers, & Lifecycle.
Chapter 5: Preparing C Programs
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter 6: User-Defined Functions I
Computer Science 210 Computer Organization
Chapter 5- Assembling , Linking, and Executing Programs
Completing the Problem-Solving Process
Guide To UNIX Using Linux Third Edition
Getting Started with C.
Lecture Note Set 1 Thursday 12-May-05
CS149D Elements of Computer Science
User-Defined Functions
and Executing Programs
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Writing Methods.
Incremental Programming
1) C program development 2) Selection structure
Govt. Polytechnic,Dhangar
Creating your first C program
Lecture3.
Homework Applied for cs240? (If not, keep at it!) 8/10 Done with HW1?
Our Environment We will exercise on Microsoft Visual C++ v.6
C Programming Language
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Presentation transcript:

Write a program step by step

Step 1: Problem definition. Given the coordinate of two points in 2-D space, compute and print their straight distance

Step 2: Specifying the input and output. Input: coordinates of point one (i.e X1, Y1) and coordinates of point two (i.e X2, Y2) Output: distance between the points. For each of the input and output data you need to declare variables in your program.

Step3: Solving some instances of the problem on paper. Suppose the coordinates of point one is (X1=6, Y1=1) and coordinates of point two is (X2=2, Y2=4). The formula to compute the straight distance between two points given their coordinates is Distance = sqrt( (X1-X2)^2 + (Y1 – Y2)^2). In this example the distance will be: Distance = sqrt( (6-2)^2 + (1-4)^2) = sqrt(4^2 + 3^2) = sqrt(25) = 5.

Step4: Writing the algorithm on paper Declare the input variables X1, Y1, X2, Y2 and output variable distance. Assign some values to the input variable. Compute the distance using the following formula and assign the results in distance. –Distance = sqrt( (X1-X2)^2 + (Y1 – Y2)^2). Print the value of distance on the screen.

Step 5: Write the problem on paper #include int main(void){ /* declaring the input and output variables */ double X1, X2, Y1, Y2; double distance; /* assign some values to the input variables */ X1 = 6; Y1 = 1; X2 = 2; Y2 = 4; /*compute the distance */ distance = sqrt((X1 – X2)*(X1 – X2) + (Y1 – Y2)*(Y1 – Y2)); /*print the results */ printf(“The distance is %f \n“, distance); return 0; }

Step 7: Type the program Use a text editor to type your program. If you are typing your program in Unix you can use emacs, vim and pico. pico is the simplest one. Type pico myprog.c to start. Type in your program and press ctrl+o to save. To exit press ctrl+x. If you want to make some changes to your program after you exit type pico myprog.c

Step 8: compile your program. The next step is to compile your program. Compiling means translating your program from C language to machine language. You need to do this because the system only understands the machine language. Type g++ myprog.c –o myprog to compile your program. g++ is a compiler for C. If your program has syntax errors the compiler will print the appropriate messages on the screen. In such cases go back to your program (by typing pico myprog.c) and fix the problem. If your program is compiled successfully, no error message will be printed and the machine code will be written in the file myprog (with no extension)

Step 9: Test your program. To run your program type./myprog in Unix prompt. Test your program for different input values and see if it will produce the correct output.