Question

In: Computer Science

First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3...

First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3 L4 L5 L6 L7 L8 L9 P0 P1 P2 E0 E1 E2 FI ATT
------------------------------------------------------------------------------------------------------------------------------------------
Kevin Smith 90 100 100 100 98 97 87 100 85 87 89 100 100 100 100 90 100 98 90 100 98 98 98 90 90 98 88 0.00
Morgan Kelly 80 100 65 67 69 71 100 100 100 67 95 85 87 89 100 65 67 69 71 100 98 98 98 65 67 69 71 0.10
Isaac Newton 100 90 100 90 100 90 100 90 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.00
Cole Jones 100 100 100 87 73 75 77 79 81 87 89 91 73 75 77 79 81 100 100 100 98 100 65 67 69 71 63 0.05
Angela Allen 100 100 100 87 89 91 93 95 100 100 100 100 100 100 100 95 97 100 98 98 98 90 73 75 77 79 81 0.02
David Cooper 56 58 60 62 64 100 100 100 87 73 75 77 100 100 77 79 81 100 100 100 98 70 72 74 76 78 88 0.00
Nancy Bailey 100 87 89 91 93 95 100 100 100 100 100 100 91 93 95 97 100 98 100 100 98 98 98 90 90 98 88 0.00
Emily Synder 65 67 69 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 74 76 78 90 90 74 76 98 88 0.00
Lori Austin 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 98 98 90 90 98 88 0.02
Jenny Howard 56 58 60 62 71 62 64 73 100 66 68 70 72 74 76 78 100 100 100 60 62 79 66 68 70 68 70 0.03
Anne Lewis 100 86 58 60 100 71 62 64 73 94 66 68 90 72 74 76 78 67 68 69 70 71 98 88 76 78 68 0.04
Nick Johnson 100 100 89 91 73 75 77 79 81 100 100 100 98 100 100 95 85 87 89 100 98 98 98 80 76 78 98 0.01
Nick Spickler 100 93 95 97 100 98 98 98 90 100 89 91 93 95 97 100 100 89 91 93 95 97 98 98 90 90 98 0.00
Joy Williams 75 77 58 60 62 79 66 68 70 72 81 100 100 71 62 64 73 94 66 98 90 90 98 68 90 88 77 0.00
Barbara Hood 100 67 95 85 87 89 91 93 95 97 85 87 100 100 100 71 62 64 73 94 66 68 98 98 90 90 88 0.00
Joe Hoarn 62 63 64 65 66 67 68 69 70 71 100 81 100 100 71 62 64 73 100 100 98 98 64 73 94 66 68 0.08
Payton Bardzell 100 100 100 97 87 67 95 85 87 89 91 93 95 97 100 100 100 95 85 87 89 100 98 90 90 78 98 0.00
Kim Ludwig 71 62 64 73 75 77 58 60 62 79 66 68 70 72 81 100 100 79 66 68 70 72 98 98 90 90 98 0.09
Susan Honks 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 90 90 88 100 100 100 100 0.00

Write the program in C++ read the grades of all the students from the file above. For each student’s scores,

The program most be define arrays to keep scores for quizzes, labs, projects, midterms. Secondly, read in the grades for each student and define a function to calculate and return the average grade of quizzes, labs, projects and midterms. Sample prototype of this function: float getAverage(float gradeArray[], int arraySize); // a function to calculate average of array. Also, define a function to calculate and return the final letter grade of this student. Note the total grade, average project grade, and the attendance will be taken into consideration when the final grade is calculated. Last importantly, output this student’s first name, last name, and final letter grade in a nice format to a file named letter120.dat. Each student’s data is in one line. This file should be in the same location as data that is given from the above file. The format should be as following:

First Name Last Name Final Grade

Nick Johnson A

Anne Lewis B

Writing the program in C++

Use constants to keep the percentage values in the above table.

COMMENT YOUR CODE.

Give meaningful variable, array, and function names based on this program.

Arrays and functions are implemented properly.

The grade is calculated correctly and output file is generated properly.

Solutions

Expert Solution

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

float getFinalGrade(float totalGrade, float averageProjectGrade, float att);

//Function to calculate the average grade
float getAverage(vector<int> grades, const int size) {
        float avg = 0.0;
        for (auto iterator: grades) {
                avg += *iterator;
        }
        return (avg/size);
}

int main() {
        //Declarations
        int noOfStudents;
        const vector<string> studentFirstNames, studentLastNames;
        const int noOfQuizzes = 10, noOfLabs = 10, noOfProjects = 3, noOfMidterms = 3;
        const vector<vector<int>> quizzes, labs, projects, midterms;
        const vector<float> totalGrade, attendance;
        
        numberOfStudents = 0;
        
        //File declare and open input file
        fstream inputFile;
        inputFile.open("input.dat", ios::in);
        
        /If file is open read and store input in arrays
        if (inputFile.is_open()) {
                string line;
                while (getline(inputFile, line)) {
                        ++noOfStudents;
                        //Split string by whitespaces
                        string token = strtok(line, " ");
                        int i = 0;
                        //Arrays to store quiz grades of each student
                        vector<int> quiz, lab, project, midterm;
                        while (token != NULL) {
                                if (i == 0) {
                                        studentFirstNames.push_back(token);
                                } else if (i == 1) {
                                        studentLastNames.push_back(token);      
                                } else if (i <= 11) {
                                        quiz.push_back(stoi(token));
                                } else if (i <= 21) {
                                        lab.push_back(stoi(token));
                                } else if (i <= 24) {
                                        project.push_back(stoi(token));
                                } else if (i <= 27) {
                                        midterm.push_back(stoi(token));
                                } else if (i == 28) {
                                        totalGrade.push_back(stoi(token));
                                } else {
                                        attendance.push_back(stoi(token));
                                }
                                ++i;
                                token = strtoken(line, " ");
                        }
                        //Add all the arrays into respectives
                        quizzes.push_back(quiz);
                        labs.push_back(lab);
                        projects.push_back(project);
                        midterms.push_back(midterm);
                }
                //Close the input file
                inputFile.close();
        }
        //If file does not open display error and exit
        else {
                cout<<"There was a problem in reading data from file!!!";
                return 0;
        }
        
        vector<float> quizAverages, labAverages, projectAverages, midtermAverages;
        
        int iterator;
        for (iterator = 1; iterator <= noOfStudents; ++iterator) {
                //Calculate averages by calling getAverage function
                quizAverages.push_back(getAverage(quizzes[iterator], noOfQuizzes));
                labAverages.push_push(getAverage(labs[iterator], noOfLabs));
                projectAverages.push_back(getAverage(projects[iterator], noOfProjects));
                midtermAverages.push_back(getAverage(midterms[iterator], noOfMidterms));
        }
        
        //Array to store finalGrade
        vector<string> finalGrade;
        
        int iterator;
        for (iterator = 1; iterator <= noOfStudents; ++i) {
                //Calculate final grade by getFinalGrade function
                //Hope you can write this as there has been no logic specifies
                finalGrades.push_back(getFinalGrade(totalGrade[iterator], projectAverages[iterator], attendance[iterator]));
        }
        
        //Declare and open output file
        fstream outputFile;
        outputFile.open("letter120.dat", ios::out);
        
        //If file is not opened display error and exit
        if (!outputFile.is_open()) {
                cout<<"Problem writing output to file";
                return 0;
        }
        
        //Wrtie headings first to output
        outputFile<<"FIrst Name           Last Name               Final Grade\n";
        
        //Write line by line to file
        for (iterator = 1; iterator <= noOfStudents; ++i) {
                outputFile<<studentFirstName[iterator]<<"   "<<studentLastName[iterator]<<"             "<<finalGrade[iterator];
                outputFile<<"\n";
        }
        
        return 0;
}

This program reads input from a file (should be in specified format)

Calculates averages and final Grades respectively and then finally writes this output to a file named letter120.dat file


Related Solutions

