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

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 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.
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...
The goal of this exercise is to implement the shuffling algorithm from this chapter. 1. In...
The goal of this exercise is to implement the shuffling algorithm from this chapter. 1. In the repository for this book, you should find the file named Deck.java. Check that you can compile it in your environment. 2. Implement the randomInt method. You can use the nextInt method provided by java.util.Random, which we saw in Section 7.6. Hint: To avoid creating a Random object every time randomInt is invoked, consider defining a class variable. 3. Write a swapCards method that...
Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
Write pseudocode to implement the paranoid algorithm. (You vs 2 other players)
1. Perform a Desk check for the following pseudocode algorithm L1: Program AddFirst5Numbers; L2: Data Counter...
1. Perform a Desk check for the following pseudocode algorithm L1: Program AddFirst5Numbers; L2: Data Counter as Integer; L3: Data Sum as Integer; L4: Counter:= 1; L5: Loop until Counter = 5 L6: Sum := Sum + Counter; L7: counter := counter + 1; L8: Next Loop; L9: Output “The sum is”, Sum; L9: End AddFirst5Numbers; 2. Write a pseudocode algorithm to print the following pattern 2 4 6 8 10 3. Using nested loops, write a pseudocode algorithm to...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT