Struct

Apr 14, 2015 at 7:20pm
A. Using C++, define a struct Student which has three properties: id, score, and grade. id is in integer type, score is in double type, and grade is in char type. Using Student to declare an array with 20 elements in main(); assign the ids of each student from 1 to 10; assign the scores of each student with random within [10,99]; then define a function and pass the Student array as parameter(s). In the function, assign the grade of each student according to his scores (e.g. if the score is >=90, assign 'A' grade; else if score is >=80, assign 'B' grade; else if score is >=70, assign 'C'; else if score is >=60, assign 'D'; otherwise , assign 'F'); after the function returns, print all students' ids, scores, and grades accordingly.

B. Redefine the function to assign grades, but change it to a recursive one.

My question is, so far, do I have the grade assigning & the random number part correct? Also, I need assistance with part B of the problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  int getRandomNumber()
{
	int b = (rand() % 100) +1;

	if (b< 10)
	{
		b = (rand() % 100) +1;
	}

	else if (b > 99)
	{ 
		b = (rand() % 100) +1;
	}

	return b;
}

void ComputeTheGrade()
{
	if (score > 100)
	{
		cout << " Invalid Score for Grade. Please Try Again." << endl;
	}
	else if (score >= 90 && score <= 100)
	{
		cout << "Letter Grade is A!" << endl;
	}
	else if (score >= 89 && score <= 80)
	{
		cout << "Letter Grade is B!" << endl;
	}
	else if (score >= 79 && score <= 70)
	{
		cout << "Letter Grade is C!" << endl;
	}
	else if (score >= 69 && score <= 60)
	{
		cout << "Letter Grade is D!" << endl;
	}
	else
	{
		cout << "Letter Grade is F!" << endl;
	}

	cout << endl;
Last edited on Apr 14, 2015 at 7:34pm
Apr 14, 2015 at 7:58pm
The grade assigner is to take an array as an argument.

Aceix.
Apr 14, 2015 at 8:01pm
You could always test it and find out for yourself.
Topic archived. No new replies allowed.