# prog2_ Mid2 ```Majmaah University
College of Science in Zolfi
Dept. of Computer Science &amp; Info.
Name :
‫(برنامج تجسير) البرمجة الشيئية‬
Midterm Exam on C++ OOP
Time: 2 Hr
23-6-1435
ID:
1- What is the correct variable type for storing the following data? Provide meaningful variable names for the
variables into the following table?
1234-
Description
The number of books in a bookshelf
The cost of this book
The number of people in the world
The word Hello
Variable name
`
2- What is the output of the following program?
#include &lt;iostream&gt;
using namespace std;
Outputs:
int main( void )
{
int x = 25;
string str2 = “This is a test\n”;
cout &lt;&lt; ”Test” &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; ”3”;
cout &lt;&lt; 25 %7 &lt;&lt; “\n” &lt;&lt; str2;
return 0;
}
3- Write a program that asks users for their names, that greets them, and that asks
them for two numbers and then provides the sum.
4-
Write a program to calculate the area and circumference of a circle with radius R where :
Circumference= 2
R
and Area =
 R2 , = 3.141592
1
Type
5- What happens when you store 10.3 as an integer? What about 0.6? Can you store
–101.8 as an integer?
6- Complete the following by operators ( = , &gt; , &lt; , ! , == and &amp;)
Max
x
y
?
y :
x
;
Min
x
y
?
y :
x
;
7- Let int x = 5;
int y = 6;
int z = y++;
z = ++x + y;
Output:
cout&lt;&lt; &quot;x=&quot;&lt;&lt; x;
cout&lt;&lt; &quot;y=&quot;&lt;&lt; y;
cout&lt;&lt; &quot;z=&quot;&lt;&lt; z;
8- Write a program
to calculate the sum {1 + 2 + 3 + . . . + N}
9- Write a conditional statement that assigns x * y if x is even; otherwise, if x is odd and y doesn’t equal 0, assign x to
x / y; if neither of the preceding cases is true, output to the screen that y is equal to 0.
10- Write a program to display a multiplication table from 1 to 10, which requires two nested for loops.
2
```