Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (TCO 1) Which of the following is a valid C++ identifier? (Points : 5) 2For1

ID: 3532134 • Letter: 1

Question


1. (TCO 1) Which of the following is a valid C++ identifier? (Points : 5)        2For1
       A_+_B
       Two/one
       A_plus_B

2. (TCO 1) Which of the following identifies syntax errors in programs written in a high-level language? (Points : 5)        Assembler
       Compiler
       Preprocessor
       Linker

3. (TCO 1) Suppose a, b, and c are int variables and a=5 and b=6. Find the value of a after this statement executes:

a = (b++) + 3;

(Points : 5)        5
       9
       10
       11

4. (TCO 1) For the values given, what will c contain after executing the following?

int a = 9, b = 4, c = -1, d = 2;
c = --a / b - c * d;

(Points : 5)        1
       4
       -27
       6

5. (TCO 1) A percent sign (%) is called (Points : 5)        the percent operator.
       the modulo operator.
       the divide operator.
       None of the above

6. (TCO 1) What is the result of 56 % 5? (Points : 5)        1
       11
       11.2
       12

7. (TCO 1) What is the output for the following code fragment?

int var1 = 20;
cout << var1--;
cout << ++var1;

(Points : 5)        1920
       1921
       2020
       2021

8. (TCO 1) Which operation in the following expression will be performed first?

c = a++ / b + 5;

(Points : 5)        a++
       a / b
       b + 5
       assignment to c


9. (TCO 2) The endl manipulator _______. (Points : 5)        requires #include <iomanip>
       is used with cout to display a new line
       only works with cin statements
       All of the above

10. (TCO 2) Which of the following would you add to your program to read an entire line of input into a string variable named input? (Points : 5)        cin >> input;
       cin.getline(input);
       getline(cin, input);
       cin << input;

11. (TCO 2) Which statement outputs a double value in a field of seven characters with four digits after the decimal point? (Points : 5)        cout << 7chars << 4digits << 1.2345678;
       cout << fixed << setprecision(4) << 1.2345;
       cout << setprecision(7) << setw(4) << 1.2345;
       cout << setprecision(4) << setw(7) << 1.2345678;
1. (TCO 2) What are the values of the variables after the code fragment below executes if the input data is 37 86.56 32?

double x, y;
int z;
cin >> x;
cin >> z;
cin >> y;

(Points : 5)        x = 37.0, y = 32, z = 86
       x = 37.0, y = 56, z = 86
       x = 37.0, y = 32, z = 86.56
       x = 37.0, y = 0.56, z = 86


2. (TCO 10) For readability, all statements inside a loop body should be (Points : 5)        indented the same distance as the loop control statement.
       indented by one additional tab stop more than the loop control statement.
       surrounded by an open and closing parenthesis.
       written on the same line.

3. (TCO 10) Which of the following lines correctly adds a multiline comment? (Points : 5)        // comment
    comment \
       /* comment
   * comment
   */
       /* comment
  */ comment
       \ comment
  \ comment

4. (TCO 3) A program needs to output the cost of shipping a package based on the weight of the package. Information is available that associates specific weight ranges with specific costs. For example, a package weighing between 1 and 2 pounds costs $2.50 to ship. The best selection structure to use to program this situation is _______. (Points : 5)        a SWITCH statement
       multiple IF statements
       nested IF statements
       multiple IF ELSE statements

5. (TCO 3) Which statement correctly tests char variable keepgoing for the upper or lower case letter A? (Points : 5)        if(keepgoing = 'a' || keepgoing = 'A')
       if(keepgoing = 'a' || 'A')
       if(keepgoing == 'a' && keepgoing == 'A')
       if(keepgoing == 'a' || keepgoing == 'A')

6.
(TCO 3) What is the output of the following code snippet?

int a = 9, b = 4, c = -1;
if (a > b || (c = a) > 0)
{
cout << "TRUE" << a << b << c;
} else {
cout << "FALSE" << a << b << c;
} (Points : 5)        FALSE 9 4 9
       TRUE 9 4 -1
       TRUE 9 4 1
       None of the above

7.
(TCO 3) What is the value of beta after the following code executes if the input is 1?


