Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming is instructing a computer to perform a task for you with the help of a programming language.

Similar presentations


Presentation on theme: "Programming is instructing a computer to perform a task for you with the help of a programming language."— Presentation transcript:

1

2 Programming is instructing a computer to perform a task for you with the help of a programming language.

3 LEGO MINDSTORMS

4 Programming on C++

5 A computer program (software) contains a sequence of instructions for a computer.One program is usually composed of three parts: Input part gets the data from an input device. Our programs, in the book, will get the data from keyboard or from a text file. Process part is the hardest working part of the program. It carries out the algorithm and finds out the desired result. Output part gives the result of the program. Our programs will display the result on the screen or print it into a text file.

6 OUR 1 st PROGRAM Program will write text on screen: START “Hello world!” END

7 #include using namespace std; int main() { cout <<"Hello world!"; system("pause"); return 0; }

8 each C++ statement ends with a semicolon character (';'). Writing comments in the program code- // OR /* */

9 #include //includes the declarations of the basic standard input-output //library in C++, and its functionality is going to be used later //in the program. using namespace std; //Namespaces are containers that contain the declarations of all //the elements of the standard C++ library int main() //the only function in this program. { cout <<"Hello world!"; //print "Hello world!". cout is //declared in the iostream standard //file within the std namespace system("pause"); //Wait until user hits a key and //displays a message return 0; //the main function ends properly }

10 START “5+3=“;5+3 END

11 #include using namespace std; int main() { cout <<"5 + 3 = "<<5+3<<endl; //calculate and print the sum system("pause"); return 0; }

12 Getting Data from the User (Input) "cin" command is used to read data from the standard input

13 Calculating sum of numbers START READ num1, num2 END Sum=num1+num2 PRINT Sum

14 #include using namespace std; int main() { int num1, num2, sum; //num1, num2 and sum are three //variables type of integer. cout<<"Enter two integers:"<<endl; cin >> num1 >> num2; //cin reads two values for //num1 and num2. sum = num1 + num2; //sum gets the value of num1+num2. cout <<"Sum is "<<sum<<endl; system("PAUSE"); return 0; }

15 HOMEWORK Make a program to calculate area and perimeter of a rectangle. Input: length of side1 and length of side2. Process: area = side1*side2 Perimeter = 2*(side1+side2) Output: area and perimeter


Download ppt "Programming is instructing a computer to perform a task for you with the help of a programming language."

Similar presentations


Ads by Google