Question

In: Computer Science

You are required to write an interactive program that prompts the user for ten (10) real...

You are required to write an interactive program that prompts the user for ten (10) real numbers and performs the following tasks:

  1. Reads and stores the numbers into one-dimensional array called A. The program must use a function to perform this task.
  2. Prints the content of the array. Write a function to perform this task.
  3. Calculates the sum of the numbers. Use a function to perform this task.
  4. Find the average of the numbers. Utilize a function to perform this task.
  5. Prints the sum and the average. Write a function that receives these values and print them.

Program requirements:

-     The program must utilize a class, an object and all the necessary functions to perform the above tasks.

-     The program must be fully documented.

-    You must submit a hard copy of the source and a properly labeled output.

-     You should submit a digital copy of source code.

-     Test your program for different values using real numbers.

Solutions

Expert Solution

#include <iostream>
using namespace std;
class Array{
private:
int *A; // pointer type array aka dynamic array
int size; // size of array
public:
Array(){ //default constructor sets size to 10
size=10;
A= new int[size]; // allocate memory of 10 blocks for array A
}
Array(int siz){ // if user gives size
size=siz; // set size
A= new int[size]; // allocate memory of size entered
}
// mutators of array and size
void setArray(int *arra){
A=arra;
}
void setSize(int siz){
size=siz;
}
// accessors of array and size
int *getArray(){
return A;
}
int getSize(){
return size;
}
void readData(){ // input array data
cout<<"Enter values for your array: ";
for(int i=0;i<size;i++){ // loops iterate till size
cin>>A[i]; // read and store into array
}
}
void print(){ // printing data
cout<<"::::::: ARRAY DATA ::::::::"<<endl;
for(int i=0;i<size;i++){
cout<<A[i]<<" ";
}
cout<<endl;
}
int calculateSum(){
int sum=0; // intialize to 0
for(int i=0;i<size;i++){
sum=A[i]+sum; // update sum
}
return sum;
}
int calculateAverage(int sum){ // sum will be passed
return sum/size; //average of array data
}
void printSumAndAverage(int sum, int average){ // we will be passing sum and average
//print them
cout<<"SUM: "<<sum<<endl;
cout<<"AVERAGE: "<<average<<endl;
}

};
int main()
{
Array a; // by default size of 10 as told
a.readData();// read and store data
a.print(); // print them
cout<<endl;
// sum and average will be calculated before printSumAndAverage program will run
a.printSumAndAverage(a.calculateSum(),a.calculateAverage(a.calculateSum()));
return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP


Related Solutions

You are required to write an interactive program that prompts the user for two integers X...
You are required to write an interactive program that prompts the user for two integers X and Y and performs the following tasks: Adds two numbers Subtracts Y from X Multiplies X and Y Divides X by Y Finds which numbers is larger X oy Y) Prints all the results (a , b, c, d, and e) Program requirements: -     The program should run as many times as the users wish -     The program should be fully documented. -   ...
You are required to write an interactive JS program that prompts the user for three numbers...
You are required to write an interactive JS program that prompts the user for three numbers and then finds the sum, average, smallest, and the largest value of the numbers and prints the results labeling properly.
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user...
c# In Chapter 2, you created an interactive application named MarshallsRevenue. The program prompts a user for the number of interior and exterior murals scheduled to be painted during the next month by Marshall’s Murals. Next, the programs compute the expected revenue for each type of mural when interior murals cost $500 each and exterior murals cost $750 each. The application also displays the total expected revenue and a statement that indicates whether more interior murals are scheduled than exterior...
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
write this program in C++ Write a program that prompts a user for three characters. The...
write this program in C++ Write a program that prompts a user for three characters. The program must make sure that the input is a number 10 - 100 inclusive. The program must re prompt the user until a correct input is entered. Finally output the largest and the lowest value. Example 1: Input : 10 Input : 20 Input : 30 The largest is 30. The lowest is 10. Example 2: Input : 100 Input : 50 Input :...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for...
Please Write C++ PROGRAM : That will write a program that initially prompts the user for a file name. If the file is not found, an error message is output, and the program terminates. Otherwise, the program prints each token in the file, and the number of times it appeared, in a well formatted manner. To accomplish all this, do the following: - Open the file - the user must be prompted and a file name input. DO NOT hardcode...
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a Java program that prompts a user for 10 integers. When completed it outputs the...
Write a Java program that prompts a user for 10 integers. When completed it outputs the highest number, the lowest number, the number of odd number, and the average of the numbers
JAVA Program Write a program that prompts the user for data until the user wishes to...
JAVA Program Write a program that prompts the user for data until the user wishes to stop (you must have a while loop) (You must read in at least 8 to 10 sets of voter data using dialog boxes) The data to read in is: The registration of the voter (Democrat, Republican or other) The gender of the voter The Presidential candidate the voter is choosing (Trump or Biden) Which candidate has done better to manage the economy? (Trump or...
Write a program that prompts the user to input a string. The program then uses the...
Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning of your program and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT