2 Replies - 2108 Views - Last Post: 25 April 2008 - 05:58 AM Rate Topic: -----

#1 karola  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-April 08

Grade of student

Post icon  Posted 25 April 2008 - 03:04 AM

Hi, Guys!!! I need your help. My assignment is to design and implement a mark analyzer information system. This mark analyzer system will read data of a group of students. The data includes students names, and marks of three subjects for each student. This data basically is stored in a text file created by a text editor student.txt. This system should display a simple text-based menu of options and operations to be applied to the data.

The system should allow the user to view all information, generate the statistics by subject and generate the overall statistics. When you run the program, the first menu to be displayed is:

Main Menu
==============================================
1. View all information
2. Statistics By Subject
3. Overall Statistics
0. Exit
==============================================
Please input your choice:

When the user presses 1, the system should display all information as shown below:

CP1 Mathematics English Overall
------------- ------------- ------------- -------------
Name Mark Grade Mark Grade Mark Grade Average Grade
===== ==== ===== ==== ===== ==== ===== ======= =====
John 50 F 60 D 78 C 62.67 D
Ahmad 95 A 59 F 89 B 81.00 B
Siti 48 F 32 F 68 D 49.33 F
...
...
...
Average 71.52 65.59 78.04 69.81

Press any key to go back to the previous menu ...


If the user selects 2 from Main Menu, the following sub menu will be displayed:

Statistics by Subject
===============================================
1. CP1
2. Mathematics
3. English
0. Exit
===============================================
Please input your choice:

Upon choosing item 1 to 3, the following sub menu will be displayed:

Statistics of CP1
===============================================
1. Subject Average
2. % of students below the subject average
3. % of students above the subject average
4. % of students who passed
5. % of students who failed
6. Display list of students based on grade
0. Exit
===============================================
Please input your choice:

Here are examples of two of the above operations:

If user chooses 1, the output will be:

Average for CP1: 75.06

Press any key to go back to the previous menu ...

If user chooses 6, the user will be prompted to input a grade:

Please enter a grade (A, B, C, D, E):

Supposed the user input grade B, all the names of student who obtained grade B for this subject will be displayed.
Students who obtained grade B for CP1:
Alan
Suraya
Mary

Press any key to go back to the previous menu ...

When user selects 3 from the Main Menu, the sub menu for Overall Statistics will be displayed:

Overall Statistics
===============================================
1. Overall Average
2. % of students below overall average
3. % of students above overall average
4. % of students who passed
5. % of students who failed
6. Display list of students based on grade
0. Exit
===============================================
Please input your choice:

The operations for the Overall Statistic menu are the same as the operations of the Statistics By Subjects.


Here is beginning of source code, but i can manage function grade() and average().What's wrong with it?I've stuck here.Where should i call to this functions in main. I put these functions as comments, coz wid them it doesn't work.Help please, am really new in programming. :blink:


#include <iostream>
#include <cstdlib>
#include <fstream>


using namespace std;


const string filename="student.txt";


void openFile(ifstream& input)
{
input.clear();
input.open(filename.c_str());

if (!input)
cout << "error open file " << endl;


}

void closeFile(ifstream& input)
{
input.close();
}





int MainMenu (void)
{
int choice=0;
bool gotInput = false;

cout << "=====================================" << endl;
cout << " Main Menu" << endl;
cout << "=====================================" << endl;
cout << "1. View all information" << endl;
cout << "2. Statistics By Subject " << endl;
cout << "3. Overall Statistics" << endl;
cout << "0. Exit" << endl;
cout << "=====================================" << endl;

do {
cout << "Please input your choice:";
if(!(cin >> choice))
{
cin.clear();
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 0 || choice <= 3) gotInput = true;
} while(!gotInput);

return choice;
}



void PressAnyKeyToContinue(void)
{
system("pause"); //pauses the system until you press a key
system("cls");
//clears the screen
}

void DisplayHeader(void)
{
cout << "Name\tCP1\tMath\tEnglish" <<endl;
cout << "---------------------------------------------" <<endl;
}



