#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2015
    Posts
    2
    Rep Power
    0

    What happened at my view report?


    Code:
    #include<iostream>
    #include<fstream>
    #include<string>
    #include<math.h> //* pow
    using namespace std;
    
    void studentrecord(); //To Add New Records
    void viewreport(); //View Number Of Student in Different Category of status in GPA
    void Help(); //Description of the System
    void Exit(); //Exit the System
    string calculateGrade (double marks); //For Calculating the Grade (Eg. A, A-, B+... etc)
    double calculatePoint(string Grade); //For Calculating the Point (Eg. A = 4.00, B+ =3.50, ... etc)
    string GPAStatus(double value); // For showing the Number of students' GPA Status
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg);
    double CalculateWithinVariance(double allSubject, double avg);
    double CalculateStandardDeviation(double variance);
    int NumberOfDismissal(); // For calculating the total of student who had Dismissal as Status 
    int NumberOfProbation(); // For calculating the total of student who had Probation as Status
    int NumberOfPass(); // For calculating the total of students who had Pass as Status
    int NumberOfGoodStanding(); // For Calculating the total of students who had Good Standing as Status
    int NumberOfDeanList(); // For Calculating the total of students who had Dean's List as Status
    int main()
    {
        char choice; //Choice of Menu
        char retu; //Choice of whether to return to Main menu or not.
        do
        {
        cout<<"Welcome to GPA System"<<endl;
        cout<<"Please Proceed By Choose Option Below"<<endl;
        cout<<"A. Add Students Records"<<endl;
        cout<<"B. View Reports"<<endl;
        cout<<"C. Help"<<endl;
        cout<<"D. Exit"<<endl;
        cin>>choice;
        choice = toupper(choice);
        //Call Function Here
        
        
        switch(choice)
        {
        //system ("cls");
          case 'A': //Add New Record
                studentrecord();
               break;
        
          case 'B' : //View Status Report
                viewreport();
               break;
          case 'C' : //Help
               //For Help Section
               Help();
                break;
          case 'D' : //Exit
               Exit();
               break;
          default : 
                  cout<<"Please Enter the Correct Answer"<<endl;
                  break;
        }
            do{
                cout<<endl<<"Return to Main Menu (Y/N)?"<<endl; //Y to Return. N to Exit.
                cin>>retu;
                retu = toupper(retu);//to make all small case input to Upper Case input
                if (retu == 'N')
                {
                   Exit();
                 }
            }while(retu != 'Y');  
             
        system ("cls");
        
        }while(retu == 'Y');
            
        system("pause");
    }
    //---------------------------------------------------------------------------------------------------------------------
    //System's Features
    void studentrecord ()
    {
         int stuID;
        string stuName,stuGender,GPA,status;
        double subPro,subPhy,subChe,subCal,subEng,avg=0,standDevia,totalSub=0,totalpoint=0,totalcredit=0,GPApoint; // for Subjects
        string ProGrade, PhyGrade, CheGrade, CalGrade, EngGrade; // Grade
        double ProPoints, PhyPoints, ChePoints, CalPoints, EngPoints; // Marks
        double variance = 0, standarddeviation = 0; //Variance , Standard Deviation
        int ProCreHrs, PhyCreHrs, CheCreHrs, CalCreHrs, EngCreHrs; //Credit Hours
        
         ofstream myfile;
         myfile.open("StudentInformation.txt",ofstream::out|ofstream::app);
        
        //Enter Required Information.
        cout<<"Student's ID : ";
        cin>>stuID;
        cout<<"Student's Name :";
        cin>>stuName;
        cout<<"Student's Gender : ";
        cin>>stuGender;
        cout<<"Each Subject Marks :"<<endl;
        cout<<"Programming : ";
        cin>>subPro;
        cout<<"Programming Credit Hours : ";
        cin>>ProCreHrs;
        ProGrade = calculateGrade(subPro);
        ProPoints = calculatePoint(ProGrade);
        cout<<"Physis : ";
        cin>>subPhy;
        cout<<"Physis Credit Hours : ";
        cin>>PhyCreHrs;
        PhyGrade =calculateGrade (subPhy);
        PhyPoints =calculatePoint(PhyGrade);
        cout<<"Chemistry : ";
        cin>>subChe;
        cout<<"Chemistry Credit Hours : ";
        cin>>CheCreHrs;
        CheGrade =calculateGrade (subChe);
        ChePoints =calculatePoint(CheGrade);
        cout<<"Calculus : ";
        cin>>subCal;
        cout<<"Calculus Credit Hours : ";
        cin>>CalCreHrs;
        CalGrade =calculateGrade (subCal);
        CalPoints =calculatePoint(CalGrade);
        cout<<"English : ";
        cin>>subEng;
        cout<<"English Credit Hours : ";
        cin>>EngCreHrs;
        EngGrade =calculateGrade (subEng);
        EngPoints =calculatePoint(EngGrade);
        
        //Calculation Start.
        totalSub=subPhy+subChe+subCal+subEng+subPro;
        avg=totalSub/5;
        totalpoint=(PhyPoints*PhyCreHrs)+(ProPoints*ProCreHrs)+(ChePoints*CheCreHrs)+(CalPoints*CalCreHrs)+(EngPoints*EngCreHrs);
        totalcredit=(PhyCreHrs + ProCreHrs + CheCreHrs + CalCreHrs + EngCreHrs);
        GPApoint=totalpoint/totalcredit;
        variance = CalculateVariance(subPro, subPhy, subChe, subCal, subEng, avg);
        standarddeviation = CalculateStandardDeviation(variance);
        
        //For Adding New Students Records Section : After Calculation.
        //Display Output.
        cout<<endl<<"Student Information :-- "<<endl;
        cout<<"Student's ID     : "<<stuID<<endl;
        cout<<"Student's Name   : "<<stuName<<endl;
        cout<<"Student's Gender : "<<stuGender<<endl;
        cout<<"Each Subject Details :-- "<<endl;
        cout<<"Programming ( "<<ProCreHrs<<" Credit Hours ) : "<<ProGrade<<"\t("<<ProPoints<<")"<<"\t("<<subPro<<")"<<endl;
        cout<<"Chemistry   ( "<<CheCreHrs<<" Credit Hours ) : "<<CheGrade<<"\t("<<ChePoints<<")"<<"\t("<<subChe<<")"<<endl;
        cout<<"Physics     ( "<<PhyCreHrs<<" Credit Hours ) : "<<PhyGrade<<"\t("<<PhyPoints<<")"<<"\t("<<subPhy<<")"<<endl;
        cout<<"Calculus    ( "<<CalCreHrs<<" Credit Hours ) : "<<CalGrade<<"\t("<<CalPoints<<")"<<"\t("<<subCal<<")"<<endl;
        cout<<"Englsh      ( "<<EngCreHrs<<" Credit Hours ) : "<<EngGrade<<"\t("<<EngPoints<<")"<<"\t("<<subEng<<")"<<endl;
        cout<<"Total Points       : "<<totalpoint<<endl;
        cout<<"Average Marks      : "<<avg<<endl;
        cout<<"Variance           : "<<variance<<endl;
        cout<<"Standard deviation : "<<standarddeviation<<endl;
        cout<<"GPA                : "<<GPApoint<<endl;
        cout<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        
        //Input / Save them into txt files.
        myfile<<"Student's ID     : "<<stuID<<endl;
        myfile<<"Student's Name   : "<<stuName<<endl;
        myfile<<"Student's Gender : "<<stuGender<<endl;
        myfile<<"Each Subject Details :-- "<<endl;
        myfile<<"Programming ( "<<ProCreHrs<<" Credit Hours ) : "<<ProGrade<<"\t("<<ProPoints<<")"<<"\t("<<subPro<<")"<<endl;
        myfile<<"Chemistry   ( "<<CheCreHrs<<" Credit Hours ) : "<<CheGrade<<"\t("<<ChePoints<<")"<<"\t("<<subChe<<")"<<endl;
        myfile<<"Physics     ( "<<PhyCreHrs<<" Credit Hours ) : "<<PhyGrade<<"\t("<<PhyPoints<<")"<<"\t("<<subPhy<<")"<<endl;
        myfile<<"Calculus    ( "<<CalCreHrs<<" Credit Hours ) : "<<CalGrade<<"\t("<<CalPoints<<")"<<"\t("<<subCal<<")"<<endl;
        myfile<<"Englsh      ( "<<EngCreHrs<<" Credit Hours ) : "<<EngGrade<<"\t("<<EngPoints<<")"<<"\t("<<subEng<<")"<<endl;
        myfile<<"Total Points       : "<<totalpoint<<endl;
        myfile<<"Average Marks      : "<<avg<<endl;
        myfile<<"Variance           : "<<variance<<endl;
        myfile<<"Standard deviation : "<<standarddeviation<<endl;
        myfile<<"GPA                : "<<GPApoint<<endl;
        myfile<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        myfile<<endl;
    
     }  
    void viewreport()
    {    
          cout<<"Dean's List : "<<NumberOfDeanList()<<endl;
          cout<<"Good Standing List : "<<NumberOfGoodStanding()<<endl;
          cout<<"Pass List : "<<NumberOfPass()<<endl;
          cout<<"Probation List : "<<NumberOfProbation()<<endl;
          cout<<"Dismissal Status List : "<<NumberOfDismissal()<<endl;
    }
    void Help()
    {
          cout<<"Description : "<<endl;
          cout<<"This System is to help user to calculate GPA as well as allowing user to view the overall Students status of GPA"<<endl;
          cout<<"Category \t Marks Range \t Point"<<endl;
          cout<<" A  \t\t 85 - 100  \t 4.00"<<endl;
          cout<<" A- \t\t 80 - 84.9 \t 3.75"<<endl;
          cout<<" B+ \t\t 75 - 79.9 \t 3.50"<<endl;
          cout<<" B  \t\t 65 - 74.9 \t 3.00"<<endl;
          cout<<" C+ \t\t 55 - 64.9 \t 2.50"<<endl;
          cout<<" C  \t\t 50 - 54.9 \t 2.00"<<endl;
          cout<<" D+ \t\t 45 - 49.9 \t 1.50"<<endl;
          cout<<" D  \t\t 40 - 44.9 \t 1.00"<<endl;
          cout<<" F  \t\t < 40 \t 0"<<endl;
          //GPA Status
          cout<<"GPA \t\t Status"<<endl;
          cout<<"< 1.0 \t\t Dismissal"<<endl;
          cout<<"< 2.0 \t\t Probation"<<endl;
          cout<<"< 3.0 \t\t Pass"<<endl;
          cout<<"< 3.5 \t\t GOod Standing"<<endl;
          cout<<"< 3.5 and Above  Dean's List"<<endl;
    }
    void Exit ()
    {
         cout<<"Exit"<<endl;
         exit(0);
    }
    //Features End
    //--------------------------------------------------------------------------------------------------------------------
    //Calculation of Grade + Point + Variance + Standard Deviation
    string calculateGrade(double marks)
    {
           if (marks >=85 && marks<=100)
              return "A";
           else if (marks >= 80 && marks <= 84.9)
                return "A-";
           else if (marks >= 75 && marks <= 79.9)
                return "B+";
           else if (marks >= 65 && marks <= 74.9)
                return "B";
           else if (marks >= 55 && marks <= 64.9)
                return "C+";
           else if (marks >= 50 && marks <=54.9 )
                return "C";
           else if (marks >= 45 && marks <= 49.9)
                return "D+";
           else if (marks >= 40 && marks <= 44.9)
                return "D";
           else if (marks <40)
                return "F";         
    }
    double calculatePoint(string Grade)
    {
           if (Grade =="A" )
              return 4;
           else if (Grade =="A-")
              return 3.75;
           else if (Grade == "B+")
              return 3.5;
           else if (Grade == "B")
              return 3;
           else if (Grade =="C+")
              return 2.5;
           else if (Grade =="C")
              return 2;
           else if (Grade =="D+")
              return 1.5;
           else if (Grade =="D")
              return 1.0;
           else if (Grade =="F")
              return 0;
    }
    string GPAStatus(double value)
    {
             if(value<1)
             return "Dismissal";
             else if(value<2)
             return "Probation";
             else if (value<3)
             return "Pass";
             else if (value<3.5)
             return "Good Standing";
             else if (value>=3.5)
             return "Dean's List";
    }  
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg)
    {
       //Formuala : (n = Number of Subject)
       //Mean = avg = (total 5 subject) / n==5;
       //Each subject - Mean = ans
       //ans = ans^2
       //total += ans ( total = total + ans);
       //variance = total / (n-1)
       double total = 0;
       double variance = 0;
       total += CalculateWithinVariance(subPro, avg); //total = total + CalculateWithinVariance(subPro, avg)
       total += CalculateWithinVariance(subPhy, avg);
       total += CalculateWithinVariance(subChe, avg);
       total += CalculateWithinVariance(subCal, avg);
       total += CalculateWithinVariance(subEng, avg);
       variance = total / (5-1); //5 Subject - 1 = (n-1) = (5-1);
       //cout<<variance<<endl;
       return variance;
    }
    double CalculateWithinVariance(double allSubject, double avg)
    {
           //In this case, assume that avg == mean;
           allSubject -= avg; // allSubject = allSubject - avg(mean)
           allSubject = pow(allSubject, 2); //allSubject ^ 2 .
           return allSubject;
    }
    double CalculateStandardDeviation(double variance)
    {
           //Square root of Variance.
           return sqrt(variance);
    }
    //End of Calculation
    //---------------------------------
    //Below is calculating Number of Student Status from GPA (eg. Pass, Dismissal, ..etc)   
    int NumberOfDismissal()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dismissal") //Find Status : Dismissal
                   {
                            count++; //Find Number of student who is Dismissal.
                   }
             }
             myfile.close();
             
             return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfProbation()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Probation")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfPass()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Pass")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfGoodStanding()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Good Standing")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfDeanList()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dean's List")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }

    sry i wan to ask..wat happen at my view report?it does not view the rate

    Comments on this post

    • Will-O-The-Wisp agrees : Context for future readers: this post once had code without tags.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2226
    Your code is unreadable because you have not used code tags:

    [code] copy and paste your formatted code listing here [/code]

    Here is your code with code tags (original format retrieved via Reply With Quote):
    Code:
    #include<iostream>
    #include<fstream>
    #include<string>
    #include<math.h> //* pow
    using namespace std;
    
    void studentrecord(); //To Add New Records
    void viewreport(); //View Number Of Student in Different Category of status in GPA
    void Help(); //Description of the System
    void Exit(); //Exit the System
    string calculateGrade (double marks); //For Calculating the Grade (Eg. A, A-, B+... etc)
    double calculatePoint(string Grade); //For Calculating the Point (Eg. A = 4.00, B+ =3.50, ... etc)
    string GPAStatus(double value); // For showing the Number of students' GPA Status
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg);
    double CalculateWithinVariance(double allSubject, double avg);
    double CalculateStandardDeviation(double variance);
    int NumberOfDismissal(); // For calculating the total of student who had Dismissal as Status 
    int NumberOfProbation(); // For calculating the total of student who had Probation as Status
    int NumberOfPass(); // For calculating the total of students who had Pass as Status
    int NumberOfGoodStanding(); // For Calculating the total of students who had Good Standing as Status
    int NumberOfDeanList(); // For Calculating the total of students who had Dean's List as Status
    int main()
    {
        char choice; //Choice of Menu
        char retu; //Choice of whether to return to Main menu or not.
        do
        {
        cout<<"Welcome to GPA System"<<endl;
        cout<<"Please Proceed By Choose Option Below"<<endl;
        cout<<"A. Add Students Records"<<endl;
        cout<<"B. View Reports"<<endl;
        cout<<"C. Help"<<endl;
        cout<<"D. Exit"<<endl;
        cin>>choice;
        choice = toupper(choice);
        //Call Function Here
        
        
        switch(choice)
        {
        //system ("cls");
          case 'A': //Add New Record
                studentrecord();
               break;
        
          case 'B' : //View Status Report
                viewreport();
               break;
          case 'C' : //Help
               //For Help Section
               Help();
                break;
          case 'D' : //Exit
               Exit();
               break;
          default : 
                  cout<<"Please Enter the Correct Answer"<<endl;
                  break;
        }
            do{
                cout<<endl<<"Return to Main Menu (Y/N)?"<<endl; //Y to Return. N to Exit.
                cin>>retu;
                retu = toupper(retu);//to make all small case input to Upper Case input
                if (retu == 'N')
                {
                   Exit();
                 }
            }while(retu != 'Y');  
             
        system ("cls");
        
        }while(retu == 'Y');
            
        system("pause");
    }
    //---------------------------------------------------------------------------------------------------------------------
    //System's Features
    void studentrecord ()
    {
         int stuID;
        string stuName,stuGender,GPA,status;
        double subPro,subPhy,subChe,subCal,subEng,avg=0,standDevia,totalSub=0,totalpoint=0,totalcredit=0,GPApoint; // for Subjects
        string ProGrade, PhyGrade, CheGrade, CalGrade, EngGrade; // Grade
        double ProPoints, PhyPoints, ChePoints, CalPoints, EngPoints; // Marks
        double variance = 0, standarddeviation = 0; //Variance , Standard Deviation
        int ProCreHrs, PhyCreHrs, CheCreHrs, CalCreHrs, EngCreHrs; //Credit Hours
        
         ofstream myfile;
         myfile.open("StudentInformation.txt",ofstream::out|ofstream::app);
        
        //Enter Required Information.
        cout<<"Student's ID : ";
        cin>>stuID;
        cout<<"Student's Name :";
        cin>>stuName;
        cout<<"Student's Gender : ";
        cin>>stuGender;
        cout<<"Each Subject Marks :"<<endl;
        cout<<"Programming : ";
        cin>>subPro;
        cout<<"Programming Credit Hours : ";
        cin>>ProCreHrs;
        ProGrade = calculateGrade(subPro);
        ProPoints = calculatePoint(ProGrade);
        cout<<"Physis : ";
        cin>>subPhy;
        cout<<"Physis Credit Hours : ";
        cin>>PhyCreHrs;
        PhyGrade =calculateGrade (subPhy);
        PhyPoints =calculatePoint(PhyGrade);
        cout<<"Chemistry : ";
        cin>>subChe;
        cout<<"Chemistry Credit Hours : ";
        cin>>CheCreHrs;
        CheGrade =calculateGrade (subChe);
        ChePoints =calculatePoint(CheGrade);
        cout<<"Calculus : ";
        cin>>subCal;
        cout<<"Calculus Credit Hours : ";
        cin>>CalCreHrs;
        CalGrade =calculateGrade (subCal);
        CalPoints =calculatePoint(CalGrade);
        cout<<"English : ";
        cin>>subEng;
        cout<<"English Credit Hours : ";
        cin>>EngCreHrs;
        EngGrade =calculateGrade (subEng);
        EngPoints =calculatePoint(EngGrade);
        
        //Calculation Start.
        totalSub=subPhy+subChe+subCal+subEng+subPro;
        avg=totalSub/5;
        totalpoint=(PhyPoints*PhyCreHrs)+(ProPoints*ProCreHrs)+(ChePoints*CheCreHrs)+(CalPoints*CalCreHrs)+(EngPoints*EngCreHrs);
        totalcredit=(PhyCreHrs + ProCreHrs + CheCreHrs + CalCreHrs + EngCreHrs);
        GPApoint=totalpoint/totalcredit;
        variance = CalculateVariance(subPro, subPhy, subChe, subCal, subEng, avg);
        standarddeviation = CalculateStandardDeviation(variance);
        
        //For Adding New Students Records Section : After Calculation.
        //Display Output.
        cout<<endl<<"Student Information :-- "<<endl;
        cout<<"Student's ID     : "<<stuID<<endl;
        cout<<"Student's Name   : "<<stuName<<endl;
        cout<<"Student's Gender : "<<stuGender<<endl;
        cout<<"Each Subject Details :-- "<<endl;
        cout<<"Programming ( "<<ProCreHrs<<" Credit Hours ) : "<<ProGrade<<"\t("<<ProPoints<<")"<<"\t("<<subPro<<")"<<endl;
        cout<<"Chemistry   ( "<<CheCreHrs<<" Credit Hours ) : "<<CheGrade<<"\t("<<ChePoints<<")"<<"\t("<<subChe<<")"<<endl;
        cout<<"Physics     ( "<<PhyCreHrs<<" Credit Hours ) : "<<PhyGrade<<"\t("<<PhyPoints<<")"<<"\t("<<subPhy<<")"<<endl;
        cout<<"Calculus    ( "<<CalCreHrs<<" Credit Hours ) : "<<CalGrade<<"\t("<<CalPoints<<")"<<"\t("<<subCal<<")"<<endl;
        cout<<"Englsh      ( "<<EngCreHrs<<" Credit Hours ) : "<<EngGrade<<"\t("<<EngPoints<<")"<<"\t("<<subEng<<")"<<endl;
        cout<<"Total Points       : "<<totalpoint<<endl;
        cout<<"Average Marks      : "<<avg<<endl;
        cout<<"Variance           : "<<variance<<endl;
        cout<<"Standard deviation : "<<standarddeviation<<endl;
        cout<<"GPA                : "<<GPApoint<<endl;
        cout<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        
        //Input / Save them into txt files.
        myfile<<"Student's ID     : "<<stuID<<endl;
        myfile<<"Student's Name   : "<<stuName<<endl;
        myfile<<"Student's Gender : "<<stuGender<<endl;
        myfile<<"Each Subject Details :-- "<<endl;
        myfile<<"Programming ( "<<ProCreHrs<<" Credit Hours ) : "<<ProGrade<<"\t("<<ProPoints<<")"<<"\t("<<subPro<<")"<<endl;
        myfile<<"Chemistry   ( "<<CheCreHrs<<" Credit Hours ) : "<<CheGrade<<"\t("<<ChePoints<<")"<<"\t("<<subChe<<")"<<endl;
        myfile<<"Physics     ( "<<PhyCreHrs<<" Credit Hours ) : "<<PhyGrade<<"\t("<<PhyPoints<<")"<<"\t("<<subPhy<<")"<<endl;
        myfile<<"Calculus    ( "<<CalCreHrs<<" Credit Hours ) : "<<CalGrade<<"\t("<<CalPoints<<")"<<"\t("<<subCal<<")"<<endl;
        myfile<<"Englsh      ( "<<EngCreHrs<<" Credit Hours ) : "<<EngGrade<<"\t("<<EngPoints<<")"<<"\t("<<subEng<<")"<<endl;
        myfile<<"Total Points       : "<<totalpoint<<endl;
        myfile<<"Average Marks      : "<<avg<<endl;
        myfile<<"Variance           : "<<variance<<endl;
        myfile<<"Standard deviation : "<<standarddeviation<<endl;
        myfile<<"GPA                : "<<GPApoint<<endl;
        myfile<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        myfile<<endl;
    
     }  
    void viewreport()
    {    
          cout<<"Dean's List : "<<NumberOfDeanList()<<endl;
          cout<<"Good Standing List : "<<NumberOfGoodStanding()<<endl;
          cout<<"Pass List : "<<NumberOfPass()<<endl;
          cout<<"Probation List : "<<NumberOfProbation()<<endl;
          cout<<"Dismissal Status List : "<<NumberOfDismissal()<<endl;
    }
    void Help()
    {
          cout<<"Description : "<<endl;
          cout<<"This System is to help user to calculate GPA as well as allowing user to view the overall Students status of GPA"<<endl;
          cout<<"Category \t Marks Range \t Point"<<endl;
          cout<<" A  \t\t 85 - 100  \t 4.00"<<endl;
          cout<<" A- \t\t 80 - 84.9 \t 3.75"<<endl;
          cout<<" B+ \t\t 75 - 79.9 \t 3.50"<<endl;
          cout<<" B  \t\t 65 - 74.9 \t 3.00"<<endl;
          cout<<" C+ \t\t 55 - 64.9 \t 2.50"<<endl;
          cout<<" C  \t\t 50 - 54.9 \t 2.00"<<endl;
          cout<<" D+ \t\t 45 - 49.9 \t 1.50"<<endl;
          cout<<" D  \t\t 40 - 44.9 \t 1.00"<<endl;
          cout<<" F  \t\t < 40 \t 0"<<endl;
          //GPA Status
          cout<<"GPA \t\t Status"<<endl;
          cout<<"< 1.0 \t\t Dismissal"<<endl;
          cout<<"< 2.0 \t\t Probation"<<endl;
          cout<<"< 3.0 \t\t Pass"<<endl;
          cout<<"< 3.5 \t\t GOod Standing"<<endl;
          cout<<"< 3.5 and Above  Dean's List"<<endl;
    }
    void Exit ()
    {
         cout<<"Exit"<<endl;
         exit(0);
    }
    //Features End
    //--------------------------------------------------------------------------------------------------------------------
    //Calculation of Grade + Point + Variance + Standard Deviation
    string calculateGrade(double marks)
    {
           if (marks >=85 && marks<=100)
              return "A";
           else if (marks >= 80 && marks <= 84.9)
                return "A-";
           else if (marks >= 75 && marks <= 79.9)
                return "B+";
           else if (marks >= 65 && marks <= 74.9)
                return "B";
           else if (marks >= 55 && marks <= 64.9)
                return "C+";
           else if (marks >= 50 && marks <=54.9 )
                return "C";
           else if (marks >= 45 && marks <= 49.9)
                return "D+";
           else if (marks >= 40 && marks <= 44.9)
                return "D";
           else if (marks <40)
                return "F";         
    }
    double calculatePoint(string Grade)
    {
           if (Grade =="A" )
              return 4;
           else if (Grade =="A-")
              return 3.75;
           else if (Grade == "B+")
              return 3.5;
           else if (Grade == "B")
              return 3;
           else if (Grade =="C+")
              return 2.5;
           else if (Grade =="C")
              return 2;
           else if (Grade =="D+")
              return 1.5;
           else if (Grade =="D")
              return 1.0;
           else if (Grade =="F")
              return 0;
    }
    string GPAStatus(double value)
    {
             if(value<1)
             return "Dismissal";
             else if(value<2)
             return "Probation";
             else if (value<3)
             return "Pass";
             else if (value<3.5)
             return "Good Standing";
             else if (value>=3.5)
             return "Dean's List";
    }  
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg)
    {
       //Formuala : (n = Number of Subject)
       //Mean = avg = (total 5 subject) / n==5;
       //Each subject - Mean = ans
       //ans = ans^2
       //total += ans ( total = total + ans);
       //variance = total / (n-1)
       double total = 0;
       double variance = 0;
       total += CalculateWithinVariance(subPro, avg); //total = total + CalculateWithinVariance(subPro, avg)
       total += CalculateWithinVariance(subPhy, avg);
       total += CalculateWithinVariance(subChe, avg);
       total += CalculateWithinVariance(subCal, avg);
       total += CalculateWithinVariance(subEng, avg);
       variance = total / (5-1); //5 Subject - 1 = (n-1) = (5-1);
       //cout<<variance<<endl;
       return variance;
    }
    double CalculateWithinVariance(double allSubject, double avg)
    {
           //In this case, assume that avg == mean;
           allSubject -= avg; // allSubject = allSubject - avg(mean)
           allSubject = pow(allSubject, 2); //allSubject ^ 2 .
           return allSubject;
    }
    double CalculateStandardDeviation(double variance)
    {
           //Square root of Variance.
           return sqrt(variance);
    }
    //End of Calculation
    //---------------------------------
    //Below is calculating Number of Student Status from GPA (eg. Pass, Dismissal, ..etc)   
    int NumberOfDismissal()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dismissal") //Find Status : Dismissal
                   {
                            count++; //Find Number of student who is Dismissal.
                   }
             }
             myfile.close();
             
             return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfProbation()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Probation")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfPass()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Pass")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfGoodStanding()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Good Standing")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfDeanList()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInformation.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dean's List")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    sry i wan to ask..wat happen at my view report?it does not view the rate
    Your program does not work because it's broken as indicated by the fact that the code does not build cleanly. Using MinGW gcc with all warnings enabled on Win7:
    C:\otros\dcw>g++ -Wall ouddy1.cpp
    ouddy1.cpp: In function `void studentrecord()':
    ouddy1.cpp:82: warning: unused variable `double standDevia'
    ouddy1.cpp: In function `class string calculateGrade(double)':
    ouddy1.cpp:235: warning: control reaches end of non-void function `calculateGrade(double)'
    ouddy1.cpp: In function `class string GPAStatus(double)':
    ouddy1.cpp:269: warning: control reaches end of non-void function `GPAStatus(double)'
    ouddy1.cpp: In function `int NumberOfDismissal()':
    ouddy1.cpp:324: warning: control reaches end of non-void function `NumberOfDismissal()'
    ouddy1.cpp: In function `int NumberOfProbation()':
    ouddy1.cpp:345: warning: control reaches end of non-void function `NumberOfProbation()'
    ouddy1.cpp: In function `int NumberOfPass()':
    ouddy1.cpp:366: warning: control reaches end of non-void function `NumberOfPass()'
    ouddy1.cpp: In function `int NumberOfGoodStanding()':
    ouddy1.cpp:387: warning: control reaches end of non-void function `NumberOfGoodStanding()'
    ouddy1.cpp: In function `int NumberOfDeanList()':
    ouddy1.cpp:408: warning: control reaches end of non-void function `NumberOfDeanList()'

    C:\otros\dcw>
    Until you can compile without any errors or warnings, you should not try to run it. Warnings means that there's something wrong with your code. Never ignore warnings! Correct the warnings before retrying.

    Most of the warnings you're getting are "control reaches end of non-void function". Quickly looking at your non-void functions, I see a chain of if-else-if's which have no final else. If none of the conditions being tested are true, then none of the return statements will be executed, leaving garbage in the memory location that the calling function will read in order to get the return value. There's no telling wild and weird garbage value your program will be using. You, as the programmer, must specify all possible return values of all your functions. Adding an else that sets a known value for failure is needed.

    Comments on this post

    • Will-O-The-Wisp agrees
    • hexman agrees : That
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2226
    Originally Posted by ouddy
    sry i wan to ask..wat happen at my view report?it does not view the rate
    Just to prevent the next round of time wasted by you not having provided us with the information that we would need to help you.

    When you ask for help with a program that isn't working, you need to provide us with this information:
    1. Enough of your source code that we can compile into a program that will run and that still exhibits the problem.
    2. A description of what you expect and what you get instead. Copy-and-paste of what you actually get can be very helpful. If "it doesn't work" means that it crashes, a statement to that effect helps (it's amazing how many people don't think to tell us that).
    3. Test input data that will cause the bad output or crash. For us to test your program ourselves, we will need to know what input data to feed the program.
    4. What compiler/IDE and what operating system you're using. Not usually that important, but sometimes absolutely vital to finding the solution.

    And do not waste everybody's time by submitting code that does not compile cleanly, unless your "it doesn't work" refers to specific error messages and warnings that you get.

    Remember: Never ignore warnings! Always turn warnings on and up! And never ignore warnings!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2015
    Posts
    2
    Rep Power
    0
    Code:
    #include<iostream>
    #include<fstream>
    #include<string>
    #include<math.h>
    using namespace std;
    
    void record();
    void report();
    void Help(); 
    void Exit(); 
    string calculateGrade (double marks); //(Eg. A, A-, B+... etc)
    double calculatePoint(string Grade); //(Eg. A = 4.00, B+ =3.50, ... etc)
    string GPAStatus(double value); // For showing the Number of students' GPA Status
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg);
    double CalculateWithinVariance(double allSubject, double avg);
    double CalculateStandardDeviation(double variance);
    int main()
    {
        char choice; //Menu
        char rturn;
        do
            {
        cout<<"GPA System"<<endl;
        cout<<"Choose Option to proceed"<<endl;
        cout<<"1.Add Records"<<endl;
        cout<<"2.report"<<endl;
        cout<<"3.Help"<<endl;
        cout<<"4.Exit"<<endl;
        cin>>choice;
        choice = toupper(choice); //convert lowercase to uppercase
        
        
        
        switch(choice)
        {
    
          case '1': //New Record
                record();
               break;
          case'2':
                 report();
                 break;
          case '3'://Help
               Help();
                break;
          case '4': //Exit
               Exit();
               break;
          default : 
                  cout<<"Please Enter the Correct Answer"<<endl;
                  break;
        }
            do{
                cout<<endl<<"Return to Main Menu (Y/N)?"<<endl;
                cin>>rturn;
                rturn=toupper(rturn);
                if (rturn== 'N')
                {
                   Exit();
                 }
            }while(rturn!= 'Y');  
             
        system ("cls");
        
        }while(rturn== 'Y');
            
        system("pause");
    }
    
    void record ()
    {
         int ID;
        string Name,Gender,GPA,status;
        double subPro,subPhy,subChe,subCal,subEng,avg=0,standDevia,totalSub=0,totalpoint=0,totalcredit=0,GPApoint; // for Subjects
        string ProGrade, PhyGrade, CheGrade, CalGrade, EngGrade;
        double ProPoints, PhyPoints, ChePoints, CalPoints, EngPoints;
        double variance = 0, standarddeviation = 0; 
        int ProCreHrs, PhyCreHrs, CheCreHrs, CalCreHrs, EngCreHrs;
        
         ofstream myfile;
         myfile.open("StudentInfo.txt",ofstream::out|ofstream::app);
        
        cout<<"ID : ";
        cin>>ID;
        cout<<"Name :";
        cin>>Name;
        cout<<"Gender : ";
        cin>>Gender;
        cout<<"Each Subject Marks :"<<endl;
        cout<<"Programming : ";
        cin>>subPro;
        cout<<"Programming Credit Hours : ";
        cin>>ProCreHrs;
        ProGrade = calculateGrade(subPro);
        ProPoints = calculatePoint(ProGrade);
        cout<<"Physis : ";
        cin>>subPhy;
        cout<<"Physis Credit Hours : ";
        cin>>PhyCreHrs;
        PhyGrade =calculateGrade (subPhy);
        PhyPoints =calculatePoint(PhyGrade);
        cout<<"Chemistry : ";
        cin>>subChe;
        cout<<"Chemistry Credit Hours : ";
        cin>>CheCreHrs;
        CheGrade =calculateGrade (subChe);
        ChePoints =calculatePoint(CheGrade);
        cout<<"Calculus : ";
        cin>>subCal;
        cout<<"Calculus Credit Hours : ";
        cin>>CalCreHrs;
        CalGrade =calculateGrade (subCal);
        CalPoints =calculatePoint(CalGrade);
        cout<<"English : ";
        cin>>subEng;
        cout<<"English Credit Hours : ";
        cin>>EngCreHrs;
        EngGrade =calculateGrade (subEng);
        EngPoints =calculatePoint(EngGrade);
        
                 
        totalSub=subPhy+subChe+subCal+subEng+subPro;
        avg=(totalSub/5);
        totalpoint=(PhyPoints*PhyCreHrs)+(ProPoints*ProCreHrs)+(ChePoints*CheCreHrs)+(CalPoints*CalCreHrs)+(EngPoints*EngCreHrs); 
        totalcredit=(PhyCreHrs + ProCreHrs + CheCreHrs + CalCreHrs + EngCreHrs);
        GPApoint=totalpoint/totalcredit;
        variance = CalculateVariance(subPro, subPhy, subChe, subCal, subEng, avg);
        standarddeviation = CalculateStandardDeviation(variance);
        
        
        cout<<endl<<"Student Info "<<endl;
        cout<<"Student's ID     : "<<ID<<endl;
        cout<<"Student's Name   : "<<Name<<endl;
        cout<<"Student's Gender : "<<Gender<<endl;
        cout<<"Total Points       : "<<totalpoint<<endl;
        cout<<"Average Marks      : "<<avg<<endl;
        cout<<"Variance           : "<<variance<<endl;
        cout<<"Standard deviation : "<<standarddeviation<<endl;
        cout<<"GPA                : "<<GPApoint<<endl;
        cout<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        
        
        myfile<<"Student's ID     : "<<ID<<endl;                        //save in file
        myfile<<"Student's Name   : "<<Name<<endl;
        myfile<<"Student's Gender : "<<Gender<<endl;
        myfile<<"Each Subject Details :-- "<<endl;
        myfile<<"Total Points       : "<<totalpoint<<endl;
        myfile<<"Average Marks      : "<<avg<<endl;
        myfile<<"Variance           : "<<variance<<endl;
        myfile<<"Standard deviation : "<<standarddeviation<<endl;
        myfile<<"GPA                : "<<GPApoint<<endl;
        myfile<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
        myfile<<endl;
    
     }
    void report()
    {
         int ID;
        string Name,Gender,GPA,status;
        double avg=0,standDevia,totalSub=0,totalpoint=0,totalcredit=0,GPApoint; 
        double variance = 0, standarddeviation = 0; //Variance ,
         cout<<"Student's ID     : "<<ID<<endl;
        cout<<"Student's Name   : "<<Name<<endl;
        cout<<"Student's Gender : "<<Gender<<endl;
        cout<<"Each Subject Details :-- "<<endl;
       cout<<"Total Points       : "<<totalpoint<<endl;
       cout<<"Average Marks      : "<<avg<<endl;
       cout<<"Variance           : "<<variance<<endl;
        cout<<"Standard deviation : "<<standarddeviation<<endl;
        cout<<"GPA                : "<<GPApoint<<endl;
        cout<<"Status             : "<<GPAStatus(GPApoint)<<endl; 
    }
    void Help()
    {    
          cout<<"system calculation formula"<<"\n\n";
          cout<<"totalSub=subPhy+subChe+subCal+subEng+subPro"<<"\n\n";
          cout<<"avg=totalSub/5"<<"\n\n";
          cout<<"totalpoint=(PhyPoints*PhyCreHrs)+(ProPoints*ProCreHrs)+(ChePoints*CheCreHrs)+(CalPoints*CalCreHrs)+(EngPoints*EngCreHrs)"<<"\n\n";
          cout<<"totalcredit=(PhyCreHrs + ProCreHrs + CheCreHrs + CalCreHrs + EngCreHrs)"<<"\n\n";
          cout<<"GPApoint=totalpoint/totalcredit"<<"\n\n";
          cout<<"variance = CalculateVariance(subPro, subPhy, subChe, subCal, subEng, avg)"<<"\n\n";
          cout<<"standarddeviation = CalculateStandardDeviation(variance)"<<"\n\n";
          cout<<"Category......marks..........Cgpa"<<endl;
          cout<<" A...........85 - 10.........4.00"<<endl;
          cout<<" A-..........80 - 84.9.......3.75"<<endl;   
          cout<<" B+..........75 - 79.9.......3.50"<<endl;
          cout<<" B...........65 - 74.9.......3.00"<<endl;
          cout<<" C+..........55 - 64.9.......2.50"<<endl;
          cout<<" C...........50 - 54.9.......2.00"<<endl;
          cout<<" D...........45 - 49.9.......1.50"<<endl;
          cout<<" E...........40 - 44.9.......1.00"<<endl;
          cout<<" F............< 40...........0.00"<<endl;
    }
    void Exit ()
    {
         cout<<"Exit"<<endl;
         exit(0);
    }
    string calculateGrade(double marks)
    {
           if (marks >=85 and marks<=100)
              return "A";
           else if (marks >= 80 and marks <= 84.9)
                return "A-";
           else if (marks >= 75 and marks <= 79.9)
                return "B+";
           else if (marks >= 65 and marks <= 74.9)
                return "B";
           else if (marks >= 55 and marks <= 64.9)
                return "C+";
           else if (marks >= 50 and marks <=54.9 )
                return "C";
           else if (marks >= 45 and marks <= 49.9)
                return "D";
           else if (marks >= 40 and marks <= 44.9)
                return "E";
           else if (marks <40)
                return "F";
    }
    double calculatePoint(string Grade)
    {
           if (Grade =="A" )
              return 4;
           else if (Grade =="A-")
              return 3.75;
           else if (Grade == "B+")
              return 3.5;
           else if (Grade == "B")
              return 3;
           else if (Grade =="C+")
              return 2.5;
           else if (Grade =="C")
              return 2;
           else if (Grade =="D")
              return 1.5;
           else if (Grade =="E")
              return 1.0;
           else if (Grade =="F")
              return 0;
    }
    string GPAStatus(double value)
    {
             if(value<1)
             return "Dismissal";
             else if(value<2)
             return "Probation";
             else if (value<3)
             return "Pass";
             else if (value<3.5)
             return "Good Standing";
             else if (value>=3.5)
             return "Dean's List";
    }  
    double CalculateVariance(double subPro, double subPhy, double subChe, double subCal, double subEng, double avg)
    {
    
       double total = 0;
       double variance = 0;
       total += CalculateWithinVariance(subPro, avg); 
       total += CalculateWithinVariance(subPhy, avg);
       total += CalculateWithinVariance(subChe, avg);
       total += CalculateWithinVariance(subCal, avg);
       total += CalculateWithinVariance(subEng, avg);
       variance = total / (5-1); 
       return variance;
    }
    double CalculateWithinVariance(double allSubject, double avg)
    {
           
           allSubject =avg; 
           allSubject = pow(allSubject, 2);
           return allSubject;
    }
    double CalculateStandardDeviation(double variance)
    {
    
           return sqrt(variance);
    }
    int NumberOfDismissal()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInfo.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dismissal") 
                   {
                            count++;
                   }
             }
             myfile.close();
             
             return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfProbation()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInfo.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Probation")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfPass()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInfo.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Pass")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfGoodStanding()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInfo.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Good Standing")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }
    int NumberOfDeanList()
    {
         int count=0;
        string line;
        ifstream myfile ("StudentInfo.txt");
        if (myfile.is_open())
        {
             while (! myfile.eof())
             {
                   getline(myfile,line);
                   if (line == "Status : Dean's List")
                   {
                            count++;
                   }
             }
             myfile.close();
             
              return count;
        }
        else cout<<"Unable to open file";
    }

    i wan to ask how to do the pseudo code...cause lecture reject my flow chart..nid help
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2226
    What are you talking about? Pseudo-code is what you use to develop source code. You already have the source code! You do not need any pseudo-code! You just need to fix your code so that it will work.

    And use code tags! Your listing is an unreadable mess! I can't even tell whether you made any corrections. You most certainly have not corrected NumberOfDeanList() nor the function that precedes it.

    If your assignment is something completely different, then why keep it such a secret from us? Do you really expect us to be able to read your mind?
  10. #6
  11. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,805
    Rep Power
    508
    are we guessing yobib07 and ouddy is one person with multiple accounts?
    [code]Code tags[/code] are essential for python code and Makefiles!
  12. #7
  13. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,470
    Rep Power
    1875
    Not really, ouddy is just a dweeb who decided to hijack a thread that was nearly two years old.

    I flagged the post so the mods could split it to a new thread - but it hasn't been done either.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  14. #8
  15. Not An Expert
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2015
    Posts
    404
    Rep Power
    3
    Whoops! I must have missed that - sorry, my mistake. It's possible that the flagging system isn't working properly. I'll have to look into it. PMs and emails (markr@imninjas.com) are more likely to get my attention.

    I'll split this off into a new thread now.

    Also yes, ouddy, please use code tags when you post code in the future. The way to do this is by adding [code] at the beginning of your code, and then [(backslash)code] to the end of it (where the word backslash is replaced by a / )

    Code:
    It will format your code like this
    Into a little box
    Except I don't have any code myself
    So instead this looks like a little poem
    dwise1_aol explained this pretty well in an above post. It's really solid advice, and an important rule around here! We'll have to start giving out warnings and infractions to you (which could lead to an eventual ban) if you can't follow it.

    If it would make it easier for everyone else to read this thread, I can retroactively edit ouddy's posts to tag his [code]. Ouddy, you should be able to do this yourself, too, but it's possible that you're blocked from editing your posts as a new user. If you discover that to be the case, don't hesitate to contact me (now and in the future) and I can help.

    Edit: Also, please start your own threads in the future when you have a question - don't tag onto other peoples' threads, especially those that are years old.

    Comments on this post

    • salem agrees
    • hexman agrees
  16. #9
  17. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,323
    Rep Power
    2226
    You made many changes to your code, none of which even began to address the warnings. And you succeeded in breaking it so badly that my compiler had to give up trying to make any sense of it:
    C:TEST>g++ -Wall ouddy2.cpp
    ouddy2.cpp: In function `void record()':
    ouddy2.cpp:74: warning: unused variable `double standDevia'
    ouddy2.cpp: In function `void report()':
    ouddy2.cpp:160: warning: unused variable `double totalcredit'
    ouddy2.cpp:160: warning: unused variable `double totalSub'
    ouddy2.cpp:160: warning: unused variable `double standDevia'
    ouddy2.cpp: In function `class string calculateGrade(double)':
    ouddy2.cpp:218: parse error before `marks'
    ouddy2.cpp:237: confused by earlier errors, bailing out

    C:TEST>
    Here's the code that caused those parse errors (please note that I use code tags, as you also need to do):
    Code:
    string calculateGrade(double marks)
    {
           if (marks >=85 and marks<=100)
              return "A";
           else if (marks >= 80 and marks <= 84.9)
                return "A-";
           else if (marks >= 75 and marks <= 79.9)
                return "B+";
           else if (marks >= 65 and marks <= 74.9)
                return "B";
           else if (marks >= 55 and marks <= 64.9)
                return "C+";
           else if (marks >= 50 and marks <=54.9 )
                return "C";
           else if (marks >= 45 and marks <= 49.9)
                return "D";
           else if (marks >= 40 and marks <= 44.9)
                return "E";
           else if (marks <40)
                return "F";
    }
    This is C++, not Visual Basic! and is not a reserved word in C++ nor does it have any meaning. Rather, the relational operator for ANDing is &&, which is what you had used in the first version of this program. Whatever had possessed you to change that to something that isn't even C++?

    Not only that, but this function is one of several that throws a warning that "control reaches end of non-void function". That means that there is a path of execution in which the function does not return a value. I already pointed that out to you! Think about it. If you had written all the if and else-if conditions correctly, then the only possible condition left should be that marks < 40 in which case you should have no need to test for it explicitly. By testing for it explicitly as you are doing, you create one other possible path of execution that you are not handling, regardless of the fact that such an additional path would never be taken. The compiler cannot know that! All the compiler knows is that there is an additional possible path of execution that you are not handling.

    When your compiler gives you error messages and warnings, the first thing you need to do is to correct those errors and those warnings. First fix what you know is broken. Rewriting your entire program not only does not address the problems, but it also adds new problems, which is exactly what just happened!

    The secret to debugging is Don't Panic!. Then look at the code that threw that error or warning (the line number is right there in the error message and in the warning), figure out why that source code is not correct, and fix that specific problem. Do that with all errors and warnings, starting with the first one -- many of the subsequent errors and warnings can be caused by an earlier error (eg, if a variable declaration is bad and you use that variable in 100 places, then you will get one error and 100 warnings that that variable has not been declared; correct that one error and the 100 warnings disappear).

    Be methodical. And do not panic and change everything for no reason other than that you are panicking.

    Comments on this post

    • Will-O-The-Wisp agrees
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Location
    India
    Posts
    200
    Rep Power
    4
    Originally Posted by dwise1_aol
    You made many changes to your code, none of which even began to address the warnings. And you succeeded in breaking it so badly that my compiler had to give up trying to make any sense of it:

    Here's the code that caused those parse errors (please note that I use code tags, as you also need to do):
    Code:
    string calculateGrade(double marks)
    {
           if (marks >=85 and marks<=100)
              return "A";
           else if (marks >= 80 and marks <= 84.9)
                return "A-";
           else if (marks >= 75 and marks <= 79.9)
                return "B+";
           else if (marks >= 65 and marks <= 74.9)
                return "B";
           else if (marks >= 55 and marks <= 64.9)
                return "C+";
           else if (marks >= 50 and marks <=54.9 )
                return "C";
           else if (marks >= 45 and marks <= 49.9)
                return "D";
           else if (marks >= 40 and marks <= 44.9)
                return "E";
           else if (marks <40)
                return "F";
    }
    This is C++, not Visual Basic! and is not a reserved word in C++ nor does it have any meaning. Rather, the relational operator for ANDing is &&, which is what you had used in the first version of this program. Whatever had possessed you to change that to something that isn't even C++?

    Not only that, but this function is one of several that throws a warning that "control reaches end of non-void function". That means that there is a path of execution in which the function does not return a value. I already pointed that out to you! Think about it. If you had written all the if and else-if conditions correctly, then the only possible condition left should be that marks < 40 in which case you should have no need to test for it explicitly. By testing for it explicitly as you are doing, you create one other possible path of execution that you are not handling, regardless of the fact that such an additional path would never be taken. The compiler cannot know that! All the compiler knows is that there is an additional possible path of execution that you are not handling.

    When your compiler gives you error messages and warnings, the first thing you need to do is to correct those errors and those warnings. First fix what you know is broken. Rewriting your entire program not only does not address the problems, but it also adds new problems, which is exactly what just happened!

    The secret to debugging is Don't Panic!. Then look at the code that threw that error or warning (the line number is right there in the error message and in the warning), figure out why that source code is not correct, and fix that specific problem. Do that with all errors and warnings, starting with the first one -- many of the subsequent errors and warnings can be caused by an earlier error (eg, if a variable declaration is bad and you use that variable in 100 places, then you will get one error and 100 warnings that that variable has not been declared; correct that one error and the 100 warnings disappear).

    Be methodical. And do not panic and change everything for no reason other than that you are panicking.
    I'm no expert at C but its obvious that the OP is not only wasting their time but yours also, I'd rather ignore such posts (even more so when the user replies in a confused manner bailing out of topic, asking about pseudo-code and flow-charts!!). Declaring variables and not using them, ignoring so many compiler warnings and using "and" instead of logical operator && and who knows how many errors besides this, these are all red-flags indicating that the OP's messed up about his programming concepts and its best to give a small suggestion that they need to rewrite what they've written.

    How many times do we have explained in the forum, to use '[CODE]' tags, grouping and indenting up code, search-the-f*cking-web (or at-least pay heed to what the compiler's saying) and most of all: Do not put up all code up at once, only post the part that (you know) has errors (and I'm pretty sure that the OP knows what the compiler means by those line numbers). Posting up all the code at once, even if using CODE tags, makes the code nigh unreadable, and even more when there's no proper formatting.

    And this is not an instant-messaging service or irc of any kind, you're not supposed to use instant-messaging shortcuts here. Spelling sorry as sry, and need as nid makes you look like a semi-literate boob (as esr likes to say it).

    There's always a "How To Post" sticky thread in each section and I can say with confidence that most new-members ignore all of them.

    And the title too, "What happened at my view report?" doesn't give a clue about what you're trying to ask, and wastes the time of other members who go on the link to read this post. Try to refrain from using such pathetic headlines as your thread's title, as it affects (to some extent) how helpful answers you're gonna get.

    And I don't know why most new members don't understand that,
    We're (largely) volunteers. We take time out of busy lives to answer questions, and at times we're overwhelmed with them. So we filter ruthlessly. In particular, we throw away questions from people who appear to be losers in order to spend our question-answering time more efficiently, on winners.
    I would not give my time to such people, I think its best to ignore such as they're only a waste of time.
    What we are, unapologetically, is hostile to people who seem to be unwilling to think or to do their own homework before asking questions. People like that are time sinks — they take without giving back, and they waste time we could have spent on another question more interesting and another person more worthy of an answer. We call people like this “losers”.
    You've given a great answer here man, you've my respect for that, in fact most people wouldn't have even answered. I think the OP was talking about the design, its highly likely that the OP started a random-walk without considering any design; and not knowing what design is enough to indicate that the OP doesn't know what he's talking about.

    Thanks.
    Last edited by hexman; April 21st, 2015 at 11:55 AM.

IMN logo majestic logo threadwatch logo seochat tools logo