0% found this document useful (0 votes)
43 views5 pages

C++finalPL Final A

C++ lecture

Uploaded by

Adham Aljeady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

C++finalPL Final A

C++ lecture

Uploaded by

Adham Aljeady
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Philadelphia University Summer Semester 2022/2023

Faculty of Engineering and Date:- 07/09/2023


Technology Allowed time:- 75 Minutes
Electrical Engineering Department Num of Pages: 5
Programming Language (610263) MidTerm Exam (Theoretical - A)

:‫ الرقم الجامعي‬........................................................................ :‫اسم الطالب‬


.......................................
Question Practical
Q1 / 4 Q2 / 4 Q3 / 7 Q4 / 6 Q5 / 4 Total / 30
Q6 /15
Points

Question 1: Choose the correct answer for the following questions.


4 Points

1. In C++ defining multiple functions in the same name is called


function _______________
A. Redefining B. Overnaming C. Overlapping D. Overloading

2. Which of the following is a valid C++ function definition?


A. B.
void Test(int& u, double& v) void Test(int& u, double& v);
{ {
cout << u << " " << v << endl; cout << u << " " << v << endl;
} }

C. D.
void Test(int& u, double& v) void Test(int& u, double& v)
( [
cout << u << " " << v << endl; cout << u << " " << v << endl;
) ]

3. A is an Array of 13 elements Which of the followings will


correctly display it.
A) for(int i=0;i<14;i++) B) for(int i=0;i<=12;i++)
cout<<A[i]; cout<<A[i];

C) for(int i=1;i<14;i++) D) for(int i=0;i<=13;i++)


cout<<A[i]; cout<<A[i];

4. Which of the following is the "and" operator?


A) ! B) || C) != D) &&
Question 2: Marks the following statements as True or False.
4 Points
1. The variable names firstName and FirstName are the same. F
2. The operator that perform multiplication and assignment is(*=).T
3. Executing continue statement in a loop will terminates the loop F
4. The Loop for(int i=10;i>=10;i++) is an infinite loop. T

Question 3: What is the output of the following pieces of code.


7 Points
Code Output
int x=6,y=4,c=2;
8
cout<<x+y/c<<endl;
cout<<x/y-c<<endl; -1

char ch='b';
int a=6;

if(ch>'B'||a==5)
cout<<1111<<endl;
1111
else
cout<<2222<<endl;
4444
if(ch<'a'&&a==6)
cout<<3333<<endl;
else
cout<<4444<<endl;
int z=3,a=9;
while(a<13)
{
0
cout<<a%z<<endl;
a+=2; 5
z+=3;
}
float x=0.5,sum=0;
do
{
sum+=x;
0.5
x*=3;
} 1.5
while(x<0);
cout<<sum<<endl;
cout<<x<<endl;
Code Output

float Arr[6]={-3,2.5,6,9,-3,-5};
for(int i=1 ; i<6 ; i+=2) 1
{ 3
cout<<i<<endl; 5
}

bool Test(int x)
{
if( x>3 && x<6 )
return true;
else
return false;
0
}
void main() 1
{
int n1=1 , n2=5;
cout<< Test( n1 )<<endl;
cout<< Test( n2 )<<endl;
}

int Test(int x)
{
static int c=2;
c++;
return x*c;
}
3
void main()
{ 8
int n=1;
cout<< Test( n ) << endl;
cout<< Test( n + 1 ) <<
endl;
}
Question 4: Find the Errors (Logical or syntax)in the following
pieces of code then correct them. 6 points
Code Correction
int Arr[3][3]={{1,2},{4,5,6}};
for(int i=0;i<=3;i++)
{
for(int j=0;j<=3;j++)
i<3
{
cout<<Arr[i][j];
}
}
float fun(int x) float fun(int x)
{ {
float b; float b;
b=(x*5+3)/x; b=(x*5+3)/x;
} return b;
void main() }
{
cout<<fun(5);
}
int x , y =5; x= 0
while ( y <= 10 ) while ( y <= 10 )
y = x + 2; { y = x + 2;
x++; x++;
cout << y; }
int A[5]={3,5,6,4,1}; int i=0;
int i;
while(i<5)
{ A[i]+=5;
i++;
}
for( int x = 0 ; x <= 10 ; x++); for( int x = 0 ; x <= 10 ; x++)
{
Cout<< x <<endl;
}

float a=3.5; 2<a && a<10


if(2<a<10)
cout<<5*x<<endl;
else
cout<<6*x;
Question 5: Perform the following tasks assume all variables are
probably declared and initialized. 4 Points

Rewrite the following using int sum=0,x=1;


for statements for(x=1;x<=5;x++)
int sum=0,x=1; {
do sum+=x*x;
{ }
sum += x*x;
x++;
}
while(x<=5);

Write a C++ statement to


calculate
the following:

1 𝑠 R=1/(pow(s,2)-6)+s/(s+1);
𝑅= +
𝑠2 − 6 𝑠 + 1

You might also like