Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++, Write a program that asks a student for his/her grades assessing his/her

ID: 3666753 • Letter: I

Question

In C++,

Write a program that asks a student for his/her grades assessing his/her C++ programming skills. The student gets a separate grade for each homework assignment and the lab exam associated with it. In order for the student to pass the class, he/she needs to achieve 50% or better in all possible “dimensions”, i.e.,

>= 50% average in homework assignments

>= 50% average in lab exams

Assume that the student has been given 5 “sets” of homework assignments and lab exams, respectively, and that the scores are given in percentages.

The program should get input from the screen and do the following:

a) Calculate the best, worst, and average grade for each of the two components (hw assignments and lab exams).

b) Calculate the overall grade of the student, as the average of the hw/lab sets averages.

c) Decide whether the student passes the class or not. If the student cannot pass the class, the program should output the reason why.

Explanation / Answer


#include <iostream>
#include <fstream> //Basic C++ Libraray which has all functions related to file opeartions.
using namespace std;

void exercise();

// main function
int main()
{
   exercise();
   return 0;
}

// define exercise
void exercise()
{
   double points[2][8]={};
   double FinalGrade=0;
   double average[5]={0,0,0,0,0};
  
   // asking user to enter assignment value
  
   cout << "PLEASE ENTER YOUR FIVE HOMEWORK ASSIGNMENT points IN C++"<<endl;
   for(int i=0;i<5;i++)
   {
       cin >> points[0][i]; //getting five home works points
   }
  
   //asking user to enter lab points
   cout << "PLEASE ENTER YOUR FIVE LABS points IN C++"<<endl;
   for(int i=0;i<5;i++)
   {
       cin >> points[1][i]; //getting five lab points
   }
   for(int i=0;i<5;i++)
   {
       for(int j=0;j<2;j++)
       {
           if(points[j][i]>100)
           {
               cout << "PLEASE ENTER YOUR points < 100" <<endl;
               exercise();
               return;
           }
       }
   }
   points[0][5]=points[0][0];//To know best HW we are initializing here
   points[1][5]=points[1][0];//To know best Lab we are initializing here
   points[0][6]=points[0][0];//To know worst HW we are initializing here
   points[1][6]=points[1][0];//To know worst Lab we are initializing here
   for(int i=0;i<5;i++)
   {
       for(int j=0;j<2;j++)
       {
           if(points[j][i]>points[j][5])
           {
               points[j][5] = points[j][i];//Acquiring best HW and Best Lab
           }
           if(points[j][i]<points[j][6])
           {
               points[j][6] = points[j][i];//Acquiring worst HW and worst Lab
           }
           points[j][7] =points[j][i]+points[j][7];//Acquiring AVG HW and AVG Lab Calculation
       }
   }
   points[0][7]=points[0][7]/5; //Average Calculation for HW
   points[1][7]=points[1][7]/5; //Average Calculation for Lab
   for(int i=0;i<5;i++)   //Average Calculation For each Assignment
   {
       average[i]=(points[0][i]+points[1][i])/2; //Average calculation for each assignment
   }
   FinalGrade=(points[0][7]+points[1][7])/2;
   cout << "**************************FINAL RESULT***************************************** "; //Final Result Printing
   cout << "       1   2   3   4   5   BEST   WORST   AVERAGE ";
   cout << "******************************************************************************* ";
   cout << "HOMEWORK        ";
   for(int i=0;i<8;i++)
   {
       cout.precision(2);
       cout.setf(ios::fixed);
       cout << points[0][i] << "   ";
   }
   cout << " LAB       ";
   for(int i=0;i<8;i++)
   {
       cout.precision(2);
       cout.setf(ios::fixed);
       cout << points[1][i] << "   ";
   }
   cout << " AVERAGE          ";
   for(int i=0;i<5;i++)
   {
       cout.precision(2);
       cout.setf(ios::fixed);
       cout << average[i] << "   ";
   }
   cout.precision(2);
   cout.setf(ios::fixed);
   cout << "YOUR OVERALL GRADE IS: "<< FinalGrade<<endl;
   if(points[0][7] < 50 || points[1][7] <50)
   {
       cout.precision(2);
       cout.setf(ios::fixed);
       cout << " SORRY YOU HAVE FAILED THIS CLASS BECAUSE YOU HAVE NOT MET REQUIREMENTS OF ACHEVEING AVERGAE MORE THAN 50 % IN HOMEWORKS AND ASSIGNEMNTS "<<endl;
       cout<<"YOUR AVERAGE IN HOME WORK ASSIGNMENTS IS " << points[0][7] <<endl;
       cout<<"YOUR AVERAGE IN LAB IS "<<points[1][7]<< " KINDLY IMPROVE YOUR MARKS NEXT SEMESTER."<<endl;
   }
   else
   {
       cout << " CONGRATULATIONS! YOU PASSED THE CLASS!"<<endl;
   }
   cout << " PLEASE ENTER THE FILE NAME THAT WHICH YOU WANT TO SAVE THE RESULT "<<endl;
   char fileName[16];
   cin >> fileName;
   ofstream sout;
   sout.open(fileName);
   if (sout.fail( ) )
   {
       sout << "Input file opening failed. ";
       return;
   }
   else
   {
       sout << "**************************FINAL RESULT***************************************** ";//Final Result Saving to File
       sout << "       1   2   3   4   5   BEST   WORST   AVERAGE ";
       sout << "******************************************************************************* ";
       sout << "HOMEWORK        ";
       for(int i=0;i<8;i++)
       {
           sout.precision(2);
           sout.setf(ios::fixed);
           sout << points[0][i] << "   ";
       }
       sout << " LAB       ";
       for(int i=0;i<8;i++)
       {
           sout.precision(2);
           sout.setf(ios::fixed);
           sout << points[1][i] << "   ";
       }
       sout << " AVERAGE          ";
       for(int i=0;i<5;i++)
       {
           sout.precision(2);
           sout.setf(ios::fixed);
           sout << average[i] << "   ";
       }
       sout.precision(2);
       sout.setf(ios::fixed);
       sout << "YOUR OVERALL GRADE IS: "<< FinalGrade<<endl;
       if(points[0][7] < 50 || points[1][7] <50)
       {
           sout.precision(2);
           sout.setf(ios::fixed);
           sout << " SORRY YOU HAVE FAILED THIS CLASS BECAUSE YOU HAVE NOT MET REQUIREMENTS OF ACHEVEING AVERGAE MORE THAN 50 % IN HOMEWORKS AND ASSIGNEMNTS "<<endl;
           sout<<"YOUR AVERAGE IN HOME WORK ASSIGNMENTS IS " << points[0][7] <<endl;
           sout<<"YOUR AVERAGE IN LAB IS "<<points[1][7]<< " KINDLY IMPROVE YOUR MARKS NEXT SEMESTER."<<endl;
       }
       else
       {
           sout << " CONGRATULATIONS! YOU PASSED THE CLASS!"<<endl;
       }


       }
   sout.close();
   cout << "YOUR REPORT HAS BEEN SUCCESSFULLY SAVED TO "<<fileName<<endl;
}

