Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Suppose that x, y, and z are int variables, and x = 9, y = 14, and z = 19.Determine whether the following expressions

1. Suppose that x, y, and z are int variables, and x = 9, y = 14, and z = 19.Determine whether the following expressions evaluate to true or false:a. !(x > 9)

b. x <= 8 || y < 14

c. (x != 9) && (y != z)

d. x >= z || (x + y >= z)

e. (x <= y - 2) && (y >= z) || (z - 2 != 0)

2. Suppose that str1, str2, and str3 are string variables, and str1 = "French", str2 = "Italian", and str3 = "Swedish".Determine whether the following expressions evaluate to true or false:a. str1 >= str2 b. str1 != "French" c. str3 < str2 d. str2 <= "French"

3. What is the output of the following statements? (Show the characters printed by cout and whether or not they are printed on the same line - be precise!)

a. if ('a' < 'A')

cout << "BB";

cout << "bb" << endl;

b. if (50 <= 5 * 10)

cout << "50";

cout << "5 * 10";

cout << endl;

c. if('C' < 'c')

{

cout << 'C';

cout << 'c';

}

cout << '!' << endl;

d. string dplus = "d+", dminus= "d-";

if(dplus >= dminus)cout << dplus << endl;cout << dminus << endl;

e. string sam = "Sam", samantha = "Samantha";

if(samantha < sam)

cout << samantha << sam << endl;

cout << sam << samantha << endl;

f. if(10 == 3 * 4 - 2)cout << 2 * 3 / 6 1 << endl;cout << "*" << endl;

4. What is the output of the following code? (I am only interested in the characters printed by cout and whether or not they are printed on the same line - be precise!)int num = 20; //Line 1double temp = 4.9; //Line 2bool found; //Line 3found = (num == 2 * static_cast(temp) + 12); //Line 4cout << "The value of found is: " << found << endl; //Line 5

5. Program specification: when buying less than 4 items the shipping charges are $6.00 for each item bought; if the number of items bought is at least 4, but less than 8, then the shipping charges are $5.00 for each item bought; if the number of items bought is at least 8, there are no shippingcharges. Correct the following code so that it computes the correct shipping charges. I am only looking for this section of code after it has been fixed, but you can certainly show an entire program if you'd like (in which case I encourage you to test numOfItemsBought values of 3, 4, 5, 7, 8, and 100).

if (numOfItemsBought >> 4) shippingCharges = 7.00 * numOfItemsBought;else if (4 = numOfItemsBought && numOfItemsBought is less than 8); shippingCharges = 5.00 * numOfItemsBoughtelse shippingCharges are 0.00;

6. Given variables overSpeed and fine of type double, create code that implements the following algorithm. For example, someone caught speeding doing 65.0 miles per hour in a 60.0 mph highway zone would correspond to an overSpeed of 65.0-60.0=5.0.Assign the value to fine as follows:

If overSpeed is above zero and less than 5, the value assigned to fine is $22.00

If overSpeed is at least 5 and less than 10, the value assigned to fine is $82.00

If overSpeed is at least 10 and less than 15, the value assigned to fine is $135.00

If overSpeed is at least 15 the value assigned to fine is $170.00 +(10(overSpeed - 15))

7. Rewrite the following expressions using the conditional operator. (Assume that all variables are declared properly.)

//Case one

if (x > y)

z = x - y;

else

z = y - x;

//Case two

if (hours > 40.0)

pay = 40 * 7.50 + 1.5 * 7.5 * (hours - 40);

else

pay = hours * 7.50;

//Case three

if (points >= 60)

str = "Pass";

else

str = "Fail";

8. Suppose that the cmath library is included. Consider the following C++ code:

int beta;

cin >> beta;

switch (beta % 7)

{

case 0:

case 1:

beta = beta + beta;

break;

case 2:

beta++;

break;

case 3:

beta = static_cast(sqrt(beta * 1.0));

break;

case 4:

beta = beta + 4;

case 6:

beta--;

break;

default:

beta = -10;

}

a. What is the final value of beta when the input is 5?

b. What is the final value of beta when the input is 2?

c. What is the final value of beta when the input is 8?

d. What is the final value of beta when the input is 19?

e. What is the final value of beta when the input is 4?

9. The following program contains errors. Correct them so that the program will run and outputw = 18.(Hint: please remove all commas, use parentheses as needed, and create compound statements for those bunched up statements following if and else. The modified code will have two compound statements, and they will not contain the cout statement at the end.)

#include

using namespace std;

const int SECRET = 2

main ()

{

int x, y, w, z;

z = 9;

if z > 9

x = 12; y = 5, w = x + y + SECRET;

else

x = 12; y = 4, w = x + y + SECRET;

cout << "w = " << w << endl;

}

10. Write the missing statements in the following program so that it prompts the user to input two numbers. If either of the numbers is 0, the program should output "both numbers must be nonzero! " and exit the program. If the first number is greater than the second number, it outputs the first number divided by the second number; if the first number is less than the second number, it outputs the second number divided by the first number; otherwise, it outputs the string "==".

#include

using namespace std;

int main()

{

double firstNum, secondNum;

cout << "Enter two nonzero numbers: ";

cin >> firstNum >> secondNum;

cout << endl;

//Missing statements

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Apache Cassandra Development

Authors: Vivek Mishra

1st Edition

1484201426, 9781484201428

More Books

Students also viewed these Databases questions

Question

=+ 4. Why should policymakers think about incentives?

Answered: 1 week ago

Question

What is Ramayana, who is its creator, why was Ramayana written?

Answered: 1 week ago

Question

To solve by the graphical methods 2x +3y = 9 9x - 8y = 10

Answered: 1 week ago