First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3...
First Last Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 L0 L1 L2 L3 L4 L5 L6 L7 L8 L9 P0 P1 P2 E0 E1 E2 FI ATT ------------------------------------------------------------------------------------------------------------------------------------------ Kevin Smith 90 100 100 100 98 97 87 100 85 87 89 100 100 100 100 90 100 98 90 100 98 98 98 90 90 98 88 0.00 Morgan Kelly 80 100 65 67 69 71 100 100 100 67 95 85 87 89 100 65 67...
Do all the Q1, Q2, Q3 and Q4 The cash budget is the primary tool used...
Do all the Q1, Q2, Q3 and Q4 The cash budget is the primary tool used in short-term financial planning. As with many calculations, the sales forecast is a primary input. As an example of the cash budgeting process, we will use the Fun Toys Corporation. The sales projections and other information provided are: Q1 Q2 Q3 Q4 Sales $    200,000,000 $      300,000,000 $    250,000,000 $    400,000,000 Beginning receivables: $    120,000,000 Receivables period (days):                        45 With the receivables period shown, we can calculate the percentage...
Production Budget Q1 Q2 Q3 Q4 Total Sales in Units        1,000        1,200        1,500...
Production Budget Q1 Q2 Q3 Q4 Total Sales in Units        1,000        1,200        1,500        2,000        5,700 Add: Desired Ending Inv.                240            300            400            400            400 Total Needs        1,240        1,500        1,900        2,400        6,100 Less:Beginning Inv.                180            240            300            400            180 Units to be produced        1,060        1,260        1,600        2,000        5,92 The Direct Materials Budget tells management how much...
Brunell Products has projected the following sales for the coming year:    Q1 Q2 Q3 Q4...
Brunell Products has projected the following sales for the coming year:    Q1 Q2 Q3 Q4 Sales $480 $570 $720 $660    Sales in the year following this one are projected to be 10 percent greater in each quarter.    Calculate payments to suppliers assuming that the company places orders during each quarter equal to 25 percent of projected sales for the next quarter. Assume that the company pays immediately.    a. What is the payables period in this case?...
Let Q1, Q2, Q3, Q4 be constants so that R (2x + 3) sin 4x dx...
Let Q1, Q2, Q3, Q4 be constants so that R (2x + 3) sin 4x dx = (Q1x + Q2) sin 4x + (Q3x+Q4) cos 4x+C, where C is a constant of integration. Let Q = ln(3 +|Q1|+ 2|Q2|+ 3|Q3| + 4|Q4|). Then T = 5 sin2 (100Q) satisfies:— (A) 0 ≤ T < 1. — (B) 1 ≤ T < 2. — (C) 2 ≤ T < 3. — (D) 3 ≤ T < 4. — (E) 4 ≤...
Wentworth Products has projected the following sales for the coming year: Q1 Q2 Q3 Q4   Sales...
Wentworth Products has projected the following sales for the coming year: Q1 Q2 Q3 Q4   Sales $360 $450 $600 $540 Sales in the year following this one are projected to be 10 percent greater in each quarter. Calculate payments to suppliers assuming that the company places orders during each quarter equal to 25 percent of projected sales for the next quarter. Assume that the company pays immediately. a. What is the payables period in this case? (Do not round intermediate...
Wentworth Products has projected the following sales for the coming year: Q1 Q2 Q3 Q4   Sales...
Wentworth Products has projected the following sales for the coming year: Q1 Q2 Q3 Q4   Sales $650 $740 $875 $805 Sales in the year following this one are projected to be 15 percent greater in each quarter. a. Assume that the company places orders during each quarter equal to 30 percent of projected sales for the next quarter. Assuming that the company pays immediately, what is the payables period? (Do not round intermediate calculations and round your answer to the...
All That Remains Products has projected sales for next year of: Q1 Q2 Q3 Q4 Sales...
All That Remains Products has projected sales for next year of: Q1 Q2 Q3 Q4 Sales $ 76,000 $ 79,775 $ 86,500 $ 93,480 The company places orders each quarter that are 52 percent of the following quarter's sales and has a 60-day payables period. What is the accounts payable balance at the end of the third quarter?
Direct Materials Budget For the year ending December 31, 2018 Plain t-shirts Q1 Q2 Q3 Q4...
Direct Materials Budget For the year ending December 31, 2018 Plain t-shirts Q1 Q2 Q3 Q4 Total Units to be produced 1060 1260 1600 2000 5920 Direct materials per unit 1 1 1 1 1 Production needs 1060 1260 1600 2000 5920 Desired ending inventory 126 160 200 106 106 Total needs 1186 1420 1800 2106 6026 Less beginning inventory 58 126 160 200 58 Direct materials to be purchased 1128 1294 1640 1906 5968 Cost per t-shirt $       3.00...
Period Sales ($million) 2017 Q1 2874 2017 Q2 3000 2017 Q3 2913 2017 Q4 2916 2918...
Period Sales ($million) 2017 Q1 2874 2017 Q2 3000 2017 Q3 2913 2017 Q4 2916 2918 Q1 2910 2018 Q2 3052 2018 Q3 3116 2018 Q4 3210 2019 Q1 3243 2019 Q2 3351 2019 Q3 3305 2019 Q4 3267 The above table represents the quarterly sales (measured in millions of dollars) for the Goodyear Tire from 2017 to 2019. Compute the 4-quarter moving average. Put your answers onto the table. Compute the 4-quarter centered moving average. Put your answers onto...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT