Question

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

Use C++ 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. (5 points)

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

3. Continue to ask the user to store for storing data into another array. (10 points)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

**** Here's the code for the given problem which is very easy to understand ****

#include <bits/stdc++.h>
using namespace std;


int main()
{
    int arrayValue[5], temp[5];
    cout<<"Enter the array values: ";
    for(int i=0;i<5;i++)
    {
        cin>>arrayValue[i];
    }
    int sum=0, avg;
    for(int i=0;i<5;i++)
    {
        sum+=arrayValue[i];
    }
    avg=sum/5;

    cout<<"Sum of the array is: "<<sum<<endl;
    cout<<"Average of the array is: "<<avg<<endl;
    cout<<"Array elements are: ";
    for(int i=0;i<5;i++)
    {
        cout<<arrayValue[i]<<" ";
    }
    string s;
    cout<<"\nDo you want to store the array values in another array? (Yes/No) : ";
    cin>>s;

    if(s=="Yes")
    {
        for(int i=0;i<5;i++)
        {
            temp[i]=arrayValue[i];
        }
        cout<<"Elements are successfully stored in another array.";
    }
    else
    exit(0);

}

OUTPUT:

Enter the array values: 1 2 3 4 5 Sum of the array is: 15 Average of the array is: 3 Array elements are: 1 2 3 4 5 Do you wan

Explaination: Firstly two arrays are created: arrayValue and temp. After that we ask user to enter the array elements. After that we calculate sum and average of the array and displays it. Then we ask user that if he/she wants to store the array elements into another array? If the answer is "Yes" (which is stored in the string s) then we store the arrayValue into temp array and display "Elements are successfully stored in another array" else we exit the code.

Add a comment
Know the answer?
Add Answer to:
Use C++ to implement a program that can store and output 5 integers, where the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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. (5 points) 2. Output the content (value) that stored in the array of five elements. (10 points) 3. Continue to ask the user to store for storing data into another array(store and output 5 integers). (10 points) Prelude to Programming...

  • I need help with the C++ for the following problem: Write a program that can store...

    I need help with the C++ for the following problem: Write 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.

  • Write a c program to implement threads. Accept an array of 40 integers, write a thread...

    Write a c program to implement threads. Accept an array of 40 integers, write a thread method named sum of array elements. Divide the array into 4 equal elements and call threads to find the sum of each part. Store the sum in a variable called “arrays'. Print the sum in the main function. (10 points)

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Java Program Create a class to store an array of with enough space to store 10 integer values. Us...

    Java Program Create a class to store an array of with enough space to store 10 integer values. Using the principle of recursion, implement the following: *getSize : returns the size of the array. *get (i): returns the i-th element of the array. If the element does not exist, it throws a "NoSuchElementException” which is a subclass of Java class RunTimeException. *add (val): inserts value as the last element of the array. If necessary, double the size of the current...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • Please help C++ language Instructions Write a program that prompts the user to enter 50 integers...

    Please help C++ language Instructions Write a program that prompts the user to enter 50 integers and stores them in an array. The program then determines and outputs which numbers in the array are sum of two other array elements. If an array element is the sum of two other array elements, then for this array element, the program should output all such pairs.

  • Write a C++ program that simulates a lottery game. Your program should use functions and arrays....

    Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...

  • Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program...

    Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements:  The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...

  • in JAVA program.Use top-down design to design and implement a program to ask the user to...

    in JAVA program.Use top-down design to design and implement a program to ask the user to enter a list of integers, and then display to the user the mean and median of this list. You should first prompt the user to specify the length of the list of integers. For this assignment, your code should create an array of size 10, and then allow the user to specify the number of integers in their list, up to a maximum of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT