You are on page 1of 34

Salahaddin University - Erbil

2019-2020
College Of Engineering
Electrical Department
Second stage – Group (A)

Computer Programming/C++
Programming Language
Assignment one

Prepared by/ Supervised by/


Amilia sherzad canoon Mr/Ahmad
Answer the following Questions:
1- Why C++ language is described as middle-level language?
_C++ is called middle-level language because it actually binds the gap between a machine
level language and high-level languages. A user can use c language to do System
Programming (for writing operating system) as well as Application Programming (for
generating menu driven customer billing system ). That's why it is called the middle-level
language. C++ is a general-purpose object-oriented programming language developed by
Bjarne Stroustrup of Bell Labs in 1979. ... C++ is considered a mid-level programming
language, combining some elements of low-level programming languages, such as the
need to learn memory management, with high-level features.

2- Explain shortly, what we mean by saying C++ is a portable language?


_ A portable language is a computer programming language capable of developing
software for more than one computer system. For example, C++ is a portable
language commonly used today. Programming terms.

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.

5- What is (cin & cout) briefly explain?


_ cin is an object of the input stream and is used to take input from input streams like files,
console, etc. cout is an object of the output stream that is used to show output.
Basically, cin is an input statement while cout is an output statement. They also use
different operators.
6- Declare a variable named my-data?
_ DataType My-data;
EX: int My-data;
7- Initialize the variable in question (6)?
My-data=value;
EX:My-data=7;
8- Find the location of the variable in question (6)?
Cout<<”the location of My-data is”<<&My-data<<endl;

#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<<"* Rectangle *"<<endl;

cout<<"* Shape *"<<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

// this is a comment line


# include<iostream.h>
void main()
{
int X;
X=2;
cin>>X;
cout<<”X is equal to “<<X<<endl;
}
3-
#define<iostream.h>
#include PI 3.313567
Void main()
{
int cout,cin;
Cin>>cout;
Cout=cin;
}

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 triangle= "<<Ar<<endl;


}
else

{
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

You might also like