int beta;
cin >> beta;
switch(beta)
{
case 3:
beta += 3;
break;
case 1:
beta++;
case 4:
beta += 4;
break;
case 5:
beta += 5;
} (Points : 5)        2
       6
       11
       1


8. (TCO 4) Which looping construct would be best suited when a program must repeat a set of tasks until a specific condition occurs? It is possible that the set of tasks will not need to execute at all if the specific conditions exists initially.(Points : 5)        for
       do while
       while
       Any of the above

9.
(TCO 4) How many times does the following loop body execute?

int count = 52;
for(int i = 0; i > 26; i++)
{
      cout << count << endl;
     --count;
} (Points : 5)        26
       52
       25
       None of the above


10. (TCO 4) When the _______ statement executes in a loop body, control immediately exits from the loop. (Points : 5)        break
       continue
       exit
       done

11. (TCO 4) Which of the following expressions is correct if you want to end a while-loop when the character variable answer is anything other than the character 'y' in either upper or lower case? (Points : 5)        while(answer == 'y' && answer == 'Y')
       while(answer == "y" && answer == "Y")
       while(answer == 'y' || answer == 'Y')
       while(answer == "y" || answer == "Y") Short Answer & Essay

1.
(TCO 4) What is the output from the following loop?

int sum = 0;
for ( int i = 1; i % 2 != 0; i++)
{
sum += i;
i++;
}
cout << sum << endl; (Points : 5)       
      
2. (TCO 3) A program has a char variable response that has been assigned a value. Write a switch statement that outputs "Yes" if the variable contains lower or upper case 'y', "No" if it contains lower or upper case 'n', or "Invalid Input" for any other value. (Points : 10)       
      
3. (TCO 3) Assume a program has the following declarations and statements:

const int MAX = 100;
const int UPPER = 66;
const int LOWER = 33;
const int MIN = 0;


void main()
{
int score;
cin >> score;

//Add a few lines of code to do the following:
//    For a score of UPPER to and including MAX, output "Well Done!"
//    For a score of LOWER to but not including UPPER, output "Good Job."
//    For a score of MIN to but not including LOWER output "Try Harder!"
//    For any other score, output an error message. (Points : 10)       
      
4. (TCO 3) Write a complete program for Visual C++ to calculate and display the volume of a cylinder, given its radius and height. Your program must meet the following requirements:

Explanation / Answer

1. A_plus_B

2. Compiler

3. 9

4. 4

5. the modulo operator

6. 1

7. 2020

8. a/b

9. is used with cout to display a new line

10. getline(cin,input);

11. cout << setprecision(4) << setw(7) << 1.2345678;


1. x = 37.0, y = 32, z = 86

2. indented by one additional tab stop more than the loop control statement.

3. /* comment

* comment

*/

4. a SWITCH statement

5. if(keepgoing == 'a' || keepgoing == 'A')

6. image not visible

7. image not visible

8. while

9. image not visible

10. break

11. while(answer == 'y' && answer == 'Y')


1. image not visible

2.

switch(response){

case 'y':

case 'Y':cout<<"Yes"<<endl;

break;

case 'N':

case 'n':cout<<"No"<<endl;

break;

default:cout<<"invalid input"<<endl;

}


3. image not visible

4.

#include<iostream>

#include<iomanip>

using namespace std;

#define PI 3.14159

double volume(double radius,double height){

return radius*radius*height*PI;

}

int main(){

double radius,height;

cin>>radius>>height;

if(radius<=0||height<=0){

cout<<"Invalid input"<<endl;

return 0;

}

cout<<setprecision(3)<<volume(radius,height)<<endl;

return 0;

}

5.

#include<iostream>

using namespace std;

int main(){

int i=75;

do{

cout<<i<<endl;

i+=5;

}while(i<200);

return 0;

}


6.

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

char ans='y';

double deposit,rate;

while(ans=='y'||ans=='Y'){

cout<<"Enter initial deposit and interest rate"<<endl;

cin>>deposit>>rate;

if(deposit<0||rate<0){

cout<<"deposit and rate have to be positive numbers"<<endl;

continue;

}

cout<<"Interest on the deposit "<<deposit<<" at rate "<<rate<<" is "<<setprecision(2)<<deposit*rate<<endl;

cout<<"Do you want to continue?(enter y/Y):";

cin>>ans;

}

return 0;

}

}

}