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

Part 1: (10 Marks) True/ False Questions T/F 1

h

Uploaded by

younis77zl7
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)
8 views5 pages

Part 1: (10 Marks) True/ False Questions T/F 1

h

Uploaded by

younis77zl7
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

Sana’a University ‫جامعة صنعاء‬

Faculty of Computer & IT ‫كلية الحاسوب وتكنولوجيا المعلومات‬


Programming 2 2 ‫برمجة‬
Date: - -2021, Time: Two hours
‫ اوراق‬5 ‫تتكون ورقة االسئلة من‬

Part 1: (10 marks) True/ False Questions T/F

1 If we declare three variables x, y, and z. This statement cin>>x>>y>>z; is same as the


following statements:
cin>>x; cin>> y; cin>> z;
2 Compiler can catch logical errors.
3 A program is used to divide complicated functions into small manageable programs.
4 Predefined functions are organized into separate libraries
5 In function prototype, it is necessary to specify the variable name in the parameter list.
6 C++ does not allow programmers to define a function inside a another function.
7 Function stub is a function that is not fully coded.
8 typedef does not create any new data types
9 An array is a simple data type.
10 int list1[]={1,2,3}; int list2[]={1,2,3}; can we assign list2 directly to list1
like below
list1=list2;

Part 2: (30 marks) Multiple Choices


1 To use showpoint, a programmer should include the following header file:

a. iostream b. iomanip
c. ioformat d. iopoint
2 What is the unnecessary option in order to use a function?

a. Name of the function b. data type of each parameter, if any


c. function process d. data type of the returned data
3 What is the incorrect option for calling the below function

int test(int x, int y){ return x+y; }

a. cout<<test(4,5); b. return test(2,6);


c. int x= test(5,4); d. test(4,5) + 7;
4 void test(int x, y){ int z; z=x+y; cout<<z; }
What is the correct option?

a. x and y are formal parameters b. x and y are actual parameters


c. z is a formal parameter d. z is an actual parameter

1
Sana’a University ‫جامعة صنعاء‬
Faculty of Computer & IT ‫كلية الحاسوب وتكنولوجيا المعلومات‬
Programming 2 2 ‫برمجة‬
Date: - -2021, Time: Two hours

5 What is the incorrect option when a return statement executes?

a. Function immediately terminates b. Control goes back to the caller


c. passes the returned value outside the d. Control goes to the next statement inside the
function function
6 What is the correct option that allows function to return more than one value?
a. return x, y; b. return (x, y);
c. return x; return y; d. None of the above
7 What is the option that makes the global variable inaccessible by a function?

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. Constant variable b. Static variable


c. Automatic variable d. Global variable
9 What is the incorrect option for function overloading of the following function:

int test(){ return 7;}

a. int test(int x) {return x;} b. int test(int x, int y){return x+y;}


c. float test(int x){return x;} d. int test(float x){ return 5;}
10 _________ can be passed as parameters to functions by reference only?

a. float data type b. enumeration type


c. array d. struct variable
11 struct is a collection of ___________?

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 ________?

a. enum type b. struct type


c. array type d. None of the above

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;

What is the incorrect option?

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

15 What is the correct output of the following program?


#include<iostream.h>
int main()
{
int matrix[3][3]={
{1,1,10},
{2,20,2},
{30,3,3}};
for(int row = 0; row < 3; row++)
{
int test = matrix[row][0];
for (int col = 1; col < 3; col++)
if (test < matrix[row][col])
test = matrix[row][col];
cout << row + 1 << test <<” ”;
}
}
a. 10 20 30 b. 30 20 10
c. 111 221 331 d. Error
Part 3: (20 marks)
Chose the correct output
1 #include<iostream>
using namespace std;
int Fun(int x, int y)
{
if(x>=4)
return x, x+y;
else
return y; return x;
}
int main()
{
cout<<Fun(9,4)<<endl;
}
a. 9 b. 4 c. 13

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

Wish you the best of Success Ibrahim Al-Baltah

You might also like