Question

In: Computer Science

Write a program that will calculate numerical and letter grades for a student and output a...

Write a program that will calculate numerical and letter grades for a student and output a report:

  1. The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments:
  2. First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values for ex-am grades, percentage of ex-am grades. For example, the first row of the data file contains the following:

Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45

The student, Sherlock Holmes, has three homework grades, each with a value of 100. Homework is 15% of total grade. He has three program grades with values of 75, 80, 90. Program is 40% of grade. He has three exa-ms grades of 60, 70, 70. Exa-ms are 45% of grade.

  1. Request the name of the input file from the user. Do not “hard-code” the file name in the program. Check to ensure the input file opens. If it does not open, display an appropriate message to the user and exit the program.
  2. Using a looping construct, read until end of file. Do not hard code the number of rows in the loop. The file must be read using an outer loop and three inner/nested loops to read all the data properly. The first number will aid in determining the NUMBER of grades to read. Do NOT assume there will be only 3 values in each category. Code for a variable number of values in each category.
  3. The maximum points for each assignment, homework and ex am are 100. The maximum points for each may be calculated by multiplying the number of assignments in the group by 100. Calculate final grade using the following formula:

((total HOMEWORK Points earned/maximum HOMEWORK points) * percent of total grade) + (total PROGRAM Points earned/maximum PROGRAM points) * percent of total grade) + (total EX-AM Points earned/maximum EX-AM points) * percent of total grade)) * 100

  1. Use the final numerical grade to look up corresponding letter grade as follows:

90 - 100 = A

80 - 89 = B

70 - 79 = C

60 - 69 = D

< 60 = F

  1. Use the final letter grade to look up a "witty" comment of your choice, using a SWITCH statement. A statement must be output for each letter grade above. For example:

A = "Most excellent work”

B = "IMHO You Passed"

etc.

  1. Request an output file name from the user. Do not “hard-code” the file name in the program. Check to ensure the output file opens. If it does not open, display an appropriate message to the user and exit the program.
  2. For each student, output the following to the console (screen) and the output file in a neat, readable format. Output each input line on one output line. Use manipulators to output values in readable columns:

Student Name, Total Points (numerical grade): NN. Letter Grade: X. Depending on letter grade, The witty comment.

  1. Include the following documentation. Points will be deducted if you do not include the following documentation:

The name of your C++ file

Your name

Some kind of date, either the due date or the date you finished

The type of input

The type of output

A brief description of the algorithm/program

Watch for 1-off errors; truncated grade values; infinite loops

Turn in file code *.cpp; README file; input file (even though provided) and ALL output files. You DO NOT need to submit the executable (*.exe). You MAY zip all the files and submit if you choose. You MUST include all the files indicated or points will be deducted.

README must contain instructions for location of input/output files

STUDENT .TXT

