Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

functions, local variables, global variables Computing sum, min, max, and average Description: You will write a basic program that let the user to compute the

  • functions, local variables, global variables

  • Computing sum, min, max, and average

    Description: You will write a basic program that let the user to compute the sum, the average, the min and the max of integer numbers entered by the user. The user interacts with the program through a command prompt. Below are the commands:

  • add

  • print

  • exit

-- trigger the DATA prompt for user to add data. -- triggers the WHAT prompt for what to print -- ends the program

When the user types add at the command > prompt, it takes user to the DATA prompt. The user can type in data as integer one at a time. The user hit the key to input the next number. When the user is done inputting data, the user types done at the DATA prompt to return to the main command > prompt.

When the user type print at the command > prompt, the user is presented with WHAT prompt. Here, the user type what values the user wants to see. The possible values are sum, avg, min, and max. If the user has yet to enter any data, then the program prints Not available. Please enter data first.

Functions: Below are the functions you will write.

main() o Displaythecommandprompt> o Read a command from the user. Valid commands are add, print, and exit. o Print Unknown command for invalid command o Call the appropriate function to handle the command o Ignoreblanks(userhittheenterkeywithoutacommand) o Usertypes"exit"toendprogram.

handle_add() o Promptsfordata,onevalueatatime. o User types "done" to end reading of data and return to command prompt >. o Update sum, average, min, max, and count to account for added data o extra credits:

user type random at DATA prompt to generate random data Ask for lower bound, upper bound, and how many data points Displays the random numbers as a table of 10 columns Update sum, average, min, max, and count

handle_print() o Prompts the user for what to print. Valid options are: min, max, sum, avg o Print I dont know what that is. If invalid option is entered. o Printtheresultforwhatisrequested. o If no data has been entered, then print Not available. Please enter data first."

Sample run:

Welcome to Pystats > print WHAT: sum Not available. Please enter data first. > add

DATA: 10 DATA: 20 DATA: 5 DATA: 90 DATA: done > print WHAT: min 5 
> print WHAT: max 90 > print WHAT: avg 31.25 
> > add DATA: 1 DATA: 1000 DATA: done > print WHAT: min 1 > exit Goodbye! Hit  key to end. 

Extra credit sample un:

Welcome to Pystats > add DATA: 10 DATA: random lower bound: 0 upper bound: 100 data points: 25 RANDOM DATA 

1537317192418 02748 25 94 60 22 58 93 52 31 77 62 52 59 28 81 65

DATA: 500 DATA: done 
> print WHAT: min 0 > print WHAT: max 500 
> print WHAT: sum 1649 > add DATA: 2000000 DATA: done 
> print WHAT: max 2000000 > exit Goodbye! Hit  key to end.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What were some of the team roles at Casper?

Answered: 1 week ago