In: Advanced Math
Exercise 1. Write an algorithm (pseudocode) to read a set of sales data items from standard input and calculate and output their total and their average. Prompt user to enter number of data items. Exercise 2. Create a test data set to verify your algorithm. How many cases are needed? Explain. Write your test data set below for submission to the EOL dropbox upon completion of your lab. Number of items List data items Expected output Case 1: Exercise 3. Create a flowchart for your algorithm on Raptor and verify it using your test data. Copy and paste your flowchart below for submission to the EOL dropbox upon completion of your lab. Exercise 4. Write a C++ program that implements your flowchart. Use a do-while loop for input validation and a for loop to calculate the total (You may skip this exercise until we cover for and do-while loops)
#include <iostream>
using namespace std;
int main() {
int n, item = 0, total = 0;
double average;
do // input validation
{
cout << "Enter number of items(> 0): ";
cin >> n;
} while(n <= 0);
cout << "Enter prices one by one: ";
for(int i=0; i<n; i++) // taking input and adding
{
cin >> item;
total += item;
}
average = total / (float) n;
// printing output
cout << "Total is " << total << endl;
cout << "Average is " << average << endl;
}
/*SAMPLE OUTPUT
Enter number of items(> 0): -4
Enter number of items(> 0): 0
Enter number of items(> 0): 3
Enter prices one by one: 4 6 7
Total is 17
Average is 5.66667
*/
In limited time for questions, I am able to solve only one question. Sorry for that.