Sunday, 2 June 2013

Number generating C++

Number generating C++

In your homework 1, you will write a program to generate the grades of all the students in your class, and calculate the distributions. Assume the following:
(1) The number of the students in your class is a random number between [131, 162]. (2) Every student's grade is a random integer between [10, 100]. (3) If the grade is in [10, 59], the letter grade is F; If the grade is in [60, 74], the letter grade is C; If the grade is in [75, 84], the letter grade is B; If the grade is in [85, 100], the letter grade is A. (4) You should calculate the highest grade (point grade, not letter grade) and lowest grade (point grade). (4) For your final output, please print the following: -- There are * students in my class! <-- A's B's C's F's -- The highest grade is ! -- The lowest grade is **!
Please note that you need to substitute these *'s with numbers you generated from your program. A screenshot of a sample output could be found in the attachment; notice that numbers in it are just randomly generated.
I am having a hard time with the first part of this homework in which u have to generate # of students between the range specified.
This is what I am doing
    int randomN;
randomN = rand()% 31+131;
it gives me one number obviously. What I am having trouble implementing is that number into an array ranging from 1 to the random number that comes out. I've used MATLAB before and in there you would do something like x = 1:randomN and it will generate an array. How do I do this on C++? and if you have to use loops, could u please give me hints on that? Thank you.

No comments:

Post a Comment