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.
1. Design and implement a program that reads a series of integers from the user and...
1. Design and implement a program that reads a series of integers from the user and continually prints their average after every reading. The input stops when the user enters “stop” as the input value. Read each input value as a string, then check if it is “stop” or not. If the string is not “stop”, 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...
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, 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 integer), display an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
Program in Java Create a stack class to store integers and implement following methods: 1- void...
Program in Java Create a stack class to store integers and implement following methods: 1- void push(int num): This method will push an integer to the top of the stack. 2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
Program in Java Create a queue class to store integers and implement following methods: 1- void...
Program in Java Create a queue class to store integers and implement following methods: 1- void enqueue(int num): This method will add an integer to the queue (end of the queue). 2- int dequeue(): This method will return the first item in the queue (First In First Out). 3- void display(): This method will display all items in the queue (First item will be displayed first). 4- Boolean isEmpty(): This method will check the queue and if it is empty,...
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!!
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT