1. Suppose that x, y, and z are int variables, and x = 20, y = 30, and z = 40. D
ID: 3828756 • Letter: 1
Question
1. Suppose that x, y, and z are int variables, and x = 20, y = 30, and z = 40.
Determine whether the following expressions evaluate to true or false:
a. !(x > 10)
b. x <= 5 || y < 15
c. (x != 5) && (y != z)
d. x >= z || (x + y >= z)
e. (x <= y - 2) && (y >= z) || (z - 2 != 20)
2. Suppose that str1, str2, and str3 are string variables, and str1 = "English", str2 = "Physics", and str3 = "Computer Programming".
Evaluate the following expressions:
a. str1 >= str2
b. str1 != "english"
c. str3 < str2
d. str2 >= "Chemistry"
3. What is the output of the following statements?
a. if('+' < '*')
cout << "+*";
cout << "%%" << endl;
b. if(10 <= 2 * 5)
cout << "10 ";
cout << "2 * 5";
cout << endl;
c. if('a' < 'A')
{
cout << 'a';
cout << 'A';
}
cout << endl;
d. if("C++" >= "C--")
cout << "C++" << endl;
cout << "C--" << endl;
e. if("Sam" <= "Tom")
cout << "Sam Tom" << endl;
cout << "Tom Sam" << endl;
f. if(6 == 2 * 4 - 2)
cout << 3 * 4 / 6 – 8 << endl;
cout << "**" << endl;
4. What is the output of the following code?
int num = 20; //Line 1
double temp = 2.5; //Line 2
bool found; //Line 3
found = (num == 2 *static_cast<int>(temp) + 1); //Line 4
cout << "The value of found is: " << found << endl; //Line 5
5. If the number of items bought is less than 5, then the shipping charges are $5.00 for each item bought; if the number of items bought is at least 5, but less than 10, then the shipping charges are $2.00 for each item bought; if the number of items bought is at least 10, there are no shipping charges.
Correct the following code so that it computes the correct shipping charges.
if(0 < numOfItemsBought || numOfItemsBought <> 5)
shippingCharges = 5.00 * numOfItemsBought;
else if (5 <= numOfItemsBought && numOfItemsBought < 10);
shippingCharges = 2.00 * numOfItemsBought;
else
shippingCharges = 0.00;
Explanation / Answer
1. Suppose that x, y, and z are int variables, and x = 20, y = 30, and z = 40.
Determine whether the following expressions evaluate to true or false:
a. !(x > 10) = False
b. x <= 5 || y < 15 = False
c. (x != 5) && (y != z) True
d. x >= z || (x + y >= z) True
e. (x <= y - 2) && (y >= z) || (z - 2 != 20) True
2. Suppose that str1, str2, and str3 are string variables, and str1 = "English", str2 = "Physics", and str3 = "Computer Programming".
Evaluate the following expressions:
a. str1 >= str2 False
b. str1 != "english" True
c. str3 < str2 True
d. str2 >= "Chemistry" True
3. What is the output of the following statements?
a. if('+' < '*')
cout << "+*";
cout << "%%" << endl;
Output: %%
b. if(10 <= 2 * 5)
cout << "10 ";
cout << "2 * 5";
cout << endl;
output: 10 2 * 5
c. if('a' < 'A')
{
cout << 'a';
cout << 'A';
}
cout << endl;
output:
d. if("C++" >= "C--")
cout << "C++" << endl;
cout << "C--" << endl;
output: C--
e. if("Sam" <= "Tom")
cout << "Sam Tom" << endl;
cout << "Tom Sam" << endl;
ouput:Sam Tom
Tom Sam
f. if(6 == 2 * 4 - 2)
cout << 3 * 4 / 6 – 8 << endl;
cout << "**" << endl;
output:-6
**
4. What is the output of the following code?
int num = 20; //Line 1
double temp = 2.5; //Line 2
bool found; //Line 3
found = (num == 2 *static_cast<int>(temp) + 1); //Line 4
cout << "The value of found is: " << found << endl; //Line 5
The value of found is: 0
5.
if(0 < numOfItemsBought && numOfItemsBought <> 5)
shippingCharges = 5.00 * numOfItemsBought;
else if (5 <= numOfItemsBought && numOfItemsBought < 10);
shippingCharges = 2.00 * numOfItemsBought;
else
shippingCharges = 0.00;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.