Hi everyone, i need to design a simple grading system and the requirements are as below:

Mark Grade
----------- --------
90 – 100 A
80 – 89 B
70 – 79 C
60 – 69 D
0 – 59 F

input.txt -sample input, i have attached the file too

Felix Fiji 41 40 80 80
Philip Panama 50 50 70 70
Abel Austria 60 95 49 79
Cindy Canada 70 40 91 63

This is the starting screen

Number of students = 4 - based on the input file

All information is loaded from file to program.

Press any key to continue . . .

This is the main menu:

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

For the no.1 i have done it, the output is

Name Nation English Math CPP SE Average
-------- -------- ------ ------ ------ ------ ---------
Felix Fiji 41 F 40 F 80 B 80 B 60.25 D
Philip Panama 50 F 50 F 70 C 70 C 60.00 D
Abel Austria 60 D 95 A 49 F 79 C 70.75 C
Cindy Canada 70 C 40 F 91 A 63 D 66.00 D

Press any key to continue . . .

I lost touch in c++, so i am having problem for the q no.2.....
The expected screen for q no.2 is

Statistics of English
==============================================
1. Subject Average
2. % of students below the subject average
3. % of students above the subject average
4. Display list of students based on grade
0. Exit

and the expected answer for no.1 is

Average for English is --> 55.25

Press any key to continue . . .

for no.2 is

Students below the average of 55.25 for English are:

Felix 41
Philip 50

Press any key to continue . . .

lastly for no.3 is

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

Students who obtained grade ‘C’ for English:

Cindy 70

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

I need help in solving the 1st problem, because the balance 3 problems could be solved easily if the no.1 could be solved.

here is my code, hope you guys could help me out:

#include <iostream>
#include <fstream>

using namespace std;

const string filename = "input.txt"; // Fixes the input file name

class Person
{
public:
	Person::Person();
	Person::Person(string, string, int, int, int, int);
    void Person::setName(string);
    void Person::setNation(string);
    void Person::setEnglish(int);
    void Person::setMath(int);
    void Person::setCpp(int);
    void Person::setSe(int);
    string Person::getName();
    string Person::getNation();
    int Person::getEnglish();
    int Person::getMath();
    int Person::getCpp();
    int Person::getSe();

private:	

	string name;
	string nation;
	int english;
	int math;
	int cpp;
	int se;
};

void viewAllInfo(Person year1[], int size)
{
    system("cls");
    string name, nation, dump;
    int m1, m2, m3, m4, i = 0; 
    char m1_gred;
    char m2_gred;
    char m3_gred;
    char m4_gred;
    
    cout << "Name" << "\t " << "Nation" << "\t  " << "English" << " "  
             << "Maths" << "\t  "  << "Cpp" << "\t "  << "Se" << "  "  << "Average" <<endl;
        cout << "----" << "\t " << "------" << "\t  " << "-------" << " "  
             << "-----" << "\t  "  << "---" << "\t "  << "--" << "  "  << "-------" <<endl;
    for (int i = 0; i <= size-1; i++) 
    {
        name = year1[i].getName();
        nation = year1[i].getNation();
        m1 = year1[i].getEnglish();
        m2 = year1[i].getMath();
        m3 = year1[i].getCpp();
        m4 = year1[i].getSe();
        
        if ( m1 > 89){
             m1_gred = 'A';
             }
        else if ( m1 < 90 && m1 > 79){
             m1_gred = 'B';
             }
        else if ( m1 < 80 && m1 > 69){
             m1_gred = 'C';
             }
        else if ( m1 < 70 && m1 > 59){
             m1_gred = 'D';
             } 
        else
            m1_gred = 'F'; 
            
            
        if ( m2 > 89){
             m2_gred = 'A';
             }
        else if ( m2 < 90 && m2 > 79){
             m2_gred = 'B';
             }
        else if ( m2 < 80 && m2 > 69){
             m2_gred = 'C';
             }
        else if ( m2 < 70 && m2 > 59){
             m2_gred = 'D';
             } 
        else
            m2_gred = 'F'; 
        
        
        if ( m3 > 89){
             m3_gred = 'A';
             }
        else if ( m3 < 90 && m3 > 79){
             m3_gred = 'B';
             }
        else if ( m3 < 80 && m3 > 69){
             m3_gred = 'C';
             }
        else if ( m3 < 70 && m3 > 59){
             m3_gred = 'D';
             } 
        else
            m3_gred = 'F';
        
        
        if ( m4 > 89){
             m4_gred = 'A';
             }
        else if ( m4 < 90 && m4 > 79){
             m4_gred = 'B';
             }
        else if ( m4 < 80 && m4 > 69){
             m4_gred = 'C';
             }
        else if ( m4 < 70 && m4 > 59){
             m4_gred = 'D';
             } 
        else
            m4_gred = 'F'; 
             
        double average = ( m1 + m2 + m3 + m4 ) / 4;    
        
        if ( average > 89){
             avg_gred = 'A';
             }
        else if ( average < 90 && average > 79){
             avg_gred = 'B';
             }
        else if ( average < 80 && average > 69){
             avg_gred = 'C';
             }
        else if ( average < 70 && average > 59){
             avg_gred = 'D';
             } 
        else
            avg_gred = 'F';
           
        cout << name << "\t " << nation << "\t  " << m1 << " "<< m1_gred << "\t "  
             << m2 << "   "<< m2_gred << "\t  "  << m3 << " " << m3_gred << "  " << m4 << " "  << m4_gred<< "  " << average << "  " << avg_gred << endl;
    }

    cout <<"\nPlease enter any key to continue:";
    cin >> dump;
    return;
}


void loadAllInfo(Person year1[], int & classSize)
{
    system("cls");

    ifstream read_file;
    read_file.open(filename.c_str());     
    if ( read_file.fail() ) {
        cout << "Sorry, error in opening file!\n\n";
        system("pause");
        exit(1);
        }
   
    string name, nation;
    int m1, m2, m3, m4, i = 0; 

    while( !read_file.eof() )
    {
        read_file >> name >> nation >> m1 >> m2 >> m3 >> m4;
        year1[i].setName(name);
        year1[i].setNation(nation);
        year1[i].setEnglish(m1);
        year1[i].setMath(m2);
        year1[i].setCpp(m3);
        year1[i].setSe(m4);

        if ( !read_file.fail() )   // to avoid reading the last line twice
        {
            i++;
        }

    }
    classSize = i;
    read_file.close();             
    cout << "\nNumber of students = " << classSize << endl;
    cout << "All information is loaded from file to program." << endl << endl;
    system("pause");
    return;
}


Person::Person()
{
	name = "";
	nation = "";
	english = 0;
	math = 0;	
	cpp = 0;	
	se = 0;	
}

Person::Person(string a, string b, int c, int d, int e, int f)
{
	name = a;
	nation = b;
	english = c;
	math = d;	
	cpp = e;	
	se = f;	
}

void Person::setName(string a)
{
     name = a;
}

void Person::setNation(string a)
{
     nation = a;     
}

void Person::setEnglish(int a)
{
     english = a;     
}

void Person::setMath(int a)
{
     math = a;     
}

void Person::setCpp(int a)
{
     cpp = a;     
}

void Person::setSe(int a)
{
     se = a;     
}

string Person::getName()
{
     return name;
}

string Person::getNation()
{
     return nation;
}

int Person::getEnglish()
{
     return english;
}

int Person::getMath()
{
     return math;
}

int Person::getCpp()
{
     return cpp;
}

int Person::getSe()
{
     return se;
}


int main()
{
    Person year1[20];
    int classSize = 0;
    loadAllInfo(year1, classSize);
    
    int ch;
    while(ch != 0)
   {
    system("cls");
    cout << "===========================" << endl;
    cout << "         Main Menu" << endl;
    cout << "===========================" << endl;
    cout << "  1. View all information" << endl;
    cout << "  2. Statistics by Subject" << endl;
    cout << "  3. Edit Data" << endl;
    cout << "  0. Exit" << endl;
    cout << "===========================" << endl;
    cout << "Please input your choice: ";
    cin >> ch;
    
    if ( ch == 0){
         exit(1);
         }
    if ( ch == 1){
        viewAllInfo(year1, classSize);
       }
    if ( ch == 2){

       }
    if ( ch == 3){
         
       }
    else
        cout << "Please enter a valid choice"<< endl;
        }
    system("pause");
	return 0;	
}

Thanks in advance, i have attach the input.txt and the .cpp file for your convenient .:icon_wink:

Recommended Answers

All 3 Replies

I'm sorry, I don't understand exactly what your problem is. Could you describe exactly which part is being problemmatic? There's so many bits of code, I'm not sure. Thanks! :D

I am facing difficulties in solving the Statistics by Subject part.... i need to read the data from an input file called 'input.txt' and then get the
1. Subject Average
2. % of students below the subject average
3. % of students above the subject average
4. Display list of students based on grade
for each subjects: eng, math, cpp and se. The expected output is as below

Average for English is --> 55.25

Press any key to continue . . .

Students below the average of 55.25 for English are:

Felix 41
Philip 50

Press any key to continue . . .

Please enter a grade (A, B, C, D, E):
C
Students who obtained grade ‘C’ for English:

Cindy 70

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

I hope this helps and it much more clearer... thanks

in your void viewAllInfo(Person year1[], int size) you are getting a redefintion error delete your decleration of i from this line. int m1, m2, m3, m4, i = 0; to get this int m1, m2, m3, m4; also in my compiler i hade to include the string header file #include<string> to make the cout statements dealing with strings to output

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.