Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code from project 5 #include #include #define SIZE 100 #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif #include int main() { int done, choice,

image text in transcribed

Code from project 5

#include #include #define SIZE 100 #ifndef FALSE #define FALSE 0 #define TRUE !FALSE #endif #include

int main() { int done, choice, N, j, numbers;//declaration of variables float n[SIZE], x[SIZE], arr[0], smallest, largest;//declaration of variables float sum, avg, sum1, variance, standard_deviation, temp;//declaration of variables done=FALSE;

printf("Program to process a list of numbers ");//display while(!done){ printf("Select the desired opersation: "); printf("\t 0 Enter list of numbers "); printf("\t 1 Find the smallest number "); printf("\t 2 Find the largest number "); printf("\t 3 Find the average of the numbers "); printf("\t 4 Find the standard deviation of the numbers "); printf("\t 5 Reverse the list of numbers "); printf("\t 6 Rotate the list of numbers to the right "); printf("\t 7 Rotate the list of numbers to the left "); printf("\t 8 Exit the program "); printf("choice? "); scanf("%d",&choice); switch(choice){ case 0: printf("How many numbers?"); scanf("%d",&numbers);

for (int i =0; ilargest) { largest = n[i]; } } printf("The largest number is: %.2f ", largest);//display break; /////////////////////////////////////////////////////////////////// case 3: avg=sumumbers;//average printf("The average is: %.2f ", avg);//display results break; /////////////////////////////////////////////////////////////////// case 4: for (int i=0; i = 0; --i, ++j){ x[j]=n[i];//reverse numbers } for (int i=0; i = 0; --i){//switches position n[i+1] = n[i]; } n[0] = temp; printf("array is: now ");//display results for (int i =0; i

CODE: From project 5:

This lab assignment is derived from a requirement in Programming Project 5-Arrays, which presents the user a menu of operations that it can perform to manipulate an array floating point numbers. The choices are listed and a prompt a waits for the user to select by entering a number. This kind of menu is a common feature of command-line programs. It can be implemented to execute in the mai n() function as we do in this lab or it can be implemented in a function known as the command-chooser that returns a numeric value for a choice that can be passed to another function known as the command dispatcher Define symbolic constants for FALSE and TRUE Use itifndef FALSE to determine if these symbolic constants are already defined and if not define both main0 function int done FALSE: is a flag used to determine if the user has finished using the program or not while-loop not done Pk command chooser printfo list of menu choices The first part of the command chooser prints a menu that lists choices for the user. Each choice is a string that begins with the value to be entered on the keyboard to make the choice and ends with a brief description of an operation. do while scanf0 has returns 0 integer values as choice scanf() can be used to read a number, character, or string from the keyboard. scanfO also returns an integer whenever it is called usually this value is not important, but for the command chooser it is essential command dispatcher switch(choice for the case that corresponds to the value of choice A switch-case state structure supports a compact com mand dispatcher. one choice set done TRUE The command choice to exit the program sets the done flag to TRUE other choices are program operations All other command choices perform an operation either inline or by calling a function with or without arguments Operations that depend on other operations can use a flag to determine if the necessary prior operations have been completed default prints invalid choice message The scant logic cannot stop all invalid choices, but the default case of the switc structure can catch the others and h() print a message The while loop can then continue prompting the user to select an operation or to quit at end of while-loop say Goodbye

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

Recommended Textbook for

More Books

Students also viewed these Databases questions