123UGRD-ITE6200A Computer Programming 1
123UGRD-ITE6200A Computer Programming 1
(x = 4 && y = 5) ? (a = 5) ; (b = 6);
If there is more than one statement in the block of a for loop, which of the following
must be placed at the beginning and the ending of the loop block?
a. braces{}
a. for
c. i = i + 1;
In a group of nested loops, which loop is executed the most number of times?
b. do-while
Each pass through a loop is called a/an -
b. iteration
2
n array can contain how many kinds of elements ?
Array is defined as -
d.
An array is a series of elements of the same type in contiguous memory locations
a. std namespace
a. Randomly
b. array array[10];
if you have to make decision based on multiple choices, which of the following is best
suited?
c. if-else-if
In situations where we need to execute body of the loop before testing the condition,
we should use_____.
c. do-while loop
What is the way to suddenly come out of or quit any loop in C++?
c. break; statement
What is the index variable for the element at the first row and first column in array?
c, a[0][0]
3
Output of the this program will be _____
#include
using namespace std;
int main ()
{
int array[] = {0, 2, 4, 6, 7, 5, 3};
int n, result = 0;
for (n = 0 ;n < 8 ;n++) {
result += array[n];
}
cout << result;
return 0;
}
d. 27
Output of this program will be ____?
#include
using namespace std;
int main()
{
char str[5] = “ABC”;
cout << str[3];
cout << str;
return 0;
}
b. ABC
What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<is_array<int>::value;
cout<<is_array<char[10]>::value;
cout<<is_array<string>::value;
return 0;
}
b. 010
What is the index number of the last element of an array with 9 elements?
d. 8
a. x,15
Fill in the blanks to enter five numbers from the user and print their sum. Store the sum in
the variable named total.
int x = 1;
int number;
int total = 0;
_______ (x <= 5) {
cin >> number;
_______= total + number;
x++;
}
cout << "Sum: " << _____ << endl;
d. if, else
Fill in the blanks to test the value of the variable x; if x is 2, print "it's 2" to the screen;
otherwise (the default case), print "the default case" to the screen.
int x;
cin >> x;
switch (____) {
case 2:
cout << "it's 2" << endl;
break;
______:
cout << "the default case" << endl;
}
b. x, default