The document contains multiple choice questions about C++ concepts such as data types, operators, input/output, functions, and arrays. It asks the value of variables after code snippets execute and the output of code snippets given inputs. It also contains questions about C++ syntax, keywords, and valid code.
The document contains multiple choice questions about C++ concepts such as data types, operators, input/output, functions, and arrays. It asks the value of variables after code snippets execute and the output of code snippets given inputs. It also contains questions about C++ syntax, keywords, and valid code.
What is the output of the following C++ code? int alpha[5] = {2, 4, 6, 8, 10}; int j; for (j = 4; j >= 0; j--) cout << alpha[j] << " "; cout << endl;
A loop that continues to execute endlessly is called a(n) ____ loop.
What is the output of the following C++ code? num = 10; while (num > 10) num = num - 2; cout << num << endl;
After the execution of the following code, what will be the value of num if the input value is 5? cin >> num; if (num > 0) num = num + 10; else if (num == 5) num = num + 15;
Suppose j, sum, and num are int variables, and the input is 26 34 61 4 -1. What is the output of the code? sum = 0; cin >> num; for (int j = 1; j <= 4; j++) { sum = sum + num; cin >> num; } cout << sum << endl;
Suppose that str1, str2, and str3 are string variables. After the following statements above execute, the value of str3 is "____". str1 = "abc"; str2 = "xyz"; str3 = str1 + '-' + str2;
The ____ function is used to interchange the contents of two string variables.
In C++, the following character '/0' represents ____.
The value of the expression 17 % 7 is ____.
What is the value of alpha[4] after the following code executes? int alpha[5]; int j; alpha[0] = 2; for (j = 1; j < 5; j++) alpha[j] = alpha[j 1] + 3;
A variable listed in a function call is known as a(n) ____ parameter. A variable list in a header is known as a(n) ____ parameter.
Suppose that x is an int variable. Which of the following expressions always evaluates to true?
Given int one; double two; bool four; which of the following assignments are valid? (i) one = 7 * 3 % 4; (ii) 2.3 + 3.5 = two; (iii) four = (2 <= 3);
What is the value of alpha[2] after the following code executes? int alpha[5]; int j; for (j = 0; j < 5; j++) alpha[j] = 2 * j + 1;
Suppose x and y are int variables. Consider the following statements. if (x > 5) y = 1; else if (x < 5) { if (x < 3) y = 2; else y = 3; } else y = 4; What is the value of y if x = 6?
Which of the following function prototypes is not valid? int funexp(intx,intv); int funexp(intx,intv){};???? ?? funexp(void); int funexp(void);
Which of the following is NOT a reserved word in C++? int cons? num???? ??
Assume all variables are properly declared. What is the output of the following C++ code? num = 100; while (num <= 150) num = num + 5; cout << num << endl;
What is the output of the following C++ code? x = 0; if (x < 0) {cout << "One "; cout << "Two ";} cout << "Three";
What is the output of the following C++ code? int x = 1; do { cout << x << " "; x--; } while (x > 0); cout << endl;
Suppose that gamma is an array of 50 components of type int and j is an int variable. Which of the following for loops sets the index of gamma out of bounds
The declaration int a, b, c; is equivalent to which of the following? ???? int a;intb;intc;
Given the following function prototype: int test(float, char); which of the following statements is valid?
Considering the statement string str = "Gone with the wind";, the output of the statement cout << str.find("the") << endl; is ____.
Which of the following correctly declares and initializes alpha to be an array of 4 rows and 3 columns and the component type is int?
Given the function prototype: float test(int, int, int); which of the following statements is legal?
Suppose that x = 25.67, y = 356.876, and z = 7623.9674. What is the output of the following statements? cout << fixed << showpoint; cout << setprecision(2); cout << x << ' ' << y << ' ' << z << endl;
In C++, the scope resolution operator is ____. Suppose that sum and num are int variables and sum = 5 and num = 10. After the statement sum += num++; executes ____.
When the function executes, any changes made to the formal parameters passed by value do not in any way affect the ____ parameters.
Which of the following is a relational operator?
Suppose x is 5 and y is 0. Choose the value of the following expression: (x != 7) && (!y)
What is the value of x after the following satements execute? int x; x = (5 <= 3 && 'A' < 'F') ? 3 : 4;
What is the output of the following code fragment if the input value is 4? int num; int alpha = 10; cin >> num; switch (num) { case 3: alpha++; break; case 4: case 6: alpha = alpha + 3; case 8: alpha = alpha + 4; break; default: alpha = alpha + 5; }
Suppose that you have the following function. void mystery(int& one, int two) { int temp
temp = one; one = two; two = temp; } What are the values of x and y after the following statements? (Assume that variables are properly declared.) x = 10; y = 15; mystery(x, y);
Consider the following statement. int y = !(12 < 5 || 3 <= 5 && 3 > x) ? 7 : 9; What is the value of y if x = 2?
Suppose that x = 87 and y = 423. What is the output of the following statements? cout << "12345678901234567890" << endl; cout << setw(5) << x << left << setw(5) << y << setw(7) << "Sunny" << endl;
Suppose that ch1, ch2, and ch3 are variables of the type char and the input is: A B C What is the value of ch3 after the following statements execute? cin.get(ch1); cin.get(ch2); cin.get(ch3);
If a formal parameter is a non-constant reference parameter, its corresponding actual parameter during a function call must be a(n) ____.
Consider the following declaration. char charArray[51]; char discard; Assume that the input is: Hello There! How are you?
What is the value of discard after the following statements execute? cin.get(charArray, 51); cin.get(discard); ???? ????
Suppose that x and y are int variables. Which of the following is a valid input statement?
The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.
Suppose that nameStr is a character array of size 21. Which of the following statement is valid in C++? (i) if (strcmp(nameStr, "Lisa") == 0) cout << nameStr << endl; (ii) if (nameStr[0] == 'L') cout << nameStr[0] << endl;
Consider the statement int list[10][8];. Which of the following about list is true?
Suppose that x is an int variable, y is a double variable and ch is a char variable and the input is: 15A 73.2 Choose the values after the following statement executes: cin >> x >> ch >> y;
Assume that alpha is a character array of size 20. Which of the following statements is illegal in C++? - 1 - Answer all questions Q1. Write a one line C++ statement to do the following: a. An infinite while loop, without any statement inside the while loop block, using the expression (x < 10) as the decision maker, not x is declared as in integer?. b. Declare a character array to a store a name of a student of 30 character maximum for 100 students? c. A call to function fctx which return no value- the call passes the array student with is declared as int students (5) (10)? Assume all needed variables are declared". d. In the previous question, what would be the function declaration/header. e. Declares the integer array test- score (100) and initializes only the first element of the array to 10?
Q.2. given the following structure that contains the social security number and the year ob birth: Struct into (unsighed long soc sec/num). Unsigned int year birth). a. Write a structure called Boo di that contains the following members: info structure, name of type, string. b. write a function named initialize info that takes no parameters but return a structure of type info in which the social security number is initialized to 5511, the name is initialized to Ahmed, and the year to 1986. c. Write a main function (including all necessary header files and other parameters) to declare an identifier of type Boo di, initialize, Boo Di by calling the function initialize info. - 2 - Multiple choice: Identify the letter of the choice that best complete the statement or answers the question. 1. Which of the following is not a valid C ++ identifier? a. stop and go. b. salary for the month. c. hello three. d. My counter.
2. which of the following is a reserved word in C++? a. char. b. char. c. CHAR. d. None of these. 3. The value of the C++ expression 14/4 + 4.3 is: a. 7 b. 7.3 c. 7.8 d. none of these.
4. Suppose that alpha is a double variable. What is the value of alpha after the following statement executes: a. alpha 14.0 + static- cast < double> (15/2): a. alpha = 21.0. b. alpha = 21.5. c. alpha = 22.0. d. none of these.
- 3 - 5. Suppose that X and y are int variables, ch is a char variable, and the input is 4 2 A 12.
What is the value of x, y, and Ch after the following statement executes <in >> x >> ch>>y, a. x = 4, ch = 2, y= 12. b. x 4, ch= A, y = 12. c. x = 4, ch = ', y = 2. d. this statement results in input failure.
6. Suppose that X = 55.68, y = 476,859 and z = 23, 8216, what is the output of the following statement? Cout << fixed<< showpoint. Cout << setprecision (3). Cout << x << << y << setprecision (2) << z << end1". a. 55.680 476,859 23,82. b. 55.690 476, 860 23.82. c. 55.688, 476, 23.82. d. None of these.
7. Suppose that X = 32, y = 62.93, and Z = 781.92. what is the output of the following statements" Cout << fixed<< showpoint. Cout << setprecision (3). Cout << x << << y << setprecision (2) << z << end1". Cout << setprecision (3). a. 123456789102348901234567890. Hi 32 62.93 781.92. b. 123456789012345678901234567890. - 4 - Hi 32 62.93 781.92. c. 12345678901234567890j. Hi 32 62.93 781. 92. d. None of these.
8. after the execution of the following code, what will be the value of num ifthe input values are 4 5 ? Cin >> num. If (num > 0). Num = num > 5). Num = num + 15'. a. 4. b. 5. c. 14. d. 15.
9. What is the output of the following C ++ code ? Int x = 35, Int y = 45. Int z, If (x > y). Z = x + y1 Else Z = y x Cout << x << " << y <<" << z<< end1". a. 35 45 80. b. 35 45 10. c. 35 45 10. d. none of these. - 5 -
10. What is the output of the following code fragment if the input value is 4? Int num' Int alpha = 10. Cin >> num, Switch (num). Case 3: alpha ++. Break; Case 4: Case 6: alpha = alpha + 3. Case 8: alpha + 4. Break, Default: alpha = alpha + 5'. Cout << alpha << endl' a. 13. b. 14. c. 15. d. 17.