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

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

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • Arrays and reading from a file USE C++ to write a program that will read a...

    Arrays and reading from a file USE C++ to write a program that will read a file containing floating point numbers, store the numbers into an array, count how many numbers were in the file, then output the numbers in reverse order. The program should only use one array and that array should not be changed after the numbers have been read. You should assume that the file does not contain more than 100 floating point numbers. The file name...

  • In C Write a couple of functions to process arrays. Note that from the description of...

    In C Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an int array and size, and...

  • l ask Write a C++ program that accomplishes the following tasks 1. Write a function that...

    l ask Write a C++ program that accomplishes the following tasks 1. Write a function that finds the average of current element and the next element in given array named as "elements" and stores the new found averages into another array called "averageArray". Note: For the last element you can just divide the value of last element by 2 Write a function that takes both the given array and average array you just created along with a variable "productofArrays" using...

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