You are on page 1of 9

Midterm 1 Part 1 [Written] Results for David

Nunez-Garcia
Question 1
0 / 1 pts
What does the following code output?

int x = 3;
int y = 0;

x = 4 + 9;
y = x;
cout << x;
y = x + 1;
x = y;
cout << y << endl;

• 13

• 13 14

• 14

• 54

Question 2
1 / 1 pts
In C++, using correct syntax, show how you would request the name and age of a person, and output it
outputs like this:

Your name is Lisa and you are 34 years old.

(no need to include main and headers, just the code that goes in main)
Your Answer:

string name;

int age;

// Requesting person's name

cout << "Enter your name: " << endl;

cin >> name;

// Requesting the person's age

cout << "Enter your age: " << endl;


cin >> age;

// Output

cout << " Your name is " << name << " and you are " << age << " years old. " << endl;

Question 3
1 / 1 pts

All of the following are valid identifiers (valid names) for variables in C++ except:

• final grade

• _miles

• totalPrice

• num_of_friends

Question 4
1 / 1 pts
What data type would you use for decimal values (floating type numbers)?

• float or double

• char

• int

• long

Question 5
1 / 1 pts
What data type would you use to hold a last name?

string

Question 6
1 / 1 pts
What data type would I use for a variable that can hold the value ‘M’?

char

Question 7
1 / 1 pts
Declare a variable with of data type int identifier maxHorsePower and initialize it with a value of 30000.
Use correct C++ syntax.
int maxHorsePower = 30000;

Question 8
0 / 1 pts
Which of the lines below is an example of proper C++ syntax to take input from the user and store an
integer into a variable called miles.

• cin >> miles;

• cin << miles;

• cout >> miles;

• cout << miles;

Question 9
0 / 1 pts

What line of code is used to output the value of the variable miles to the console (terminal screen or
command prompt ).

• cout << miles;

• cin >> miles;

• cin << miles;

• cout >> miles;

Question 10
0 / 1 pts
According to the order of precedence in C++ which operator will be evaluated first here?

50 + 10 - 2 * 5/ 7

• *

• -

• /

• +

Question 11
1 / 1 pts
Assume we have three double variables x = 1.5, y =6.0, z = 1.5. Is the following true or false:

(x <= y )

• True False
Question 12
1 / 1 pts

Assume we have three integer variables x = 1, y =6, z = 5. Is the following true or false:

(x < y && z > y)

• True False

Question 13
1 / 1 pts

Assume we have three integer variables x = 1, y =6, z = 5. Is the following true or false:

(x < y || z > y)

• True False

Question 14
1 / 1 pts

What expression can be used in C++ to validate whether a number is between 1 – 10

• (number >=1 && number <=10)

• (number >1 && number <10)

• (number >=1 || number <=10)

• (1 <= number <= 10)


Question 15
1 / 1 pts
Which line of code executes?

int apples = 4;
int oranges = 7;

if(apples > oranges)


{

cout << "Pumpkin Lattes or Cold Brew?" << endl;

}
else if(oranges >= apples)
{

cout << "Apple Cider or Ponche Navideno?" << endl;

• Pumpkin Lattes or Cold Brew?

• Apple Cider or Ponche Navideno?

• none of the above

Question 16
1 / 1 pts
Which line of code executes below?

int num = 5;
if (num > 5)

num = 0;
cout << "Num is " << num;
}

else

cout << "Num is zero" << endl;


}

• Num is zero

• Compiler Error

• Num is 0
• Num is 5

Question 17
1 / 1 pts
Using correct C++ syntax show how you would update a variable that has been previously declared as
string with identifier month, to value "December".
month = "December";

Question 18
1 / 1 pts
What would be the output of the following code?

if (60 <= (10*6))

{
cout << "Hello";
cout << " There";
}

• Hello There

• Hello

• There

• Compiler Error

Question 19
1 / 1 pts
Using C++ syntax, Show how you would request the user for two numbers and add them together, output
the result.

Your Answer:

int num1, num2;

// Requesting the user to input two numbers to add up

cout << " Enter for num1: " << num1 << " and for num2: " << num2 << endl;

cout << num1 + num2;

Question 20
1 / 1 pts
Using correct C++ syntax ask the user for a number and multiply it by 5, output the result.
Your Answer:

int num1;

int num2 = 5;

// Requesting the user to input a number


cout << "Enter any number: " << endl;

cin >> num1;

cout << num1 * num2;

Question 21
1 / 1 pts
Using correct C++ syntax ask the user for a number, if the number is greater than or equal to 10, output
"That number is greater than or equal to 10" if they input a number lower than 10, output "The number is
less than 10"
Your Answer:

int num1;

// Requesting the user to input a random number

cout << " Enter a random number: " << endl;

cin >> num1;

// If statement

if(num1 >= 10){

cout << " That number is greater than or equal to 10! " << endl;

else if(num1 < 10){

cout << " The number is less than 10! " << endl;

Question 22
1 / 1 pts
Using proper C++ syntax, which of the options below properly updates the value of a char variable
called color to the character Y.

• color = 'Y';

• int COLOR = 'Y'

• string Color = 'Y'

• char color = 'Y';

Question 23
0 / 1 pts
Using proper C++ syntax, show how you would declare and initialize variable password to
value true using the assignment operator. Assume password is a variable of data type bool.
password = true;
Question 24
0 / 1 pts
Using proper C++ syntax, show how you would declare and initialize variable vehicle to
value Honda using the assignment operator.

vehicle = "Honda";

Question 25
1 / 1 pts
Using Proper C++ syntax, which of the options below is the CORRECT way to properly evaluate the
expression below into C++:

(a2+b2)4-7

• a*a+b*b*4-7

• a^2+b^24-7

• a**2+b**24-7

Question 26
1 / 1 pts
Which number can be used to represent a true value in bool.

• 1

• 0

• -1

• none of the above

Question 27
1 / 1 pts
!(Expression1)

If Expression1 is true, it negates to:

• True False

Question 28
0 / 1 pts
Epxression1 && Expression2

If Expression1 is True AND Expression2 is True, the whole expression evaluates to:

• True False
Question 29
1 / 1 pts
Epxression1 || Expression2

If Expression1 is True OR Expression2 is False, the whole expression evaluates to:

• True False

Question 30
1 / 1 pts
Epxression1 && Expression2

If Expression1 is True AND Expression2 is False, the whole expression evaluates to:

• True False

Quiz Score: 23 out of 30

You might also like