Quiz 01C Keys

advertisement
CS1430 Quiz #1C Take Home Quiz (10 pts)
Section Number ___________
Kevin Tian
Name: (Full Name) _____________________
1. [3 pts] Given the variable declarations,
int x = 9, y = 12, z = 50;
Evaluate the following logical expression. (Give the answer TRUE or FALSE)



( x > z || y > x) && ( y < z || x > y – z ) T
!(!( x != z )&& (z % 11 > 9)) T
(y != z -2) && (y != x && x < 2*z ) T
2. [1 pt] Transform the following algebraic formula to a c++ expression.
a+
3𝑚−𝑛
𝑥+5
+
2𝑎−𝑧
𝑥∗2
– 2b a + (3*m – n)/(x+5) + (2*a – z)/(x*2) – 2 *b
3. [1 pt] Given the following C++ code segment.
int x = 11, y = 14, z = 43;
int ans1, ans2;
ans1 = 2 * z * z % y / 2;
ans2 = x – y * y / z;
The value of ans1 is ___1____;
The value of ans2 is ___7____;
< Continue to the back page. >
CS1430 Quiz #1C Take Home Quiz (10 pts)
Kevin Tian
4. [3 pts] Complete the following program that reads a char from the standard input (console, command
line), and determines if the char is ‘A’. If the char is ‘A’, display the message: “Yes, it is A.”. Otherwise,
display “x is not A.”, where x should be the char entered.
#include <iostream>
using namespace std;
int main()
{
_______char input________________; //variable declaration
cout << “Please enter a char: ”;
_cin >> input_______________________; // get the integer from standard input
If( __input == ‘A’_______________ )
_____cout << “Yes, it is A”_________________________;
else
______cout << input << “ is not A”________________________;
return 0;
}
5. [2 pts] Write a C++ assignment statement to be used to implement the equation below. Assume that
variables b, x1 (pseudocode uses x1, you should use x1 in C++ assignment statement), x2 (pseudocode
uses x2), and t1 (t1) have already been declared as float variables. (1)
b
x1  x2 x2  x1 ( x2 x1  x2 x1 )
b = (x1- x2)*(x2+x1)*(x1*x2-x2*x1)/t1;
t1
Download