Sherlock Holmes 3 100 100 100 0.15 3 75 80 90 0.40 3 60 70 70 0.45
Constant Success 4 100 88 100 92 0.15 3 75 80 90 0.40 2 100 89 0.45
Happy Grant 3 79 82 77 0.15 3 80 82 93 0.40 3 86 90 76 0.45
Reach Further 3 100 99 98 0.15 3 98 97 93 0.40 3 88 90 99 0.45

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(){
    const int SIZE=4;
    int i;
    const int maxCount = 9;

    struct Records {
        string firstname;
        string secondname;
        
        int homework_grades;
                int homework_value[maxCount];
        float homework_total_grade;
        int program_grades;
                int program_values[maxCount];
        float program_total_grade;
        int exa_ms_grades;
                int exa_ms_values[maxCount];
        float exa_ms_total_grades;
        
    }record[SIZE];
/*  string filename;
    ofstream fileC;

    cout << "which file do you want to open?";
    cin >> filename;

    fileC.open(filename.c_str());
*/
    ifstream in("STUDENT.txt");

    if (!in){
    cerr << "File can't be opened! " << endl;
    system("PAUSE");
    exit(1);
    }
    for (int i=0; i < SIZE; i++){
            in >> record[i].firstname >> record[i].secondname >>record[i].homework_grades;
            
                for(int j=0;j<record[i].homework_grades;j++){
                        in >> record[i].homework_value[j];
                } 
                
                in >> record[i].homework_total_grade >> record[i].program_grades;
                
                for(int j=0;j<record[i].program_grades;j++){
                        in >> record[i].program_values[j];
                }
                
                in >> record[i].program_total_grade >> record[i].exa_ms_grades;  
                
                for(int j=0;j<record[i].exa_ms_grades;j++){
                        in >> record[i].exa_ms_values[j];
                }
                
                in >> record[i].exa_ms_total_grades ;
    }
    for (int i=0; i < SIZE; i++){
                        float homework_earned= 0 ;
                        float total_homework_point = 0;
                        
                        float program_earned= 0;
                        float total_program_point = 0;
                        
                        float exa_ms_earned = 0;
                        float total_exa_ms_point = 0;
                        
                        for(int j=0;j<record[i].homework_grades;j++){
                                        homework_earned += record[i].homework_value[j];
                                        total_homework_point +=100;
                        } 
                        
                
                        for(int j=0;j<record[i].program_grades;j++){
                                        program_earned += record[i].program_values[j];
                                        total_program_point +=100;
                        }
                        
                        
                        for(int j=0;j<record[i].exa_ms_grades;j++){
                                        exa_ms_earned += record[i].exa_ms_values[j];
                                        total_exa_ms_point +=100;
                        }
                        
                        /* cout<<"((total HOMEWORK Points earned/maximum HOMEWORK points) * percent of total grade):  "<<homework_earned<<"/"<<total_homework_point<<"*"<<record[i].homework_grades<<"+";
                         cout<<" (total PROGRAM Points earned/maximum PROGRAM points) * percent of total grade)"<<program_earned<<"/"<<total_program_point<<"*"<<record[i].program_grades<<"+";
                         cout<<"((exa_ms_earned/total_exa_ms_point)*record[i].exa_ms_grades)"<<exa_ms_earned<<"/"<<total_exa_ms_point<<"*"<<record[i].exa_ms_grades;
                         */
                        float final_grade= (((homework_earned/total_homework_point)*record[i].homework_total_grade)+((program_earned/total_program_point)*record[i].program_total_grade)+((exa_ms_earned/total_exa_ms_point)*record[i].exa_ms_total_grades));
                        final_grade=final_grade*100;
                        char letter_grade;
                        //cout <<"final grades= " << final_grade<<"\n";
                        if (final_grade>=90 or final_grade<=100){
                                letter_grade ='A';
                        }else if (final_grade>=80 or final_grade<=89){
                                letter_grade='B';
                        }else if (final_grade>=70 or final_grade<=79){
                                letter_grade='C';
                        }else if (final_grade>=60 or final_grade<=69){
                                letter_grade='D';
                        }else{
                                letter_grade='F';
                        }
                        
                switch (letter_grade) {
                        case 'A':cout <<"Most excellent work"<<"\n";
                                break;
            case 'B':cout<<"good work"<<"\n";
            break;
            case 'C':cout<<"Average Work"<<"\n";
                        break;
                        case 'D' :cout<<"Pass"<<"\n";
                        break;
                        default:cout<<"Failed"<<"\n";
                        break;
                
                }
                         
   }
         
   /* for (int i=0;i< SIZE;i++) {
        cout << record[i].firstname<<"  ";
        cout << record[i].secondname<<" ";
        cout << record[i].homework_grades<<"  ";
        
        for(int j=0;j<record[i].homework_grades;j++){
                        cout << record[i].homework_value[j] <<" ";
                } 
                
                cout << record[i].homework_total_grade << "  ";
                cout << record[i].program_grades << "  ";
                
                for(int j=0;j<record[i].program_grades;j++){
                        cout << record[i].program_values[j]<<" ";
                }
                
                cout << record[i].program_total_grade << "  ";
                cout << record[i].exa_ms_grades << "  ";
                
                for(int j=0;j<record[i].exa_ms_grades;j++){
                        cout << record[i].exa_ms_values[j]<<" ";
                }
                
        cout << record[i].exa_ms_total_grades << "  "<<"\n";
                
    }   */
return 0;
}

Related Solutions

Write a program that will calculate numerical and letter grades for a student and output a...
Write a program that will calculate numerical and letter grades for a student and output a report: The information will be in the provided data file studentGrades.txt. The data file consists of several rows of data containing a student name and information for 3 types of assignments: First Name, Last Name, number of homework grades, values for homework grades, percentage of total grade, number of program grades, values for program grades, percental of total grade, number of ex-am grades, values...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with...
Grade:ABCDF Probability:0.10.30.40.10.1 To calculate student grade point averages, grades are expressed in a numerical scale with A = 4, B = 3, and so on down to F = 0. Find the expected value. This is the average grade in this course. Explain how to simulate choosing students at random and recording their grades. Simulate 50 students and find the mean of their 50 grades. Compare this estimate of the expected value with the exact expected value from part (a)....
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
For this assignment, write a program that will calculate the quiz average for a student in...
For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of quiz...
Write a program to calculate fees that must be paid by a student at a State...
Write a program to calculate fees that must be paid by a student at a State university using the following values: Each semester unit $90.00 Regular room charge per semester $200.00 Air conditioned room $250.00 Food charge for the semester $400.00 Matriculation fee (all students) $30.00 Diploma fee (if graduating student) $35.00 Input student ID number (one integer containing four digits), the type of room (regular or air conditioned), units, and whether or not the student is graduating. Output an...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
Overview For this assignment, write a program that will calculate the quiz average for a student...
Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be written in two versions. The first version of the program will read a set of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT