Professional Documents
Culture Documents
2019-2020
College Of Engineering
Electrical Department
Second stage – Group (A)
Computer Programming/C++
Programming Language
Assignment one
3- List the main procedures that a C++ program must passes to be executed?
_ Step By Step Execution Of C++ Program
Step 1 : Edit. This is First Step i.e Creating and Editing Program. ...
Step 2 : Compiling. Compiling C++ Program : C++ Source code with [. ...
Step 3 : Checking Errors. ...
Step 4 : Linking Libraries. ...
Step 5 : Error Checking
4- What is a pre-processor?
_ In computer science, a preprocessor is a program that processes its input data to
produce output that is used as input to another program. The output is said to be a
Tcompilers.
#include <iostream.h>
void main()
{
int my_data; //Q6
My_data=7; //Q7
Cout<<”the location of my_data =”<<&my_data<<endl; //Q8
}
The ouput is
The location of my_data=0x0019FF2C
9- Print the output the Rectangle Shape:
#include <iostream.h>
void main()
{
cout<<"*******************"<<endl;
cout<<"* *"<<endl;
cout<<"*******************"<<endl;
}
The output
*******************
* Rectangle *
* Shape *
* *
10- print the text shown below:
“I am studding C++ Language , I am in second academic year’’
Separate the sentence between two lines?
#include<iostream.h>
void main()
{
cout<<”I am studding C++ Language”<<endl;
cout<<”I am in second academic year”<<endl;
}
The output
I am studding C++ Language
I am in second academic year
11-Write a C++ program to separate the integer part of a floating point
number from the fractional part using only 3 variables, use cin for the
floating point number ?
#include<iostream.h>
#include<math.h>
void main()
{
cout<<"please enter the float number"<<endl;
cout<<"the float number ="<<endl;
double a , b , c ;
cin>>a;
b= floor (a);
c= fmod (a,b);
cout<<"the real part ="<<b<<endl;
cout<<"the float part="<<c<<endl;
}
The ouput
Please enter the float number
The float number=8.9
The real part=8
The float number=0.9
Find Errors and correct them for the following:
write down all the errors you face with the codes below then rewrite it in
correct way.
1-
#include>iostream.h<
Void main()
{
Cout<<”this is C program!!_ <<end _
]
Correct
#include<iostream.h>
void main()
{
cout<<”this is C program!!”<<endl;
}
2-
/this is a comment line
# include<iostream.h>
Void main()
{
INT X;
X=2;
CIN>>x;
Cout<<”x is equal to”<<x<<endl;
}
Correct
Correct
#include<iostream.h>
#define PI 3.313567
void main()
{
int A variable name cannot be keyword (cin,cout)
cin>> A variable name cannot be keyword (cin,cout)
cout= A variable name cannot be keyword (cin,cout)
cout<<” A variable name cannot be keyword (cin,cout)”<<endl;
}
13-write a C++ programm to print your full name ina a first line then your age in
second line , after that print the location address of age in the third line . use
user friendly programming paradigm.
#include<iostream.h>
void main()
{
char a [15] = “Amilia sherzad”;
int b = 19;
cout<<”my full name is “<<a<<endl;
cout<<”my age is “<<b<<endl;
cout<<”the location address of age is “<<&b<<endl;
}
The output
My full name is Amilia sherzad
My age is 19
The location address of age is 0x0019FF1C
15-write a C++ program to find the area of a (rectangular ,square and triangle) in
one program , the dimensions must be variable for the three shapes use user
friendly programming paradigm?
#include<iostream.h>
int main()
{
long double x,y,As,Ar;
cout<<"please enter the value of x"<<endl;
cin>>x;
if (x>0)
{
cout<<"please enter the value of y"<<endl;
cin>>y;
if (y>0)
{
As=(x*y);
Ar=(x*y*0.5);
if (x==y)
{
cout<<"the area of square= "<<As<<endl;
{
cout<<"the area of rectangle="<<As<<endl;
cout<<"the area of tringle="<<Ar<<endl;
}
}
else
cout<<"the value of (y) must be more than 0"<<endl;
}
else
cout<<"the value of (x) must be more than 0"<<endl;
}
The output
The value of x
X=2
The value of y
Y=2
The area of square=4
The area of trinagle=2
The value of x
X=4
The value of y
Y=5
The area of rectangle =20
The area of tringle =10