Question

In: Computer Science

Use DevC++ to implement a program that can store and output 5 integers, where the user...

Use DevC++ to implement a program that can store and output 5 integers, where the user can input its value into an array named arrayValue. The program should implement the following:

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Continue to ask the user to store for storing data into another array.

c++ ONLY PLEASE NEED IT FAST AS POSSIBLE

Solutions

Expert Solution

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

#include<iostream>

using namespace std;

//method to ask user to enter size number of elements and store it in an array

void readArray(int *arr, int size){

                cout<<"Enter "<<size<<" integers: ";

                //reading size number of elements, storing in array

                for(int i=0;i<size;i++){

                                cin>>arr[i];

                }

}

//method to print the contents of an array

void printArray(int *arr, int size){

                cout<<"Array: ";

                //looping and printing

                for(int i=0;i<size;i++){

                                cout<<arr[i];

                                //if this is not last element, printing a comma and space

                                if(i!=size-1){

                                               cout<<", ";

                                }

                }

                cout<<endl;

}

//finds the sum of values in an array, returns it

int sum(int *arr, int size){

                int s=0;

                //summing values

                for(int i=0;i<size;i++){

                                s+=arr[i];

                }

                return s;

}

//finds the average of values in an array, returns it

double average(int *arr, int size){

                //finding sum

                int s=sum(arr,size);

                //finding average

                double avg=(double) s/size;

                return avg;

}

//method to display a menu to the user

void displayMenu(){

                cout<<"1. Calculate the sum and average of the array."<<endl;

                cout<<"2. Output the content (value) that stored in the array of five elements."<<endl;

                cout<<"3. Input another set of values."<<endl;

                cout<<"4. Quit"<<endl;

                cout<<"Enter your choice: ";

}

//main method

int main(){

                //setting up an integer array of size 5

                const int size=5;

                int arr[size];

                //reading initial values

                readArray(arr,size);

                int ch=0;

                //looping until user wish to quit

                while(ch!=4){

                                //displaying menu

                                displayMenu();

                                //getting choice

                                cin>>ch;

                                //handling choice

                                switch(ch){

                                               case 1: cout<<"Sum is "<<sum(arr,size)<<" and average is "<<average(arr,size)<<endl;

                                               break;

                                               case 2: printArray(arr,size);

                                               break;

                                               case 3: readArray(arr,size);

                                               break;

                                               case 4: cout<<"Bye!"<<endl;

                                               break;

                                }

                }

               

                return 0;

}

/*OUTPUT*/

Enter 5 integers: 1 2 3 4 5

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 1

Sum is 15 and average is 3

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 2

Array: 1, 2, 3, 4, 5

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 3

Enter 5 integers: 15 16 17 22 0

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 1

Sum is 70 and average is 14

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 2

Array: 15, 16, 17, 22, 0

1. Calculate the sum and average of the array.

2. Output the content (value) that stored in the array of five elements.

3. Input another set of values.

4. Quit

Enter your choice: 4

Bye!


Related Solutions

Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
5. Take user input and give corresponding output. User will enter a sentence. The program will...
5. Take user input and give corresponding output. User will enter a sentence. The program will output the word that appears most frequently in this sentence. If there are multiple words with same frequency, output the first of these words. Please enter a sentence: I like batman because batman saved the city many times. The most frequent word is: batman The frequency is: 2 PYTHON
Write a program that ask the user for three integers. Use two functions to determine the...
Write a program that ask the user for three integers. Use two functions to determine the largest and smallest number of the three. One function will determine the largest number, and the other function will determine the smallest number. (6 points) In c++ using functions.
Write a program where you- 1. Create a class to implement "Double Linked List" of integers....
Write a program where you- 1. Create a class to implement "Double Linked List" of integers. (10) 2. Create the list and print the list in forward and reverse directions. (10)
Write a java program that will ask the user to enter integers (use loops) until -100...
Write a java program that will ask the user to enter integers (use loops) until -100 is entered. The program will find and display the greatest, the smallest, the sum and the average of the entered numbers. also write a separate driver class which will be used to run and display the greatest, the smallest, the sum and the average of the entered numbers. Thanks!!
Write a program Write a program whose inputs are three integers, and whose output is the...
Write a program Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 C++ please
please using Repl.it basic C-programing part1 Write a program that requests 5 integers from the user...
please using Repl.it basic C-programing part1 Write a program that requests 5 integers from the user and stores them in an array. You may do this with either a for loop OR by getting a string from stdin and using sscanf to store formatted input in each spot in the array. part2 Add a function to the program, called get_mean that determines the mean, which is the average of the values. The function should be passed the array and the...
Write a program to implement the IntStack that stores a static stack of integers and performs...
Write a program to implement the IntStack that stores a static stack of integers and performs the pop, push, isFull, and isEmpty operations. Write the main class to create a static stack of numbers 10, 20, 30, 40, and 50 then try the member functions. C++
Write a program to implement the IntStack that stores a static stack of integers and performs...
Write a program to implement the IntStack that stores a static stack of integers and performs the pop, push, isFull, and isEmpty operations. Write the main class to create a static stack of numbers 10, 20, 30, 40, and 50 then try the member functions. C++
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT