0% found this document useful (0 votes)
20 views

Quiz 5

Uploaded by

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

Quiz 5

Uploaded by

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

QUIZ CSC430

1. Given a function prototype:

double calcSalary(int workDay, double rate);

Which of the following statement regarding function is CORRECT?


A. char salary = calcSalary(24, 36.72);
B. double salary = calcSalary (24, 36.72);
C. double salary = calcsalary(24, 36.72);
D. calcsalary(24 & 36.72);

2. Which of the following is a VALID function heading?


A. one (int a, int b)
B. int thisone (char x)
C. char another (int a, b)
D. double anotherone

3. Which of the following statement is TRUE?


A. A value-returning function can return several values
B. Every user-define function must return a value
C. The C++ system allows only user-define functions
D. When a function exit, the control goes back to the caller

4. Show the output display by the statement.

A. 4
B. 7
C. 9
D. 16

5. What is the output of the following program?

int kira(int c, int a, int b)


{
return c-a*b;
}
main()
{
int a=2, b=3, c=4, num;
num=kira(a,b,c);
cout<<num;
}

A. -10
B. -2
C. 10
D. 2
6. Which of the following is a VALID function prototype for a C++ program that
receives an integer number and returns an integer number?

I. int f1 (int);
II. void f1 (int &);
III. void f1(int, int &);

A. I and II.
B. I and III
C. I only.
D. I, II and III

7. What is the output of the following program segments?

void Demo(int& intVal, double doubleVal)


{
intVal = intVal * 2;
doubleVal = double (intVal) + 3.5;
}
main()
{
int myInt = 20;
float myDble = 4.8;
Demo(myInt, myDble);
cout << "myInt = " << myInt << " and myDble = " <<
myDble;
}

A. myInt = 20 and myDble = 43.5


B. myInt = 20 and myDble = 4.8
C. myInt = 40 and myDble = 4.8
D. myInt = 40 and myDble = 43.5
8. Given the following code fragment:

int number;
cin >> number;
if (functionX(number) == 1)
cout << “This is an odd number”;
else
cout << “This is an even number”;

Which of the following the most suitable function prototype for the
functionX()?
A. int functionX();
B. void functionX(float);
C. void functionX(int);
D. int functionX(int);

9. Which of the following is a valid function prototype for a C++ program that
receives two integer values and a float value and returns a float number for
function f3?
A. int f3 (int, int, float);
B. float f3 (int, int, float);
C. void f3 (int, int, float);
D. float f3 (int, int);

10. What is the output of the following program segment?

char code[6] = "A5721";


switch(code[0])
{
case 'A': cout« "It is a grade A product." «endl;
break;
case ' B' : cout« "It is a grade B product." <<endl;
break;
default: cout<< "Code cannot be found!" «endl;
}

A. It is a grade C product.
B. It is a grade B product.
C. It is a grade A product.
D. No output
11. Given the following declaration:

int myArray [ 3 ] = { 4, 2, 7 };

Which of the following array statement is syntactically WRONG?


A. cout<<myArray[myArray[1] ] ;
B. cout<<myArray[1 + 1] + 1;
C. cout<<myArray[1.1];
D. cout<< 1 + myArray[2];

12. Trace the output of the following program segment.

char w[10] = "banana";


w[7] = w[1] ;
w[6] = w[4] ;
cout<< w «endl;

A. banana
B. bananan
C. bananana
D. banananan

13. Show the output of the following program segment.

int y[] = {4, 5, 2, 6, 8, 3, -2};


float w = y[1] + y[4];
cout << w;

A. 3
B. 10
C. 11
D. 13

14. What is the correct statements for the following declaration of C++ program?

char name [16];

I. Maximum string in array name is 15 elements.


II. There are 16 components in array name.
III. If you store a string of length 10 in name, first 11 components of name are
used.
IV. If you store a string of length 10 in name, last 5 components of name are
unused.

A. I and II
B. Ill and IV
C. II, III and IV
D. I, II, III and IV
15. Which of the following statements is TRUE about the number 10 used in the
program segments?
int list1[10]; //statement 1

list2[10] = 15; //statement 2

A. In statement 1, 10 specifies the array size, whereas in statement 2, it


specifies a particular element of array.
B. In statement 1, 10 specifies a particular element of array, whereas in
statement 2, it specifies the array size.
C. In statement 1, 10 specifies a particular element of array, whereas in
statement 2, it specifies the array content.
D. In both statements, 10 specifies an array size.

16. What is the output of the following program segments?


int temp[5];
for (int i = 0; i < 5; i++)
temp[i] = 2 * i - 3;

temp[1] = temp[4];
temp[4] = temp[2];
temp[2] = temp[3] + temp[1];

for (int i = 0; i < 5; i++)


cout << temp[i] << " ";

A. 3 -1 8 4 5
B. -3 4 8 5 1
C. 3 4 8 -1 5
D. -3 5 8 3 1

17. Compute and display the value of z.

int a[] = {9,3,8,-2,8};


int b[] = {2,9,7,4,-1};
int z = a[2] + b[3] ;
cout << z;

A. 12
B. 11
C. 10
D. 9
18. Determine the output of the following program segment.

int array1[] = {1200, 200, 2300, 1230, 1543};


int array2[] = {12, 14, 16, 18, 20};
int temp, result = 0;

for (temp = 0; temp < 5; temp=temp+1)


result = result + array1[temp];

for (temp = 0; temp < 4; temp=temp+1)


result = result + array2[temp];

cout << result;

A. 6533
B. 6553
C. 6353
D. 6522

19. Which of the following statements declare a string called name that is able to hold
up to 19 characters?
A. char name;
B. char name = 20;
C. char name[20];
D. char[20] name;

20. Given the following array declaration:

float fscore[SIZE] = {45.6, 68.3, 75.4, 88.0, 23.4, 100.0};

Which of the following statements is TRUE to describe about an array?

i. The size of the array is 5


ii. The array is named as fscore
iii. The index of last element is 5

A. i and ii
B. i and iii
C. ii and iii
D. All of the above

You might also like