Tech Support Forum banner

Another question regarding 2 dimensional array in VC++

2991 Views 1 Reply 1 Participant Last post by  melvynlyc
This is another headache problem or task for a C++ beginner like me.

This program needs me to write a program using 2 dimensional array. The program is to record test results for 5 students. The marks in these test is in the range of 0 to 100. This is the grading system:

90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

The application should allow user to input the student number and three test results,then compute each student's average and the class average. The application should display the student grade after caluculating the average.

Sample outputs:

Please enter student no: 1
Please enter test 1 : 87
Please enter test 2 : 94
Please enter test 3 : 93
The average is : 91.33
The grade is A
.
.
.
.
.
Student Number Test 1 Test 2 Test 3 Average Grade
1 87 94 93 91.33 A
2 21 33 60 38.00 F
3 60 75 70 68.33 D
4 80 99 75 84.67 B
5 65 80 88 77.67 C

Class Average: 71.87
Class Grade: C




The sample my lecturer gave me is some sort of thing like the above. I will include a coding that i tried but please dun laugh at me coz i am new to C++,i would like to thank u all in advance and hopefully i can get some help from u all. My main problem about this is how to display the result in a table like format(like shown above).

Thanks a million guys!
See less See more
Status
Not open for further replies.
1 - 2 of 2 Posts
here is the coding i written so far....btw...i juz noticed the display of the table had some problem in my last post. All those numbers and grades shouldn't be sticking together(gosh i am so noobie..can't even post a good thread). I hope u all can help me...i need assistance badly...

Program:-

//PREPROCESSOR DIRECTIVES
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

//GLOBAL CONSTANT DECLARATIONS
const X = 5;
const Y = 5;

//FUNCTION PROTOTYPES
void GetGrades(int table[X][Y],int &StudentNumber,int &Test1,int &Test2,int &Test,int &average,char &grade);
void DisplayTable(int table[X][Y],int StudentNumber,int Test1,int Test2,int Test3,int average,char grade);

struct studentgrade
{
int StudentNumber;
int test1;
int test2;
int test3;
int average;
char grade;
int table;

};

studentgrade student;

//THIS PROGRAM INPUTS HOMEWORK GRADES TO A TWO-DIMENSIONAL ARRAY.
//THE GRADES ARE THEN DISPLAYED IN A TABLE.

int main()
{
int table[X][Y];
int StudentNumber;
int Test1;
int Test2;
int Test3;
int average;
char grade;


//ProgramPurpose();
GetGrades(table,StudentNumber,Test1,Test2,Test3,average,grade);
DisplayTable(table,StudentNumber,Test1,Test2,Test3,average,grade);

cout << "\n\nPress any key to continue.";
getch();
return 0;
}//END main()

//THIS FUNCTION INPUTS STUDENT GRADES INTO A TWO-DIMENSIONAL ARRAY
void GetGrades(int table[X][Y],int &StudentNumber,int &Test1,int &Test2,int &Test3,int &average,char &grade)
{
for( int i =1 ; i <6 ; i ++)
{
cout<<"Please Enter Student No: ";
cin>>StudentNumber;
cout<<"Please Enter Test 1: ";
cin>>student.test1;

cout<<"Please Enter Test 2: ";
cin>>student.test2;

cout<<"Please Enter Test 3: ";
cin>>student.test3;

//Formula to calculate average
student.average = ( student.test1 + student.test2 + student.test3 ) /3;
cout<<"The average is:"<<student.average;

// Determine Student grade
if(student.average>=90 ){
// Grade A
student.grade='A';
}
else if (student.average>=80 ){
//Grade B
student.grade='B';
}
else if (student.average>=70 ){
//Grade C
student.grade='C';
}
else if (student.average>=60 ){
//Grade D
student.grade='D';
}
else
{
//Grade F
student.grade='F';
}
cout<<"\nThe Grade is \t: "<<student.grade<<"\n\n";
}
}//END GetGrades()

//THIS FUNCTION DISPLAYS STUDENT GRADES FROM TWO-DIMENSIONAL ARRAY IN TABLE
void DisplayTable(int table[X][Y],int StudentNumber,int Test1,int Test2,int Test3,int average,char grade)
{
cout<<setw(10)<<"Student No";
{
for (int Counter= 1; Counter<= 3; Counter++)

cout<<setw(10)<<"Test"<<Counter;

for (int row = 0; row < 1; row++)
{
for (int col = 0; col < 1; col++)

cout<<setw(10)<<" Average ";

cout<<setw(10)<<" Grade ";

cout<<student.test1;

cin >> table[1][2];

}
}
}//END DisplayTable()


Output:

Please Enter Student No: 1
Please Enter Test 1: 80
Please Enter Test 2: 85
Please Enter Test 3: 95
The average is:86
The Grade is : B

Please Enter Student No: 2
Please Enter Test 1: 80
Please Enter Test 2: 55
Please Enter Test 3: 64
The average is:66
The Grade is : D

Please Enter Student No: 3
Please Enter Test 1: 55
Please Enter Test 2: 48
Please Enter Test 3: 65
The average is:56
The Grade is : F

Please Enter Student No: 4
Please Enter Test 1: 88
Please Enter Test 2: 66
Please Enter Test 3: 77
The average is:77
The Grade is : C

Please Enter Student No: 5
Please Enter Test 1: 95
Please Enter Test 2: 75
Please Enter Test 3: 40
The average is:70
The Grade is : C

Student No Test1 Test2 Test3 Average Grade 95
See less See more
1 - 2 of 2 Posts
Status
Not open for further replies.
Top