Question

C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

C++ Program

Int Main First Please

Write one program that does the following:

1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average.

a.       Declare an integer array with the name of “grades” of size 10 in the main function.

b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.

                                                               i.      The function will receive an integer array and the size of the array.

                                                             ii.      In the function prototype and the function header, call the array “gradeArray” and call the size of the array "size."

                                                            iii.      Create a For Loop that cycles through each cell of the array.

                                                           iv.      At each cell prompt the User for a grade.

                                                             v.      Store the grade entered by the User into the array cell.

c.       From main, send this function the array called “grades” and the size of the array.

d.      Create a function called “computeAverage” that computes the average of an array of integers and returns the average as a float.

                                                               i.      The function will receive an integer array and the size of the array.

                                                             ii.      In the function prototype and the function header, call the array “numbers” and call the size of the array "size."

                                                            iii.      Create a For Loop that cycles through each cell of the array and computes a running total of the values stored in the array.

                                                           iv.      Use the size of the array to compute the average from the running total.

                                                             v.      Return the average through the function name.

e.      From main, send this function the array called “grades” and the size of the array.

f.       From main, print out the average returned by computeAverage.

g.        Create a third function called “printInts” that will print out the contents of an integer array.  This function will be void.

                                                               i.      The function will receive an integer array and the size of the array.

ii.    In the function prototype and the function header, call the array “intArray” and call the size of the array "size."

iii.      Create a For Loop that prints out the contents of the array.

2.      2.   Generate 20 random numbers within a range of 1 to 50 and store them in an integer array named “randomArray.”  Then print out the contents of the array.

a.       Create a function named “getRandom” that will generate a random number between any range.

                                                               i.      The function will receive two call-by-value arguments – the beginning value of the range and the ending value of the range.

                                                             ii.      Generate a random number within the specified range.

                                                            iii.      Send the random number back through the function name.

b.      In the main function, create a For Loop that cycles through the array called randomArray.

                                                               i.      With each cycle, call your getRandom function from main and store the random number it returns into your array.

c.       In main, call the function printInts to print out the contents of the array called randomArray.  Make sure you use the SAME FUNCTION you created in step 1.  You are just sending it a different array.

d.      Next, in the main function, call the function computeAverage to compute the average of the random numbers you stored in the array called randomArray.  Make sure you use the SAME FUNCTION you created in step 1.  You are just sending it a different array.

e.      In main, print out the average returned by computeAverage.

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

#include<iostream>
#include<stdlib.h>
using namespace std;

//function prototypes

void getGrades(int [],int);
float computeAverage(int [],int);

void printInts(int [],int );
int getRandom(int,int );

//driver program
int main()
{
    int grades[10],no,randomArray[20],x,y,i;
    float a;
    //ask for number of grades
    cout<<endl<<"Enter the number of grades";
    cin>>no;
    //call to getGrades();
    getGrades(grades,no);
    //display the grades
    cout<<endl<<"Grade values are : ";
    printInts(grades,no);
    //compute the average
    a=computeAverage(grades,no);
    //display the average
    cout<<endl<<"Average of the Grades is : "<<a;
    //ask for range to generate random numbers
    cout<<endl<<"Enter the begin value and end value to generate random numbers";
    cin>>x>>y;
    //loop to generate random numbers and store in randomArray
    for(i=0;i<20;i++)
    randomArray[i]=getRandom(x,y);
    //display the randomArray
cout<<endl<<"Random array elements are : ";
    printInts(randomArray,20);
    //compute the average
    a=computeAverage(randomArray,20);
    //display the average
    cout<<endl<<"Average of the random elements is : "<<a;
      
}


//defination of getGrades()
void getGrades(int gradeArray[10],int size)
{
   int i;
   for(i=0;i<size;i++)
   {
      cout<<endl<<"Enter a grade";
      cin>>gradeArray[i];
   }
}
//defination of computeAverage()
float computeAverage(int numbers[10],int size)
{
   int i,sum=0;
   float avg;
   for(i=0;i<size;i++)
   sum=sum+numbers[i];
   avg=(float)sum/size;
   return avg;
}
//defination of printInts()
void printInts(int intArray[10],int size)
{
    int i;
    for(i=0;i<size;i++)
    cout<<" "<<intArray[i];
}

int getRandom(int a,int b)
{
   int n;
   n=(rand() % (b + 1 - a)) + a;
   return(n);
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...
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
  • Fix this C++ code so that the function prototypes come before main. Main needs to be...

    Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...

  • Write a program that will do the following. The main function should ask the user how...

    Write a program that will do the following. The main function should ask the user how many numbers it will read in. It will then create an array of that size. Next, it will call a function that will read in the numbers and fill the array (fillArray). Pass the array that was made in themain function as a parameter to this function. Use a loop that will read numbers from the keyboard and store them in the array. This...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • Create a class called Student. This class will hold the first name, last name, and test...

    Create a class called Student. This class will hold the first name, last name, and test grades for a student. Use separate files to create the class (.h and .cpp) Private Variables Two strings for the first and last name A float pointer to hold the starting address for an array of grades An integer for the number of grades Constructor This is to be a default constructor It takes as input the first and last name, and the number...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc...

    The main(int argc, char *argv[]) function will perform the following: • Evaluate whether value in argc is greater or equal to 3. • If it is not, then print the following message: Incorrect number of arguments - please call with assignment min max where assignment is the name of your executable and min/max define the range of numbers for your array. • If argc is ≥ 3 convert the values for min and max into integers and store them in...

  • Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and...

    Q 3-) (30 points) Write a C program (MAIN function) and a FUNCTION to create and print the transpose of a two- dimensional array. Within C program (the MAIN function); Declare a two- dimensional 3X2 integer array A and initialise with the values (1,2), (3,4), (5,6), declare also a two-dimensional 2X3 integer array B and initialise it with zero. Call the FUNCTION and pass arrays A and B to the FUNCTION as arguments. Print the array A and its transpose....

  • Please write a C# program For this part of the lab, you'll be writing methods to...

    Please write a C# program For this part of the lab, you'll be writing methods to work with 1D arrays. We will expect you to know how to create an array, and store and retrieve information from them. Continue working in the same project and “Program.cs” file. You will be generating random numbers, but the class Random is part of the standard library (don’t need any additional using statements). You should consider developing the methods for this project incrementally. In...

  • 17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int...

    17.9 Worksheet 7 (C++) Follow the instructions commented into the given template. int main() { int array1[20] = {3, 18, 1, 25, 4, 7, 30, 9, 80, 16, 17}; int numElements = 11; cout << "Part 1" << endl; // Part 1 // Enter the statement to print the numbers in index 4 and index 9 // put a space in between the two numbers    cout << endl; // Enter the statement to print the numbers 3 and 80...

  • Please help code in c++ and use the answers you get from question 1 and 2...

    Please help code in c++ and use the answers you get from question 1 and 2 into the 3rd answer! Question 1 is first, question 2 is in the middle, question 3 is last Input Array (10 pts) te a function only (no main) that takes an array of doubles as a parameter as well as another integer rray. Create a for loop that asks the user to input any real number between-100 and r each element of the array....

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