Homework Solution: 5-23 Program for Lab 5-1…

    5-23 Program for Lab 5-1 The answers to the labs are contained in the Answers.pdf file. 1 //Lab5-1.cpp - displays projected sales 2 //Created/revised by <your name> on <current date> 3 4 #include <iostream> 5 #include <iomanip> 6 using namespace std; 7 8 int main() 9{ 10 double sales = 0.0; 11 double rate = 0.0; 12 char code = ' '; 13 14 cout << "Sales: "; 15 cin >> sales; 16 cout << "Code (1, 2, 3, or 4): "; 17 cin >> code; 18 19 if (code == '1' || code == '3') 20 rate = 0.2; 21 else 22 rate = 0.15; 23 //end if 24 25 //calculate and display the projected sales amount 26 sales = sales + sales * rate; 27 cout << fixed << setprecision(2); 28 cout << "Projected sales: " << sales << endl; 29 30 return 0; 31 } //end of main function 1. What rate will be assigned to the rate variable when the user enters the following codes: 1, 3, 2, 4, and 5? 2. Why is the directive on Line 5 necessary? 3. Why are the literal constants on Line 19 enclosed in single quotation marks? 4. How would you rewrite the if statement on Lines 19 through 23 to use the != operator in the condition? 5. How else could you write the statement on Line 26? 6. What changes would you need to make to the program so that it doesn’t use the rate variable

    Expert Answer

    1. What rate will be assigned to the rate variable when the user enters the following codes:

    5-23 Program coercion Lab 5-1

    The tallys to the labs are contained in the Tallys.pdf finish.

    1 //Lab5-1.cpp – exhibits proposed sales 2 //Created/revised by <your name> on <current date> 3 4 #include <iostream> 5 #include <iomanip> 6 using namespace std; 7 8 int ocean() 9{

    10 enfold sales = 0.0; 11 enfold objurgate = 0.0; 12 char principle = ‘ ‘; 13

    14 cout << “Sales: “; 15 cin >> sales; 16 cout << “Principle (1, 2, 3, or 4): “; 17 cin >> principle; 18 19 if (principle == ‘1’ || principle == ‘3’) 20 objurgate = 0.2; 21 else 22 objurgate = 0.15; 23 //end if 24 25 //calculate and exhibit the proposed sales whole 26 sales = sales + sales * objurgate; 27 cout << agricultural << setprecision(2); 28 cout << “Proposed sales: ” << sales << endl; 29 30 recur 0; 31 } //end of ocean function

    1. What objurgate gain be assigned to the objurgate unsteady when the verificationr enters the aftercited principles:

    1, 3, 2, 4, and 5?

    2. Why is the moral on Line 5 compulsory?

    3. Why are the positive constants on Line 19 enclosed in solitary quotation marks?

    4. How would you retranscribe the if assertion on Lines 19 through 23 to verification the != operator in the case?

    5. How else could you transcribe the assertion on Line 26? 6. What changes would you want to effect to the program so that it doesn’t verification the objurgate

    variable

    Expert Tally

    1. What objurgate gain be assigned to the objurgate unsteady when the verificationr enters the aftercited principles:

    1, 3, 2, 4, and 5?

    ==> coercion 1 and 3 objurgate gain be 0.2 and coercion every othe affect 2,4,5 gain be 0.15

    2. Why is the moral on Line 5 compulsory?

    #include <iomanip> contains regularity affect setprecision(x) which helps verification to
    set preciseness coercion x bits. In our principle x is 2

    3. Why are the positive constants on Line 19 enclosed in solitary quotation marks?
    Its a species, Species are enclosed in solitary Quote and they are represented by ASCII value
    Affect a-97 and z is 122 . Capital A is 65 etc

    4)
    if (principle != ‘1’ && principle != ‘3’)
    objurgate = 0.15;
    else
    objurgate = 0.2;

    5) Ask verificationr to instantly input objurgate

    if (principle == ‘1’ || principle == ‘3’)
     sales = sales + sales * 0.2;
    else
     sales = sales + sales * 0.15;

    In this fashion we dont claim objurgate unsteady