Question

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 (6th Edition)

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

Below is the code in C++ for the above question:

#include<iostream>
using namespace std;

int main(){
   // integer array of size 5
   int arrayValue[5];
   // infinite loop
   while(1)
   {
       // prompts the user to enter the elements of array.
       cout << "Enter the elements of array: " << endl;
       for(int i=0;i<5;i++){
           // getting user input
           cin >> arrayValue[i];
       }
      
       // variable to calculate sum and average
       int sum = 0;
       double average;
       // calculating sum and displaying the elements of array
       for(int i=0;i<5;i++){
           sum += arrayValue[i];
           cout << arrayValue[i] << " ";
       }
       // calculating average
       average = sum/5.0;
       // displaying sum and average
       cout << "\nSum = " << sum << "\nAverage = " << average;
      
       // getting user choice to continue or not.
       char choice;
       cout << "\nDo you want to continue (y/n)? ";
       cin >> choice;
      
       if(choice == 'n')
           break;
   }
   return 0;
}

Refer to the screenshot attached below to better understand the code and indentation:
{ 1 #include<iostream> 2 using namespace std; 3 4 int main() { 5 // integer array of size 5 6 int arrayValue[5]; 7 // infinit

Output:
= Enter the elements of array: 5 6 1 2 В 5 6 1 2 3 Sum m = 17 Average 3.4 Do you want to continue (y/n)? y Enter the elements

If this answer helps you then please upvote,
for further queries comment below.
Thank you.

Add a comment
Know the answer?
Add Answer to:
Use DevC++ 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 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)

  • 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.

  • Use DevC++ to implement a program uses objected oriented programming to calculate the area of a...

    Use DevC++ to implement a program uses objected oriented programming to calculate the area of a rectangle. The program should create a Rectangle class that has the following attributes and member functions: Attributes: width and length Member functions: setWidth(), setLength(), getWidth() , getLength(), getArea() Where width and length are the respect width and length of a Rectangle class. The setWidth() and setLength() member function should set the length and width, the getWidth(), getLenght(), and getArea() member function should get the...

  • 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...

  • 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...

  • Write a program that asks the user to input 5 integers in an Array named "gradearray.”...

    Write a program that asks the user to input 5 integers in an Array named "gradearray.” then passes gradearray in a function to find how many passing grades exist. (passing grades are between 60 and 100) Input elements for the gradearray : 67 43 90 100 75 There are 4 passing grades There are 1 failing grades

  • 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...

  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • Write a program that asks the user to input 10 integers of an array. The program...

    Write a program that asks the user to input 10 integers of an array. The program then inserts a new value at position (or index) given by the user, shifting each element right and dropping off the last element. For example, in the sample input/output below, the program will insert the value 30 at index 3. All the previous numbers of the array starting from position 3 (i.e., 7 1 20 9 23 8 22 will be shifted one position...

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