# Answered Essay: 5-23 Program for Lab 5-1

5-23 Program for Lab 5-1

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

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

1, 3, 2, 4, and 5?

==> for 1 and 3 rate will be 0.2 and for all othe like 2,4,5 will be 0.15

2. Why is the directive on Line 5 necessary?

#include <iomanip> contains method like setprecision(x) which helps use to
set precision for x bits. In our code x is 2

3. Why are the literal constants on Line 19 enclosed in single quotation marks?
Its a character, Character are enclosed in single Quote and they are represented by ASCII value
Like a-97 and z is 122 . Capital A is 65 etc

4)
if (code != ‘1’ && code != ‘3’)
rate = 0.15;
else
rate = 0.2;

5) Ask user to directly input rate

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

In this way we dont require rate variable

Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

Try it now!

## Calculate the price of your order

Total price:
\$0.00

How it works?

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.