I need help creating the flowcharts for these pre labs, as well as answering the
ID: 3688095 • Letter: I
Question
I need help creating the flowcharts for these pre labs, as well as answering the questions they ask.
Pre-Lab 7
Objectives:
To work with the while loop
To introduce the do-while loop
To work with the for loop
To work with nested loops
Lab 7a:
Create a project named Lab7a in CodeBlocks.
For lab 7a, you need to write a program that will calculate a tax on a bill, until the user decides to quit. The user needs to enter the price of the bill and the percent of the tax for each iteration using ‘while’ loop. For the prelab, you need to work on this problem and have the flowchart ready before the lab.
Prelab TA Check: ____________
Prelab 7b:
Study the following code. You need to run this code in the debug mode to check how the program validates the user’s input (price) that is positive. In the lab7b, you need to test the following program using both negative and positive input. Add a block comment on top of this code and explain briefly what does this program do.
int main( )
double price;
cout <<“Enter a positive price for an item: “;
cin >> price;
}while(price <= 0);
//when this is true, the block repeats-when the
// user enters bad data the loop exits when the
// user enters good data because the condition
// becomes false
cout << “Great, you entered a positive value for price!”;
return 0;
Prelab TA Check: _________
Prelab 7c:
In lab7c, you need to write and test a program to validate user input. The user must enter two double values, one equal to 5, one less than zero AND a menu choice of ‘A’, ‘B’ or ‘C’. This requires three do-while loops. The only thing this program does is input validation. Simply print a message after each do-while loop stating the data entered is valid. For prelab, you need to work on the algorithm and flowchart.
Prelab TA Check: ___________
Prelab 7d:
Study the following code that calculates average of 3 tests:
In this lab, you need to change the below code so it will calculate an average and print the new average of several test scores which the number of them is determined by the user. Also, this can be done for any number of students. You need to look at the code example from the textbook that was discussed during the lecture. For the prelab, you need to work on the algorithm and flowchart. (HINT : Use the 3 scores in a loop which is determined by user input and add all scores in each iteration and calculate average at the end)
#include<iostream>
using namespace std;
int main( ) {
double testScore;
double total;
double average;
total = 0;
cout << “Enter the score for test 1: “;
cin >> testScore;
total = total + testScore;
cout << “Enter the score for test 2: “;
cin >> testScore;
total = total + testScore;
cout << “Enter the score for test 3: “;
cin >> testScore;
total = total + testScore;
average = total/3;
cout << “The average for the three tests is: “ << average << endl;
return 0;
}
Prelab TA Check: __________
Prelab 7e:
In this lab, you need to using a for-loop to write a program to print 10 random integers in the range of 1 to 30. Be sure to look at the output to be sure all the numbers printed are in this range. For the prelab, you need to work on the algorithm and the flowchart to figure out the logic first. Answer the following questions:
How many times will the for loop run?
What is range of random numbers you will generate ?
Prelab TA Check: ________
Prelab 7f:
Make a program that will ask the user for his/ her name and then it will save his/her name in a file called “test”
Prelab TA Check: ________
Explanation / Answer
Prelab 7f:
Make a program that will ask the user for his/ her name and then it will save his/her name in a file called “test”
int main()
{
char name[30];
cout<<"Please enter your name";
cin>>name;
ofstream myfile;
myfile.open ("test");
myfile << name;
myfile.close();
return 0;
}
Prelab 7e:
In this lab, you need to using a for-loop to write a program to print 10 random integers in the range of 1 to 30.
Be sure to look at the output to be sure all the numbers printed are in this range.
For the prelab, you need to work on the algorithm and the flowchart to figure out the logic first. Answer the following questions:
How many times will the for loop run? 10 times
What is range of random numbers you will generate ? 1 to 30
for(int i=0;i<10;i++)
{
int random_no=1 + ( std::rand() % ( 20 - 1 + 1 ) );
cout<<"Random number: "<<random_no;
}
You need to look at the code example from the textbook that was discussed during the lecture(This is not provided. Please help)
#include<iostream>
using namespace std;
int main( ) {
double testScore;
double total;
double average;
total = 0;
cout << “Enter the score for test 1: “;
cin >> testScore;
total = total + testScore;
cout << “Enter the score for test 2: “;
cin >> testScore;
total = total + testScore;
cout << “Enter the score for test 3: “;
cin >> testScore;
total = total + testScore;
average = total/3;
cout << “The average for the three tests is: “ << average << endl;
return 0;
}
Prelab 7c:
In lab7c, you need to write and test a program to validate user input.
The user must enter two double values, one equal to 5, one less than zero AND a menu choice of ‘A’, ‘B’ or ‘C’.
This requires three do-while loops. The only thing this program does is input validation. Simply print a message after each do-while loop stating the data entered is valid.
double a,b;
cin>>a,b;
if(a==5.0)
cout<<"Valid";
else cout<<"Comparison 1 is invalid";
if(b<0)
cout<<"Valid";
else cout<<"Comparison 2 is invalid";
(I think I got the question wrong. How are we supposed to incorporate the do-while loop here? Please reply so I can help :) )
PreLab 7b
int main( )
{
double price;
do{
cout <<“Enter a positive price for an item: “;
cin >> price;
}
while(price <= 0); // For negative value, the program will keep adsking the user to enter a positive value, and as soon as the positive value is provided, it prints the statement.
cout << “Great, you entered a positive value for price!”;
return 0;
}
Create a project named Lab7a in CodeBlocks.
For lab 7a, you need to write a program that will calculate a tax on a bill, until the user decides to quit.
The user needs to enter the price of the bill and the percent of the tax for each iteration using ‘while’ loop.
For the prelab, you need to work on this problem and have the flowchart ready before the lab.
double bill,total_bill,tax_percent;
cout<<"Enter q to quit..else continue";
cin>>ch;
do
{
cout<<"Enter price of Bill";
cin>>bill;
cout<<"Enter tax percent";
cin>>tax_percent;
tax_price=tax_percent/100;
total_bill=bill+(tax_price*bill);
cout<<"Total is :"<<total_bill;
cout<<"Enter q to quit..else continue";
}
while(ch!='q')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.