Array

1.Rewrite the program on cumulative final grade. This time:
a. use rectangular arrays.
b. Use array for student name which are also inputted during runtime.
c. Display the student name instead of student# in the final screen output.

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Compute for the prelim grade of 5 students
#include <iostream>
using namespace std;
void main()
{
int iCS[5], iAQ[5], iPT[5], iPG[5], iCt;

// initialize all variables
for (iCt = 0; iCt < 5; iCt++)
{
iCS[iCt] = iAQ[iCt] = iPT[iCt] = iPG[iCt] = 0;
}

// ask for the Class Standing
cout << "Student Name" ;
cin >> sn;
cout << "Enter the Class Standing: " << endl;
for (iCt = 0; iCt < 5; iCt++)
{
cout << (iCt + 1)
     << " ";
 cin >> iCS[iCt]; }

// Ask for the Average Quiz
cout << endl << endl
        << "Enter the Average Quiz: " 
        << endl;
for (iCt = 0; iCt < 5; iCt++)
{
cout << (iCt + 1)
        << " ";
   cin >> iAQ[iCt]; }


// ask for the Periodic Test
cout << endl << endl
        << "Enter the Periodic Test: "
        << endl;
for (iCt = 0; iCt < 5; iCt++)
{
cout << (iCt + 1)
        << " ";
  cin >> iPT[iCt]; }

// compute for the cummulative final grade
for (iCt = 0; iCt < 5; iCt++)
iPG[iCt] = (iCS[iCt] + iAQ[iCt] + iPT[iCt]) / 3;

// display the output
cout << endl << endl;
cout << "Student#"
       << " CS "
       << "AQ "
       << "PT "
       << "PG "
       << endl << endl;
for (iCt = 0; iCt < 5; iCt++)
{
cout << (iCt + 1)
        << "       " << iCS[iCt]
        << " " << iAQ[iCt]
        << " " << iPT[iCt]
        << " " << iPG[iCt]
        << endl; 

}
system("PAUSE");
}

Last edited on
So, what is your problem all about?
1.Rewrite the program on cumulative final grade. This time:
a. use rectangular arrays.
b. Use array for student name which are also inputted during runtime.
c. Display the student name instead of student# in the final screen output.
You've restated the original problem statement (which you already posted).
You have not said what problem you're having.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
I want to enter student name with test results and display it in the output instead of the
number only. my problem is i cannot display student names in the output ?
Where should i insert this in the existing code?

1
2
cout << "Student Name" ;
cin >> sn;



Last edited on
Line 16: sn is undefined.

Since you can calculate grades for 5 students, you want sn to be an array.

1
2
3
4
5
6
7
8
#include <string>
...
string sn[5];
...
  for (int i=0; i<5; i++)
  {  cout << "Enter the name of student " << i+1;
      cin >> sn[i];
  }


The above example is just showing entering student names in a simple loop. In your code, you probably want to enter all the information about a student together.

Last edited on
Topic archived. No new replies allowed.