Presentation is loading. Please wait.

Presentation is loading. Please wait.

PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.

Similar presentations


Presentation on theme: "PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve."— Presentation transcript:

1 PRINCIPLES OF PROGRAMMING Revision

2 A Computer

3  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve a problem), you have to write a computer program.  The computer program tells a computer, step by step, exactly what you want it to do.  The computer then executes the program, following each step mechanically, to accomplish the end goal.

4 Algorithms  The sequence of steps to be performed in order to solve a problem by the computer  Can be expressed as:  Natural languages  Pseudocode  Flowcharts  Programming Languages

5 Natural Language Direct someone to the Library: 1. Assume the person is at the main gate 2. Take 35 steps to the fountain that overlooks the main gate 3. Walk past the fountain using the steps either to the left or right of the fountain. 4. Take 50 steps following the pavement after the fountain. 5. The building in front of you is the main library

6 Natural Language Example 2 1. Check patient’s temperature 2. Is the temperature less than or greater than 37 degrees? 3. If yes, give a warning 4. If no, let the patient know their temperature is normal

7 Pseudocode Example  Temp = t1  If (t1 37), Warning!  Else  Temp is Normal  OR  Temp = t1  If(t1 ≠37), Warning!  Else Temp is Normal

8 Flow Chart Example No Yes START Read t1 Is t1=37? Temp is Normal Warning! STOP

9 Programming Language  It expresses an algorithm in a way that can be executed by a computer 1.# include 2.using namespace std; 3.int main() 4.{ 5.int t1;//t1 is temperature 6.cout<<“Enter temperature\n”; 7.cin>>t1; 8.if(t1!=37) 9.cout<<“Warning!\n”; 10.else 11.cout<<“Your Temperature is normal\n”; 12.return 0; 13.}

10 Programming Language  Coded language used by programmers to write instructions that a computer can understand to do what the programmer (or the computer user) wants. Read more: http://www.businessdictionary.com/definition/progr amming-language.htmlprogrammerswrite instructionscomputerwants http://www.businessdictionary.com/definition/progr amming-language.html

11 Typical C++ development Environment

12 Understand the C++ Language  Errors  Syntax Errors  Runtime Errors  Logical Errors

13 Printing out a line of text 1. # include 2. using namespace std; 3. int main() 4. { 5. cout<<“Hello World!”; 6. return 0; 7. }

14 Escape Sequences

15 Example Program 2  # include  using namespace std;  int main()  {  int x;  int y;  x=2;  y=4;  cout<<x<<“\t”<<y;  return 0;  }  # include  using namespace std;  int main()  {  int x, y;  x=2;  y=4;  cout<<x<<“\t”<<y;  return 0;  }

16 Example Program 3 1. // Program to add two integers typed by user at keyboard 2. #include 3. using namespace std; 4. int main() 5. { 6. int a, b, total; 7. cout << "Enter integers to be added:" << endl; 8. cin >> a >> b; 9. total = a + b; 10. cout << "The sum is " << total << endl; 11. return 0; 12. }

17 Definition of terms  Variables  Use valid identifiers  Identifier  Sequence of letters numbers/digits and underscores  Data type  int, Char, float, double, string  Declarations  int x;  Initialization  x = 0;

18 Comments  // this comment spans one line  /* this kind of comment is used for more than one line*/  Documentation  For the person reading your code  Not interpreted by the compiler

19 Good Programming practice  Computation statements separated from declaration 1. int a, b, total; 2. cout << "Enter integers to be added:" << endl; 3. cin >> a >> b; 4. total = a + b; 5. cout << "The sum is " << total << endl;  Do not use variables you have not declared

20 Decision Making  If statements  If – else statements  Nested if statements  Equality and Relational operators  Switch

21 Repetition  Loops  While loop  Do- While loop  For loop


Download ppt "PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve."

Similar presentations


Ads by Google