C++ Programming Club

     Lecture 1
Steps needed for solving a programming
                    problem
Software engineering steps:
• Problem definition & analysis:
    Identifying inputs/outputs of a problem. Develop a list of
    variables & indicate their relationship.

• Algorithm development:
  Pseudo code or flowchart.

• Coding:
  Converting algorithm into a programming language.

• Testing & Debugging
                              (1)
Programming Algorithms

General form of a computer algorithm:
             INPUT → PROCESSING → OUTPUT
Algorithm types: pseudo code & flowchart.

Pseudo code is the steps of an algorithm written in
concise natural language for problem solving.
Example: Ohms law.
1. Start.
2. Input resistor R & voltage V values.
3. Compute current I = V/R.
4. Output I (Current).
5. Stop.
                            (2)
Commands for the C++ preprocessor.
Preprocessor         Lines beginning with # are preprocessor
  Directive                        directives.




                       C++ contains one or more functions,
    Main             the main function must be one of them.
  Function



 Declaration          Within the main function all variables
                       must be declared to the compiler.
   Block



 Statement                Statement block contains the
    Block                     program statements.

               (3)
A SIMPLE C++ PROGRAM        Remarks for program
                                   clearity. These are not
                                          compiled
//A Welcome Messege
                                     It’s a type of pre-
                                   processor directive .It
#include<iostream>                 enable the compiler to
Using name space std;              recognize i/p and o/p.
Void main ()                     Function that accepts
{                                And returns no value.
                                 {} is used for opening
                                 and closing a function.
cout<<“Welcome to C++!”<<endl;
                                 Output statement that
                                 displays text on screen
System (“pause”);                All statements end
}                                with a ;

                                 Written so that the
                                 command prompt does
                                 not quickly disappear but
                    (4)          remains on the screen.
• C++ Data Types




But we shall be only dealing with Interger , Character and
Floating point!
                            (5)
How To Find Out The Force Exerted On
      An Object By Using C++
// Finding out the force
#include <iostream>
using namespace std;
Void main ()
{
   float f,m,a;                           // variables that will be used
cout<<“Please enter the mass:”;          //Displayed on the screen
cin>>m;                                 // First Input
cout<<“Please enter the area:”        // Displayed on the screen
cin>>a;                              //Second Input
f=m*a;                              //Processing
cout<<f<<endl;                     //Output
system (“pause”);
}

                             (6)
• Home Work
1.Write an assignment statement to calculate
the circumference of a circle. The formula for
determining the circumference, c, of a
circle is c = 2*pi*r, where r is the radius and pi
equals 3.1416.
2. Write an assignment statement to convert
temperature in degrees Fahrenheit
to degrees Celsius. The formula for this
conversion is Celsius = 5/9 (Fahrenheit - 32).
                   (7)

C++ Programming Club-Lecture 1

  • 1.
  • 2.
    Steps needed forsolving a programming problem Software engineering steps: • Problem definition & analysis: Identifying inputs/outputs of a problem. Develop a list of variables & indicate their relationship. • Algorithm development: Pseudo code or flowchart. • Coding: Converting algorithm into a programming language. • Testing & Debugging (1)
  • 3.
    Programming Algorithms General formof a computer algorithm: INPUT → PROCESSING → OUTPUT Algorithm types: pseudo code & flowchart. Pseudo code is the steps of an algorithm written in concise natural language for problem solving. Example: Ohms law. 1. Start. 2. Input resistor R & voltage V values. 3. Compute current I = V/R. 4. Output I (Current). 5. Stop. (2)
  • 4.
    Commands for theC++ preprocessor. Preprocessor Lines beginning with # are preprocessor Directive directives. C++ contains one or more functions, Main the main function must be one of them. Function Declaration Within the main function all variables must be declared to the compiler. Block Statement Statement block contains the Block program statements. (3)
  • 5.
    A SIMPLE C++PROGRAM Remarks for program clearity. These are not compiled //A Welcome Messege It’s a type of pre- processor directive .It #include<iostream> enable the compiler to Using name space std; recognize i/p and o/p. Void main () Function that accepts { And returns no value. {} is used for opening and closing a function. cout<<“Welcome to C++!”<<endl; Output statement that displays text on screen System (“pause”); All statements end } with a ; Written so that the command prompt does not quickly disappear but (4) remains on the screen.
  • 6.
    • C++ DataTypes But we shall be only dealing with Interger , Character and Floating point! (5)
  • 7.
    How To FindOut The Force Exerted On An Object By Using C++ // Finding out the force #include <iostream> using namespace std; Void main () { float f,m,a; // variables that will be used cout<<“Please enter the mass:”; //Displayed on the screen cin>>m; // First Input cout<<“Please enter the area:” // Displayed on the screen cin>>a; //Second Input f=m*a; //Processing cout<<f<<endl; //Output system (“pause”); } (6)
  • 8.
    • Home Work 1.Writean assignment statement to calculate the circumference of a circle. The formula for determining the circumference, c, of a circle is c = 2*pi*r, where r is the radius and pi equals 3.1416. 2. Write an assignment statement to convert temperature in degrees Fahrenheit to degrees Celsius. The formula for this conversion is Celsius = 5/9 (Fahrenheit - 32). (7)