Please give a similar example as the previous example in photos (language C++) -Provide a hand-tracing example based off this previous example in the book Big C++ that tests the program like the previous example in the photos. Make sure it’s similar but not the same. -Use a simple pr

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 20PE
icon
Related questions
Question
C++ Please give a similar example as the previous example in photos (language C++) -Provide a hand-tracing example based off this previous example in the book Big C++ that tests the program like the previous example in the photos. Make sure it’s similar but not the same. -Use a simple program using 2 variables that require user input with 2 constants that are initialized upon declaration, and either a decision or repetition control structure the program uses to control the flow of logic. Thank you :) I will give a rating!
For example, let's trace the tax program with the data from the program run in Section 3.4. In
lines 13 and 14, taxl and tax2 are initialized to 0.
6 int main()
7 {
8
9
10
11
12
13
14
15
16
17
18
const double RATE1 = 0.10;
const double RATE2 = 0.25;
const double RATE1 SINGLE LIMIT = 32000;
const double RATE1 MARRIED LIMIT = 64000;
19
20
21
22
23
double tax1 = 0;
double tax2 = 0;
In lines 18 and 22, income and marital status are initialized by input statements.
double income;
cout << "Please enter your income: ";
cin >> income;
marital
tax tax2 income, status
0
0
cout << "Please enter s for single, m for married: ";
string marital_status;
cin >> marital_status;
Because marital status is not "s", we move to the else branch of the outer if statement (line 36).
24
if (marital status == "s")
25
26
27
28
29
if (income <= RATE1 SINGLE LIMIT)
{
}
tax1 = RATE1 * income;
thomasd007/iStockphota
Hand-tracing helps you understand
whether a program works correct-
ly.
marital
tax tax2 income, status
0
0 80000 m
Transcribed Image Text:For example, let's trace the tax program with the data from the program run in Section 3.4. In lines 13 and 14, taxl and tax2 are initialized to 0. 6 int main() 7 { 8 9 10 11 12 13 14 15 16 17 18 const double RATE1 = 0.10; const double RATE2 = 0.25; const double RATE1 SINGLE LIMIT = 32000; const double RATE1 MARRIED LIMIT = 64000; 19 20 21 22 23 double tax1 = 0; double tax2 = 0; In lines 18 and 22, income and marital status are initialized by input statements. double income; cout << "Please enter your income: "; cin >> income; marital tax tax2 income, status 0 0 cout << "Please enter s for single, m for married: "; string marital_status; cin >> marital_status; Because marital status is not "s", we move to the else branch of the outer if statement (line 36). 24 if (marital status == "s") 25 26 27 28 29 if (income <= RATE1 SINGLE LIMIT) { } tax1 = RATE1 * income; thomasd007/iStockphota Hand-tracing helps you understand whether a program works correct- ly. marital tax tax2 income, status 0 0 80000 m
Because marital status is not "s", we move to the else branch of the outer if statement (line 36).
24 if (marital status == "s")
25
{
26
27
28
29
30
31
32
33
38
39
40
41
42
43
44
45
46
if (income <= RATE1_SINGLE_LIMIT)
{
43
44
}
else
{
34
35
36
37
Because income is not <= 64000, we move to the else branch of the inner if statement (line 42).
if (income <= RATE1_MARRIED_LIMIT)
{
tax1 = RATE1 * income;
}
tax1 = RATE1 * income;
}
else
{
tax1 = RATE1 * RATE1_SINGLE_LIMIT;
tax2= RATE2* (income - RATE1_SINGLE_LIMIT);
}
else
{
}
The values of taxl and tax2 are updated.
{
tax1 = RATE1 * RATE1_MARRIED_LIMIT;
tax2 = RATE2 * (income - RATE1 MARRIED_LIMIT);
}
tax1 = RATE1* RATE1_MARRIED_LIMIT;
tax2 = RATE2* (income - RATE1 MARRIED_LIMIT);
45
46
47 }
Their sum total_tax is computed and printed. Then the program ends.
48
49
50
51
52
53 }
Because the program trace shows the expected output ($10,400), it successfully demon-
double total_tax = tax1 + tax2;
cout << "The tax is $" << total_tax << endl;
return 0;
taxl
Ø
6400
taxl
marital
tax2 income status
80000 m
6400 4000
tax2
Ø
4000
marital total
income status tax
80000 m
10400
Q
Transcribed Image Text:Because marital status is not "s", we move to the else branch of the outer if statement (line 36). 24 if (marital status == "s") 25 { 26 27 28 29 30 31 32 33 38 39 40 41 42 43 44 45 46 if (income <= RATE1_SINGLE_LIMIT) { 43 44 } else { 34 35 36 37 Because income is not <= 64000, we move to the else branch of the inner if statement (line 42). if (income <= RATE1_MARRIED_LIMIT) { tax1 = RATE1 * income; } tax1 = RATE1 * income; } else { tax1 = RATE1 * RATE1_SINGLE_LIMIT; tax2= RATE2* (income - RATE1_SINGLE_LIMIT); } else { } The values of taxl and tax2 are updated. { tax1 = RATE1 * RATE1_MARRIED_LIMIT; tax2 = RATE2 * (income - RATE1 MARRIED_LIMIT); } tax1 = RATE1* RATE1_MARRIED_LIMIT; tax2 = RATE2* (income - RATE1 MARRIED_LIMIT); 45 46 47 } Their sum total_tax is computed and printed. Then the program ends. 48 49 50 51 52 53 } Because the program trace shows the expected output ($10,400), it successfully demon- double total_tax = tax1 + tax2; cout << "The tax is $" << total_tax << endl; return 0; taxl Ø 6400 taxl marital tax2 income status 80000 m 6400 4000 tax2 Ø 4000 marital total income status tax 80000 m 10400 Q
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Structure chart
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning