Question

c++ help

Write a program that: Creates two finite arrays of size 10 These arrays will serve as a storing mechanism for student grades in Classes A and B Uses a loop to populate the arrays with randomly generated numbers from 0 to 100.These numbers will represent student grades. Compute average grade of each class. Finally, output the two arrays and the message with two averages and best class. (Class A average is: 65.43; class B average is: 68.90. Class B wins!) Please Note: To generate random numbers you will use the function srand0. srand0 function takes a seed value. You are required to ask the user to input a seed value. And please call srandO function using the seed value entered by the user. For example: int seed_value cin>>seed value; srand (seed_value) /I this is how srand) function will get called in your code 3 - Sample Output For example, suppose the array for class A looks like int class-A [10] = {10, 20, 30, 40, 50, 60, 70, 80, 90·10} · Suppose the array for class B looks like int classB [10 (21, 10, 19, 17,80,100, 50, 30,22,5 The output should be Class A average is: 46 Class B average is: 35.4 Class A wins!

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

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
int seed_value;
cout << "Enter the seed value:" << endl;
cin >> seed_value;
srand (seed_value);
int A[10],B[10];
for(int i=0;i<10;i++) {
A[i]=rand() % 101;
B[i]=rand() % 101;
}
int classASum = 0,classBSum = 0;
double classAAverage,classBAverage;
for(int i=0;i<10;i++) {
classASum+=A[i];
classBSum+=B[i];
}
classAAverage = classASum/10.0;
classBAverage = classBSum/10.0;
cout<<"Class A average: "<< classAAverage<<endl;
cout<<"Class B average: "<< classBAverage<<endl;
if(classAAverage<classBAverage) {
cout<<"Class B wins"<<endl;
} else {
cout<<"Class A wins"<<endl;
}
return 0;
}

Output:

$g++ -o main *.cpp
$main
Enter the seed value:5
Class A average: 44
Class B average: 41.2
Class A wins
Add a comment
Know the answer?
Add Answer to:
c++ help Write a program that: Creates two finite arrays of size 10 These arrays will...
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
  • In C++ Write a function that accepts two int arrays of the same size. The first...

    In C++ Write a function that accepts two int arrays of the same size. The first array will contain numbers and the second array will be filled out inside the function. The function should find all numbers in the array that are greater or equal to the average and fill out the second array with these numbers. You need to design the function. I tried this code but the errors returned were: expression must have a constant value #include<iostream> using...

  • 1. Write a program that reads in two arrays (a1 and a2) of numbers and creates...

    1. Write a program that reads in two arrays (a1 and a2) of numbers and creates a new array (a3) of numbers such that the new array contains all the unique numbers of a1 and a2. Assume the input array elements are unique elements. In the main function, ask the user to enter the length of each array, declare and reads in the numbers for each array, and calculate and display the output array. Example input/output #1: Enter the length...

  • Language C Code Write a program that takes two integer arrays (A and B) and sums...

    Language C Code Write a program that takes two integer arrays (A and B) and sums them together (element wise). A third array to accept the result should be passed in as the output argument. Assume the arrays are all the same size. The argument N is the size of the arrays. Your code should provide a function with the following signature: void array Addition (int A[], int B[], int N, int output[]) { } Your code must also provide...

  • Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4...

    Must be done in C++ 2013 microsoft visual studio Write a program that creates a 4 x 5 two-dimensional array. The program should use loops to populate the array using the rand, srand and time functions with random numbers between 10 and 60. After the values have populated the array, output the values of the array to the screen in something that looks like a 4 x 5 table.

  • Write a program that works with two arrays of the same size that are related to...

    Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:  from a previous program, populations and the associated flowrates for those populations (an int array of populations and a double array...

  • Create a program that creates an array of 500 random numbers between -10 and 10. Write...

    Create a program that creates an array of 500 random numbers between -10 and 10. Write several functions: Function 1 - prints the array with a certain number of elements per line. Prototype: void printArray(int array[], int numElements, int numPerLine, ostream &os) Function 2 prints only the array elements that are evenly divisible by an input number. Prototype: void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os) Function 3 takes the input array and returns the maximum, the...

  • Language: C++ Course: Computer Programming for Engineers Write a program that creates two 3x4 arrays of...

    Language: C++ Course: Computer Programming for Engineers Write a program that creates two 3x4 arrays of type "int". Populate each array with random integers between 1 and 9. Also ask the user to choose whether they want to add the arrays or subtract the second array from the first array. Output all three arrays in tabular form.

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • Class Average Create a program that dynamically creates an array whose size depends on the user's...

    Class Average Create a program that dynamically creates an array whose size depends on the user's preference. Pass the array to a calculate_avg function that is responsible for computing the average GPA of the given array. Use pointer arithmetic throughout your program. calculate_avg Create a function called calculate_avg that calculates the average of a double array and returns that average. calculate_avg() will have two parameters: a double* referring to the array an int that contains the size of the given...

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