Welcome to Tech Support Forum home to more then 136,000 problems solved. Issues have included: Spyware, Malware, Virus Issues, Windows, Microsoft, Linux, Networking, Security, Hardware, and Gaming Getting your problem solved is as easy as:
1. Registering for a free account
2. Asking your question
3. Receiving an answer

Registered members:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* See fewer ads.
* And much more..

 



Want to know how to post a question? click here Having problems with spyware and pop-ups? First Steps
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 08-19-2005, 04:57 AM   #1 (permalink)
Registered User
 
Join Date: Aug 2005
Posts: 18
OS: XP


Another question regarding 2 dimensional array in VC++

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!
melvynlyc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Important Information
Join the #1 Tech Support Forum Today - It's Totally Free!

TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free.

Join TechSupportforum.com Today - Click Here

Old 08-19-2005, 05:03 AM   #2 (permalink)
Registered User
 
Join Date: Aug 2005
Posts: 18
OS: XP


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
melvynlyc is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 12:05 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85