2. 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)
3. 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)
4. 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)
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++ Data Types
But we shall be only dealing with Interger , Character and
Floating point!
(5)
7. 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)
8. âą 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)