Css Midterm 1 Part 1
Css Midterm 1 Part 1
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:
(no need to include main and headers, just the code that goes in main)
Your Answer:
string name;
int 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.
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 ).
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:
• 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
int apples = 4;
int oranges = 7;
}
else if(oranges >= apples)
{
Question 16
1 / 1 pts
Which line of code executes below?
int num = 5;
if (num > 5)
num = 0;
cout << "Num is " << num;
}
else
• 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?
{
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:
cout << " Enter for num1: " << num1 << " and for num2: " << num2 << endl;
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;
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;
// If statement
cout << " That number is greater than or equal to 10! " << endl;
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';
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
Question 27
1 / 1 pts
!(Expression1)
• 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
• True False
Question 30
1 / 1 pts
Epxression1 && Expression2
If Expression1 is True AND Expression2 is False, the whole expression evaluates to:
• True False