Part 1: (10 Marks) True/ False Questions T/F 1
Part 1: (10 Marks) True/ False Questions T/F 1
a. iostream b. iomanip
c. ioformat d. iopoint
2 What is the unnecessary option in order to use a function?
1
Sana’a University جامعة صنعاء
Faculty of Computer & IT كلية الحاسوب وتكنولوجيا المعلومات
Programming 2 2 برمجة
Date: - -2021, Time: Two hours
a. Declare the variable before the function b. Function name different from the variable
c. All local variables have different names d. None of the above
8 What is the variable type that makes the memory remain allocated as long as the program executes?
a. fixed number of components which can b. fixed number of components of the same
be different data types data type
c. dynamic number of components of d. dynamic number of components of same
different data types data types
12 A function cannot return a value of ________?
2
Sana’a University جامعة صنعاء
Faculty of Computer & IT كلية الحاسوب وتكنولوجيا المعلومات
Programming 2 2 برمجة
Date: - -2021, Time: Two hours
13 Suppose we define the NameType struct, and we declare student1 and student2 variables:
struct NameType{
string first;
string middle;
string last;
}
NameType student1, student2;
a. student1=student2; b. cout<<student1;
c. student1.first> d. NameType s3={“Ahmed”, “Ali”,
student2.first “Mohammed”};
14 What is the correct output of the below program?
#include<iostream.h>
int main()
{
int matrix[3][3]={{1,1,1}, {2,2,2}, {3,3,3}};
for(int i = 0; i < 2; i++)
{
int sum = 0;
for (int j = 0; j < 2; j++)
{
sum = sum + matrix[j][i];
cout << "Sum of " << j + 1 << " = " << sum<< endl;
}
}
}
a. Sum of 1 = 1 b. Sum of 1 = 3
Sum of 2 = 3 Sum of 2 = 1
Sum of 1 = 1 Sum of 1 = 3
Sum of 2 = 3 Sum of 2 = 1
c. Sum of 2 = 1 d. Error
Sum of 1 = 3
Sum of 2 = 1
Sum of 1 = 3
3
Sana’a University جامعة صنعاء
Faculty of Computer & IT كلية الحاسوب وتكنولوجيا المعلومات
Programming 2 2 برمجة
Date: - -2021, Time: Two hours
2 #include<iostream>
using namespace std;
int Fun1(int x=2, int y=20)
{
return x+y;
}
bool Fun2()
{
if(Fun1()>19)
return true;
}
int main()
4
Sana’a University جامعة صنعاء
Faculty of Computer & IT كلية الحاسوب وتكنولوجيا المعلومات
Programming 2 2 برمجة
Date: - -2021, Time: Two hours
{
if(Fun2()==true)
cout<<"Success"<<endl;
else
cout<<"Failure"<<endl;
}
a. Success b. Failure c. Error
3 #include<iostream>
using namespace std;
enum Day{Sa, Su, Mo,Tu, We,Th, Fr};
Day Fun(int x)
{
Day y; y= Su; y= static_cast<Day>(y+x);
return y;
}
int main()
{
switch( Fun(3))
{
case 1:
cout<<"Su"<<endl; break;
case 2:
cout<<"Mo"<<endl; break;
case 3:
cout<<"Tu"<<endl; break;
case 4:
cout<<"We"<<endl; break;
}
}
a. Mo b. Tu c. We
5 #include<iostream>
using namespace std;
int main()
{
double myList[5];
myList[0] = 3.0;
myList[1] = 4.0;
for (int i = 2; i < 5; i++)
{
myList[i] = myList[i - 1] * myList[i - 2];
if (i > 3)
myList[i] = myList[i] / 4;
}
for(int i=0; i<5;i++)
cout<<myList[i]<<” “;
}
a. 3 4 12 48 144 b. 3 4 5 6 7 c. 3 9 27 81