Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

14. Write C++ statements that output Male if the gender is \'M\', Female if the

ID: 3566302 • Letter: 1

Question

14. Write C++ statements that output Male if the gender is 'M', Female if

the gender is 'F', and invalid gender otherwise.

15. 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;
16. What is the output of the following C++ code?
int x = 10;
int y = 20;
if (x < 20 && y > 20)
{
x = 2 * x;
y = y / 2;
cout << x << " " << y << " " << x - y << endl;
}
else
{
x = y / x;
cout << x << " " << y << " " << x * x + y * y << endl;
}
17. What is the output of the following program?
#include <iostream>
using namespace std;
int main()
{
int myNum = 10;
int yourNum = 30;
if (yourNum % myNum == 3)
{
yourNum = 3;
myNum = 1;
}
else if (yourNum % myNum == 2)
{
yourNum = 2;
myNum = 2;
}
else
{
yourNum = 1;
myNum = 3;
}
cout << myNum << " " << yourNum << endl;
return 0;
}

18. a. What is the output of the program in Exercise 17, if myNum = 5 and
yourNum = 12?
b. What is the output of the program in Exercise 17, if myNum = 30 and
yourNum = 33?

Explanation / Answer

14)

if(gender == 'M')
cout<<"Male"<<endl;

else if (gender == 'F')
cout<<"Female"<<endl;

else
cout<<"Invalid gender"<<endl;


Note: gender is the Character variable and that stored user input value


15)


if (0 < numOfItemsBought && numOfItemsBought < 5)
shippingCharges = 5.00 * numOfItemsBought;

else if (5 <= numOfItemsBought && numOfItemsBought < 10);
shippingCharges = 2.00 * numOfItemsBought;

else
shippingCharges = 0.00;

16)

if condition is fail so 'else' part will execute

Output:

2 20 404

17)

3 1

18)

a) 2 2

b) 1 3

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote