a. Draw the flow graph for the following program: #include <iostream> int main()
ID: 3579398 • Letter: A
Question
a. Draw the flow graph for the following program:
#include <iostream>
int main()
{
int choice, months;
double charges;
do
{
displayMenu();
cin >> choice;
if (choice >= 1 && choice <= 3)
{
cout << "For how many months? ";
cin >> months;
switch (choice)
{
case 1: charges = months * 40.0;
break;
case 2: charges = months * 20.0;
break;
case 3: charges = months * 30.0;
}
cout << "The total charges are $" << charges
<< endl;
}
else if (choice != 4)
{
cout << "Invalid choice. Please try
again. ";
}
} while (choice != 4);
return 0;
}
b. List all basis path of the flow graph that you generate from part (a).
c. Provide test data for each of the basis path that you identify in (b).
Explanation / Answer
a) start->ask for choice->ask for no of months->if choice is 1, then multiply months with 40 for charges->if choice is 2, then multiply months with 20 for charges->if choice is 3, then multiply months with 30 for charges->if choice is 4, then exit->repeat the process untill exit.
c) test data: choice=2 & months=4, then charges=80.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.