Sample Output

                                                                                                                               
PLEASE ENTER YOUR FIVE HOMEWORK ASSIGNMENT points IN C++                                                                                                    
30                                                                                                                                                          
35                                                                                                                                                          
45                                                                                                                                                          
30                                                                                                                                                          
45                                                                                                                                                          
PLEASE ENTER YOUR FIVE LABS points IN C++                                                                                                                   
50                                                                                                                                                          
40                                                                                                                                                          
                                                                                                                                                          
45                                                                                                                                                          
50                                                                                                                                                          
35                                                                                                                                                          
**************************FINAL RESULT*****************************************                                                                             
                1       2       3       4       5       BEST    WORST   AVERAGE                                                                             
*******************************************************************************                                                                             
HOMEWORK        30.00   35.00   45.00   30.00   45.00   45.00   30.00   37.00                                                                               
LAB             50.00   40.00   45.00   50.00   35.00   50.00   35.00   44.00                                                                               

    main.cpp

Compile | Execute | Share Project
               1       2       3       4       5       BEST    WORST   AVERAGE                                                                             
*******************************************************************************                                                                             
HOMEWORK        30.00   35.00   45.00   30.00   45.00   45.00   30.00   37.00                                                                               
LAB             50.00   40.00   45.00   50.00   35.00   50.00   35.00   44.00                                                                               
                                                                                                                                                            
AVERAGE         40.00   37.50   45.00   40.00   40.00   YOUR OVERALL GRADE IS: 40.50                                                                        
                                                                                                                                                            
SORRY YOU HAVE FAILED THIS CLASS BECAUSE YOU HAVE NOT MET REQUIREMENTS OF ACHEVEING AVERGAE MORE THAN 50 % IN HOMEWORKS AND ASSIGNEMNTS                     
YOUR AVERAGE IN HOME WORK ASSIGNMENTS IS 37.00                                                                                                              
YOUR AVERAGE IN LAB IS 44.00                                                                                                                                
KINDLY IMPROVE YOUR MARKS NEXT SEMESTER.                                                                                                                    
                                                                                                                                                            
PLEASE ENTER THE FILE NAME THAT WHICH YOU WANT TO SAVE THE RESULT                                                                                           
grade.txt                                                                                                                                                   
YOUR REPORT HAS BEEN SUCCESSFULLY SAVED TO grade.txt