Question

In: Advanced Math

Exercise 1. Write an algorithm (pseudocode) to read a set of sales data items from standard...

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)

Solutions

Expert Solution

#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.


Related Solutions

Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm...
Write pseudocode for quick find algorithm anf quick union algorithm Write pseudocode for quick find algorithm and quick union algorithm
The following is the pseudocode of algorithm that searches a sorted array of n items by...
The following is the pseudocode of algorithm that searches a sorted array of n items by dividing it into three sub arrays of almost n/3 items (7pt). Hint: refer Mergesort algorithm) Input: Sorted array of Keys(A) indexed from 1 to n. Output: Location, the Location of K in array A (hint: return 0 if K is no in A) index location3 (int A[1…n ], index L, index H) { index m1, m2; if (L > H) return 0; else   ...
1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any...
1. Write pseudocode for the algorithm using iteration (looping). Envision an algorithm that when given any positive integer n, it will print out the sum of the squares from 1 to n. For example given 3 the algorithm will print 14 (because 1 + 4 + 9 =14) You can use multiplication denoted as * in your solution and you do not have to define it (For example. 3*3=9) For example if n is 6 it will print: The sum...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user...
Write an algorithm (flowchart OR Pseudocode) for the following problem Take input character from the user unless he enters '$'. Thereafter display how may vowels were entered by the user. Also display the number of each vowel ('a', 'e', 'i', 'o' and 'u') separately. For example if the user enters B a b e c o o d i u g o a l $ Then we have the output below: #A=2 #E=1 #I=1 #O=3 #U=2
Problem 1: (10 marks) ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a...
Problem 1: ALGORITHM COMPLEXITY:Write an algorithm (pseudocode but not a program) that takes a positive numberias an input, where i=a1a2...an,n>=3(numberwith 3 or more digits, every digit can have the value between 0 and 9–both inclusive). The algorithm should find the largest number jsuch that j=b1..bm, 1<=m<=n(numberwith m digits),andevery bk<=bk+1where1<=k<m and bk,bk+1ε{a1, a2, an}.Also, perform the computational complexity (time complexity)analysis of your algorithm and write the algorithm complexity in Big-Oh notation. Examples:Input: 23720, Output: 237Input: 9871, Output: 9Input: 1789, Output:1789Input: 2372891,...
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit....
Write a program read in data from the standard input stream (cin) representing temperature in Fahrenheit. The program will then convert the values into Kelvin (using 5/9 (Fº-32) to convert to Celsius and a difference of 273.15 between Celsius and Kelvin) and print out the new total value. Convert temperature in Fahrenheit to Kelvin : Enter temperature in Fahrenheit: 80.33 The temperature in Kelvin is: 300 Write a second program which then does the reverse conversion (using a difference of...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the...
Write a Python program that: Create the algorithm in both flowchart and pseudocode forms for the following requirements: Reads in a series of positive integers,  one number at a time;  and Calculate the product (multiplication) of all the integers less than 25,  and Calculate the sum (addition) of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. [ If the input is 0 that means the end of the input list. ]...
Write an algorithm (in pseudocode, with proper indentation for blocks of code in loops or conditional...
Write an algorithm (in pseudocode, with proper indentation for blocks of code in loops or conditional statements) that finds and returns the location of the first negative integer in a sequence of integers.
1 The purchases of items from foreigners will be equal to the sales of items to...
1 The purchases of items from foreigners will be equal to the sales of items to foreigners. True False 2 The following chart indicates a hypothetical newspaper quotation of the exchange rates of various currencies. U.S. Dollar Equivalent February 1 February 2 British pound 1.99 1.975 Canadian dollar 0.645 0.86 On February 2, the U.S. dollar (appreciated /depreciated) against the British pound. On February 2, the U.S. dollar (appreciated /depreciated)   against the Canadian dollar. 3 Suppose the exchange rate between...
1. There are three sets of assay data obtained from a set of standard solution in...
1. There are three sets of assay data obtained from a set of standard solution in an ELISA experiment (triplicate assay). Use Excel to draw a calibration curve. Then do the following: (a) Calculate the Lower Limit of Detection (LLOD) (b) Calculate the Limit of Quantitation (LOQ) (c) Calculate the Sensitivity of the assay (d) If an unknown sample gives an assay reading of 1.35. Use the calibration curve to determine the concentration of this sample. Concentration (ng/mL) Assay1 Assay2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT