I doesn't know why my program after enter main menu and want to call any other function
will stoppped working,this is the question

Write a program that is able to help a school teacher to input, manipulate and record marks of students for 8 subjects. These subjects are English, Physics, Chemistry, Biology, Mathematics, Moral Additional Mathematics and Bahasa Malaysia.
The program must first of all be able to get input of name, student id and marks of 8 subjects. All the inputs shall be stored into a file. The file can be retrieved for other operations.
Create menu and operations for:
1) Add Student and Marks
2) Search Student details
3) Calculate CGPA and Class of Honours
4) Edit Student marks
5) Delete student from the system
6) Display all students in the File and inclusive of CGPA
7) Display students according to class of Honours

1>LINK : fatal error LNK1104: cannot open file 'C:UsersuserDocumentsVisual Studio 2010ProjectsStudent_mark_graded_systemDebugStudent_mark_graded_system.exe'
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.71
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

student_marks.txt
1
Micheal Wong
100 99  99  88  88  88  88  88

2
David Lee   
88  40  50  90  50  70  10  80

3
Lee Ah Kau
30  40  60  80  30  20  30  60





    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>
    #include<cstdlib>
    #include<iomanip>

    using namespace std;

    void add_data();
    void search_student();
    void cal_cgpa_honour(double cgpa[5000],int classhonour[5000]);
    void edit_marks();
    void del_student();
    void disp_infile(double cgpa[5000],int classhonour[5000]);
    void disp_student_classhonour(double cgpa[5000],int classhonour[5000]);




    int main( void )
    {
        char option,quit;
        string name[5000],id[5000];
        double cgpa[5000];
        int classhonour[5000];
        do{

            system("cls");
            system("color 5B");

            cout<<"nnWelcome to Student mark and Graded System"<<endl;
            cout<<"*****************************************nn";
            Sleep(1000);
            cout<<"Please select option: nn";
            cout<<"t[1] Add Student and Marks n";
            cout<<"t[2] Search Student detailsn";
            cout<<"t[3] Calculate CGPA and Class of Honoursn";
            cout<<"t[4] Edit Student marks n";
            cout<<"t[5] Delete student from the system n";
            cout<<"t[6] Display all students in the File and inclusive of CGPA n";
            cout<<"t[7] Display students according to class of Honours nn";
            cout<<"t[0] Exit nn";

            cout<<"Please select your menu : ";
            cin>>option;

            switch(option)
                {
                case '1':add_data( );
                        break;

                case '2':search_student();
                        break;

                case '3':cal_cgpa_honour(cgpa,classhonour);
                        break;

                case '4':edit_marks();
                        break;

                case '5':del_student();
                        break;

                case '6':disp_infile(cgpa, classhonour);
                        break;

                case '7':disp_student_classhonour(cgpa,classhonour);
                        break;

                case '0':
                    {
                        system("cls");
                        cout<<"Are you sure you want to exit? (Y/N): ";
                        cin>>quit;          
                        if(quit=='y'||quit=='Y')
                        {
                            cout<<"Thank you for using this program!!n";
                            cout<<"The program will be terminatednn";
                            Sleep(3000);

                        }
                        break;
                    }



                }

        }while(quit=='n'||quit=='N');






        return 0;
    }


    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>

    using namespace std;



    void add_data()
    {
        ofstream outfile;
        outfile.open("student_mark.txt",ios::out);
        int stud_num;


        system("cls");

        do{

        cout<<"ttEnter number of student :--->";
        cin>>stud_num;
        cout<<endl;
            if(stud_num>=5000)
            {
                cout<<"Sorry, memory is already full!!!Please re-enter"<<endl;
                Sleep(1500);
            }
        }
        while( stud_num>=5000);

        string name[5000];
        string id[5000];
        int i=0;
        double eng[5000],bio[5000],phy[5000],chem[5000],math[5000],moral[5000],bm[5000],addmath[5000];

        if(outfile.fail())
        {
            cout<<"File could not be open !! Press any Key...";
            cin.ignore();
            cin.get();
            exit(-1);
        }
        else
        {

            while(i<stud_num )
            {
            system("cls");
            cout<<"Please enter the data of "<<i+1<<"st student"<<endl<<endl;

            cout.flush();
            cout<<"Student ID :";     
            cin>>id[i];
            cout<<endl;
            cin.ignore(100,'n');
            cout<<"Student Name :";
            getline(cin,name[i]);
            cout<<endl;


            cout<<"Please enter student's mark"<<endl<<endl;
            cout<<"English:";
            cin>>eng[i];
            cout<<endl;
            cout<<"Physics:";
            cin>>phy[i];
            cout<<endl;       
            cout<<"Chemistry:";
            cin>>chem[i];
            cout<<endl;
            cout<<"Biology:";
            cin>>bio[i];
            cout<<endl;
            cout<<"Mathematics:";
            cin>>math[i];
            cout<<endl;
            cout<<"Moral:";
            cin>>moral[i];
            cout<<endl;
            cout<<"Additional Mathematics:";
            cin>>addmath[i];
            cout<<endl;
            cout<<"Bahasa Malaysia:";
            cin>>bm[i];
            cout<<endl;

            outfile<<id[i]<<endl;
            outfile<<name[i]<<endl;
            outfile<<eng[i]<<"t"<<phy[i]<<"t"<<chem[i]<<"t"<<bio[i]<<"t"<<math[i]<<"t"<<moral[i]<<"t"<<addmath[i]<<"t"<<bm[i++]<<endl<<endl;

            }       
            cout<<"Data Entered Successfullyn";
            Sleep(2000);
        }


        outfile.close();


    }





    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>



    using namespace std;


    void search_student()
    {



        string search_id,name[5000],id[5000];
        int i=0,j;
        char ext;
        double eng[5000],bio[5000],phy[5000],chem[5000],math[5000],moral[5000],bm[5000],addmath[5000];
        bool found = false;


        ifstream infile("student_mark.txt") ; 

        if(infile.fail())
        {
            cout<<"File could not be open !! Press any Key...";
            cin.ignore();
            cin.get();
            exit(-1);
        }
        else
        {


            while(!infile.eof())
            {

                infile>>id[i];
                infile.ignore(100,'n');
                getline(infile,name[i]);
                infile>>eng[i]>>bio[i]>>phy[i]>>chem[i]>>math[i]>>moral[i]>>bm[i]>>addmath[i++];
                infile.ignore(500,'n');
                infile.ignore(500,'n');
            }

            do{

                system("cls");

                cout<<"Please enter the ID of the student whose record you want to search-->";
                cin>>search_id;
                cout<<endl<<endl;
                for(j=0 ; j<i ; j++)
                {
                    if(search_id == id[j])
                    {
                    found = true;
                    cout<<endl;
                    cout<<name[j]<<endl;

                    cout<<"English: "<<eng[j]<<endl;
                    cout<<"Physics: "<<phy[j]<<endl;  
                    cout<<"Chemistry: "<<chem[j]<<endl;
                    cout<<"Biology: "<<bio[j]<<endl;
                    cout<<"Mathematics: "<<math[j]<<endl;
                    cout<<"Moral:"<<moral[j]<<endl;
                    cout<<"Additional Mathematics:"<<addmath[j]<<endl;
                    cout<<"Bahasa Malaysia:"<<bm[j]<<endl;

                    break;
                    }

                    else if(search_id != id[j])
                    {
                        found = false;
                    }


                }
                if(found == false)
                {
                    cout<<"nn Record Not Found ";
                    cin.ignore();
                    cin.get();
                }
                cout<<endl;
                cout<<"Do you want to continue?(Y/N)";
                cin>>ext;


            }while( ext == 'y' || ext == 'Y' );

        }


    }





    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>

    using namespace std;

    void cal_cgpa_honour(double cgpa[5000],int classhonour[5000])
    {

        int i=0,j;
        ifstream infile("student_mark.txt") ; 
        string id[5000],name[5000],cgpa_id,classh[5000];
        int a=0,b=0,c=0,f=0;
        char ext;
        double marks[8][5000];


        if(infile.fail())
        {
            cout<<"File could not be open !! Press any Key...";
            cin.ignore();
            cin.get();
            exit(-1);
        }

        else
        {


            while(!infile.eof())
            {
                infile>>id[i];
                infile.ignore(100,'n');
                getline(infile,name[i]);


                    for(j=0;j<8;j++)
                    {
                        infile>>marks[j][i];
                        if(marks[j][i]>=80 && marks[j][i]<=101)
                            a++;

                        else if(marks[j][i]>=60 && marks[j][i]<=79)
                                b++;

                            else if(marks[j][i]>=50 && marks[j][i]<=59)
                                    c++;

                                else if(marks[j][i]<50)
                                        f++;
                    }
                    cgpa[i] = (a*4.0 + b*3.0 + c*2.0 + f*0.0)/8;

                    if(cgpa[i]>=3.55 && cgpa[i]<=4.0 )   
                    {
                        classhonour[i] = 1;

                    }
                    else if(cgpa[i]>=2.5 && cgpa[i]<=3.49 )      
                        {
                            classhonour[i] = 2;
                        }
                        else if(cgpa[i]>=2.0 && cgpa[i]<=2.49 )                  

                            {
                                classhonour[i] = 3;
                            }
                            else if(cgpa[i]<2.0) 
                                {
                                    classhonour[i] = 0;

                                }


                infile.ignore(500,'n');
                infile.ignore(500,'n');
                i++;
            }


            do{
            cout<<"Please enter the ID of the student whose record you want to show the cgpa and class of honour-->";
            cin>>cgpa_id;
            cout<<endl<<endl;
            for(int k=0 ; k<i ;k++)
            {
                if(cgpa_id == id[k])
                {
                    cout<<"Name : "<<name[k];
                    cout<<"cgpa : "<<cgpa[k];

                    if(classhonour[k] !=0 )
                    {
                        cout<<classhonour[k]<<"th Class Honour";
                    }
                    else if(classhonour[k] ==0)
                        {
                            cout<<"General Degree";
                        }
                    break;
                }

            }

            cout<<"Do you want to continue?(Y/N)";
            cin>>ext;
            }while(ext == 'y' || ext == 'Y');


        }
    }

    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>

    using namespace std;



    void edit_marks()
    {

        string edit_id,name[5000],id[5000],sub_edit,subup[8]={"English","Biology","Physics","Chemistry","Moral","Mathematis","Bahasa Malaysia"};
        string sublow[8]={"english","biology","physics","chemistry","moral","mathematis","bahasa malaysia"};
        double marks[8][5000];
        int j,h,i=0;
        char ext,con_edit;
        bool edit=false;


        ifstream infile("student_mark.txt");



        if(infile .fail())
        {
            cout<<"ERROR-END PROGRAM";
            exit(1);
        }

        else
        {


            while(!infile.eof())
            {


                    infile>>id[i];
                    infile.ignore(100,'n'); 
                    getline(infile,name[i]);

                    if(infile.eof())
                    {
                        for(h=0 ; h<8 ; h++)
                        {
                            infile>>marks[h][i];
                        }

                    infile.ignore(500,'n');
                    infile.ignore(500,'n');

                    }

                    i++;
            }
        }

            infile.close();



        do{
                system("cls");
                cout<<"Please enter the ID of the student whose record you want to edit-->"<<endl<<endl;
                cin>>edit_id;


                for(j=0;j<i;j++)
                {
                    if( id[j] == edit_id)
                    {
                        edit = true;
                        cout.flush();

                        cout<<endl;
                        cout<<name[j];
                        cout<<endl;
                        do{
                                cout<<"Which subject want to edit(Please enter full subject name)?-->";
                                cin>>sub_edit;

                                cout<<"Please enter "<<name[j]<<"'s mark"<<endl<<endl;
                                for(h=0 ; h<8 ; h++)
                                {
                                    if( sub_edit == subup[h]||sub_edit== sublow[h])
                                    {
                                        cout<<subup[h]<<":";
                                        cin>>marks[h][j];
                                        cout<<endl;
                                        break;
                                    }
                                }
                                cout<<"Do you want to continue to edit  other subject?(Y/N)";
                                cin>>con_edit;

                            }while(con_edit =='y' || con_edit == 'Y');

                        break;      
                    }

                    else if(edit_id != id[j])
                    {
                        edit = false;
                    }
                }

                if(edit == false)
                {
                    cout<<"nn Record Not Found ";
                    cin.ignore();
                    cin.get();
                }

            ofstream ofil;
            ofil.open("student_mark.txt",ios::out);
            if(ofil .fail())
            {
                cout<<"File could not be open !! Press any Key...";
                cin.ignore();
                cin.get();
                return;
            }
            else
            {

                for(j=0 ; j<i ; j++)
                {
                    ofil<<id[j]<<endl;
                    ofil<<name[j]<<endl;
                        for(h=0 ; h<8 ; h++)
                        {
                            ofil<<marks[h][j];
                            ofil<<"t";

                        }
                        ofil<<endl<<endl;

                }

            }
            ofil.close();
            cout<<"Do you want to continue?(Y/N)";
            cin>>ext;

        }while(ext == 'y' ||ext == 'Y');



    }




    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>

    using namespace std;


    void del_student()
    {


        string del_id,name[5000],id[5000],sub_edit,subup[8]={"English","Biology","Physics","Chemistry","Moral","Mathematis","Bahasa Malaysia"};
        string sublow[8]={"english","biology","physics","chemistry","moral","mathematis","bahasa malaysia"};
        double marks[8][5000];
        int j,h;
        char ext;
        bool found= false;



            ifstream infile("student_mark.txt");

            if(infile .fail())
            {
                cout<<"File could not be open !! Press any Key...";
                cin.ignore();
                cin.get();
                exit(-1);
            }

            else

            {

            do{
                    int i=0;
                    system("cls");
                    cout<<"Please enter the ID of the student whose record you want to delete-->"<<endl<<endl;
                    cin>>del_id;

                    while(!infile.eof())
                    {

                        infile>>id[i];
                        infile.ignore(100,'n'); 
                        getline(infile,name[i]);

                        for(h=0 ; h<8 ; h++)
                        {
                            infile>>marks[h][i];
                        }

                        infile.ignore(500,'n');
                        infile.ignore(500,'n');
                        i++;
                    }

                        infile.close();

                        ofstream ofil;
                        ofil.open("student_mark.txt",ios::out);
                        for(j=0;j<i;j++)
                        {


                            if( id[j] == del_id )
                            {
                                found = true;
                                cout.flush();

                                id[j]=id[j+1];
                                ofil<<id[j]<<endl;

                                name[j]=name[j+1];
                                ofil<<name[j]<<endl;

                                for(h=0 ; h<8 ; h++)
                                {
                                    marks[h][j]=marks[h][j+1];
                                    ofil<<marks[h][j];
                                    ofil<<"t";
                                }

                                break;
                            }

                            else if(id[j] != del_id)
                                {
                                    found=false;
                                    ofil<<endl;           
                                    ofil<<id[j]<<endl;
                                    ofil<<name[j]<<endl;

                                        for(h=0 ; h<8 ; h++)
                                    {

                                        ofil<<marks[h][j];
                                        ofil<<"t";
                                    }

                                }
                        }



                        for(int k=j+1 ; k<i ; k++)
                        {

                                ofil<<endl;
                                id[k]=id[k+1];
                                ofil<<id[k]<<endl;
                                name[k]=name[k+1];
                                ofil<<name[k]<<endl;
                                for(h=0 ; h<8 ; h++)
                                {
                                    marks[h][k]=marks[h][k+1];
                                    ofil<<marks[h][k];
                                    ofil<<"t";
                                }

                        }
                        cout<<"nntRecord Deleted ..";
                        cin.ignore();
                        cin.get();



                    ofil.close();
                    cout<<"Do you want to continue?(Y/N)";
                    cin>>ext;


                }while(ext == 'y' ||ext == 'Y');


    }

    }


    #include<iostream>
    #include<fstream>
    #include<Windows.h>
    #include<string>

    using namespace std;

    void disp_infile(double cgpa[5000],int classhonour[5000])
    {

        int i=0,j;
        ifstream infile("student_mark.txt") ; 

        string id[5000],name[5000];
        int a=0,b=0,c=0,f=0;

        double marks[8][5000];
        string subup[8]={"English","Biology","Physics","Chemistry","Moral","Mathematis","Bahasa Malaysia"};

        if(infile.fail())
        {
            cout<<"File could not be open !! Press any Key...";
            cin.ignore();
            cin.get();
            exit(-1);
        }

        else
        {

            while(!infile.eof())
            {


                infile>>id[i];
                infile.ignore(100,'n'); 
                getline(infile,name[i]);

                if(!infile.eof())
                {
                    for(int h=0 ; h<8 ; h++)
                    {
                        infile>>marks[h][i];
                    }

                infile.ignore(500,'n');
                infile.ignore(500,'n');

                }
                i++;
            }

                for(j=0 ; j<i ; j++)
                {

                    cout<<id[j]<<endl;
                    cout<<"Name : "<<name[j]<<endl;

                    for(int h=0 ; h<8 ; h++)
                    {

                        cout<<subup[h]<<" : "<<marks[h][j]<<endl;

                    }

                    cout<<"cgpa : "<<cgpa[j]<<endl<<endl<<endl;


                }           

        }   
        infile.close();



}

Edited 4 Years Ago by angelineang

build failed because you didn't write code for function disp_student_classhonour() (or you didn't post it)

Edited 4 Years Ago by Ancient Dragon

Another thing you could do, having in consideration the fact that your problem, as you identified, resides in the main menu part of your program, you could change the approach of the menu. You could use instead of the switch case statements a simply string validation menu:

#include <iostream>
#include <string>
using namespace std;

void add_student(){
    cout<<"Adding sudent.\n";
}

void add_subject(){
    cout<<"Addind subject.\n";
}

int main(){
    cout<<"Main menu.\n"
        <<"1. Add student.\n"
        <<"2. Add subject.\n"
        <<"3. Quit.\n";
    string answer;
    for (;;){
        cout<<"\\\\: ";
        cin>>answer;
        if (answer=="1" or answer=="1."){
            add_student(); //random named function.
        }
        else if (answer=="2" or answer=="2."){
            add_subject();
        }
        else if (answer=="3" or answer=="3."){
            break;
        }
        else cout<<"Invalid command.\n";
    }
    return (0);
}
This article has been dead for over six months. Start a new discussion instead.