void ViewAllInformation()
{
int m1,m2,m3;
string name;
ifstream input;
openFile(input); // must open the file before use
DisplayHeader();

while (!input.eof()) // stop if End Of File is reached ?
{
input >> name >> m1 >> m2 >> m3; // reads a line from the file
if (input.fail()) // checks if the last line is read
{
exit(1);
} else {
cout << name << "\t"<< m1 << "\t"<< m2 << "\t"
<< m3<< endl;
}
}

closeFile(input); // must close the file
cout << endl << endl;
// create 2 emty lines after display
}


void TestOption(void)
{
cout << "=====================================" << endl;
cout << "1. Subject average " << endl;
cout << "2. % of students below overall average " << endl;
cout << "3. % of students above overall average" << endl;
cout << "4. % of students who passed " << endl;
cout << "5. % of students who failed" << endl;
cout << "6. Display list of students based on grade " << endl;
cout << "0. Exit" << endl;
cout << "=====================================" << endl;

}

void SubjectMenu(string subject)
{
cout << "=====================================" << endl;
cout << " Statistics of " << subject<< endl;
}

int StatisticsBySubject (void)
{
int choice=0;
bool gotInput = false;
bool flag = false;
cout << "=====================================" << endl;
cout << " Statistics by Subjects " << endl;
cout << "=====================================" << endl;
cout << "1. CP1" << endl;
cout << "2. Mathematics " << endl;
cout << "3. English " << endl;
cout << "4. Overall " << endl;
cout << "0. Exit" << endl;
cout << "=====================================" << endl;

do {
cout << "Please input your choice:";
if(!(cin >> choice))
{
cin.clear();
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 0 || choice <= 4) gotInput = true;
} while(!gotInput);


do{

system("cls");
if (choice == 1) {SubjectMenu("CP1"); TestOption();}
else if (choice == 2) { SubjectMenu("Mathematics"); TestOption(); }
else if (choice == 3) {SubjectMenu("English"); TestOption();}
else if (choice == 4) {SubjectMenu("Overall"); TestOption();}
else if (choice == 0) flag = true;
else cout << "use only number shown in the menu" << endl<<endl;
if (!flag) PressAnyKeyToContinue();
}while (!flag);


}




int OverallStatistics (void)
{
int choice2=0;
bool gotInput = false;

cout << "=====================================" << endl;
cout << " Overall Statistics" << endl;
cout << "=====================================" << endl;
cout << "1. Overall average " << endl;
cout << "2. % of students below overall average " << endl;
cout << "3. % of students above overall average" << endl;
cout << "4. % of students who passed " << endl;
cout << "5. % of students who failed" << endl;
cout << "6. Display list of students based on grade " << endl;
cout << "0. Exit" << endl;
cout << "=====================================" << endl;

do {
cout << "Please input your choice:";
if(!(cin >> choice2))
{
cin.clear();
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice2 >= 0 || choice2 <= 6) gotInput = true;
} while(!gotInput);

return choice2;
}

/* char grade(double mark)
{ int mark;
char result;
if (mark <= 59)
result = 'F';
if (mark <= 69 && mark >= 60)
result = 'D';
else if (mark <= 79 && mark >= 70)
result = 'C';
else if (mark <= 89 && mark >= 80)
result = 'B';
else if (mark >= 90 && mark <= 100)
result = 'A';
else result = 'x';
return result;
}

double average(int num1, int num2, int num3)

{
double result;
result = (num1+num2+num3)/static cast(3);
return result;
}
*/
int main()
{
int choice;
bool flag = false;

do{
choice = MainMenu();
system("cls");
if (choice == 1) ViewAllInformation();
else if (choice == 2) StatisticsBySubject();
else if (choice == 3) OverallStatistics();
else if (choice == 0) flag = true;
else cout << "use only number shown in the menu" << endl<<endl;
if (!flag) PressAnyKeyToContinue();
}while (!flag);


return 0;

}

Is This A Good Question/Topic? 0
  • +

Replies To: Grade of student

#2 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

Re: Grade of student

Posted 25 April 2008 - 05:06 AM

Can you put into code..... Then can you tell me what is the error?

Thax
Was This Post Helpful? 0
  • +
  • -

#3 karola  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 25-April 08

Re: Grade of student

Posted 25 April 2008 - 05:58 AM

View Postfsloke, on 25 Apr, 2008 - 05:06 AM, said:

Can you put into code..... Then can you tell me what is the error?

Thax



Actually, this program is running,but only on half way,coz i did not complete it enough :(
And there is no error yet.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1