Question

In: Computer Science

USE C++ PLEASE AND EXPLAIN LINES AS MUCH AS POSSIBLE...THANKS IN ADVANCE...NEED THIS ASAP An unknown...

USE C++ PLEASE AND EXPLAIN LINES AS MUCH AS POSSIBLE...THANKS IN ADVANCE...NEED THIS ASAP

An unknown number of grades as integers, but no more than 30, are to be read from the file grades.dat. You may assume each grade will be a valid value between 0 and 100 (no validation necessary) and all "grades" are out of a maximum 100 points. Output the Number of Grades read in from the file. Calculate and output the Total Points Earned. Calculate and output the Total Possible Points. (Remember each grade is out of a possible 100 points max.) Following these, output each individual grade and its percentage of the Total Points Earned. Format these so that they are lined up in two columns. The first column should be 20 characters wide and contain the grade; the second column should be 8 characters wide containing the percentage. A percent sign should be output after the second field. The percentages should be rounded to the nearest tenth. Finally, output the Final Grade as a percentage, such that it lines up with second column previously. See the sample input and output that follows:

Sample Input: assuming grades.dat contained the following

100
95
87
90
76
            

Sample Output:

Number of Grades:           5
Total Points Earned:      448
Max Possible Points:      500

                 100    20.0%
                  95    19.0%
                  87    17.4%
                  90    18.0%
                  76    15.2%

Final Grade:            89.6%

Solutions

Expert Solution

CODE -

#include<fstream>

#include<iostream>

#include<iomanip>

using namespace std;

main()

{

    int grades[30];                             // Creating an array to store grades.

    int count = 0;                              // Initializing number of grades to 0

    ifstream infile;                            // File reading stream

    int total_points = 0;                       // Creating the variable to store total points earned and initializing its value to 0

    infile.open("grades.dat");                  // Opening file for reading

    while(infile.peek() != EOF)                 // Reading file till we reach the end of file.

    {

        infile >> grades[count];                // Reading the grade one at a time

        total_points += grades[count];          // Adding the current grade to total points earned.

        count++;                                // Increasing the count of no. of grades.

    }

    int max_points = count*100;                 // Calculating the maximum possible points

    infile.close();                             // Closing the file

    cout << std::left << setw(23) << "Number of Grades: " << std::right << setw(5) << count << endl;                      // Displaying the no. of grades

    cout << std::left << setw(23) << "Total Points Earned: " << std::right << setw(5) << total_points << endl;            // Displaying the total points earned.

    cout << std::left << setw(23) << "Max Possible Points: " << std::right << setw(5) << max_points << endl << endl;      // Displaying the maximum possible points.

    cout << fixed << setprecision(1);                                                                                     // Setting precision to 1 so that only 1 digit after decimal is printed.

    for(int i=0; i<count; i++)

        cout << setw(20) << grades[i] << setw(8) << ((float)grades[i]/(float)max_points) * 100 << "%" << endl;              // Displaying individual grade and its percentage

    cout << endl;

    cout << std::left << setw(20) << "Final Grade: " << std::right << setw(8) << ((float)total_points/(float)max_points) * 100 << "%" << endl;      // Displaying FInal grade

}

SCREENSHOTS -

INPUT TEXT FILE -

CODE WITH OUTPUT -

If you have any doubt regarding the solution, then do comment.
Do upvote.


Related Solutions

Please answer the questions as soon as possible. Thanks in advance. Please explain in brief in...
Please answer the questions as soon as possible. Thanks in advance. Please explain in brief in one to two paragraphs and provide graphs. 1. In two paragraphs, describe the sources of the gains from trade and why countries use import tariffs. 2b In two paragraphs, describe how the COVID-19 pandemic has impacted the global macroeconomy and multiple ways it has impacted a specific agricultural commodity market (e.g. corn, beef, wheat).
WILL RATE HIGHLY!!! Please answer both questions with as much background as possible, thanks in advance!...
WILL RATE HIGHLY!!! Please answer both questions with as much background as possible, thanks in advance! 1. Why Corporate Bonds are carrying "exchange prices" fluctuating everyday and different from it's original "Issued Prices" by corporations? 2. Describe how the market interest rate, relative to the contractual interest rate, affects the selling price of bonds. Also explain the rationale for requiring an investor to pay accrued interest when a bond is purchased between interest payment dates.
please answer it ASAP, Its URGENT!!! Thanks in advance Describe the entire path of the blood...
please answer it ASAP, Its URGENT!!! Thanks in advance Describe the entire path of the blood flow through the heart starting with blood returning to the heart from the body. Be sure to include each chamber, valve and vessel. Right and left are also important. (answer in ~250 words)
Please try to answer as soon as possible. Thanks in advance. Answer the questions true, false...
Please try to answer as soon as possible. Thanks in advance. Answer the questions true, false or uncertain and provide a brief explanation or a graph to defend your answer. 1 a) A change in relative prices will always change a utility maximizing consumer’s marginal rate of substitution. 1b) Competitive firms shutdown production when price falls below the minimum of the average total cost curve. 1c) An increase the price of firms output will always increase the use of an...
Need assistance with this! Thanks in advance! Label all axes (P, Q) Label all lines/curves (Demand,...
Need assistance with this! Thanks in advance! Label all axes (P, Q) Label all lines/curves (Demand, Supply) Label all relevant equilibrium points Label intercepts for your linear demand and supply. (Intercepts are the points where the lines intersect the axes. For example, if a demand curve intersects the price axis at P=100, indicating that at P=100, 0 units are demanded, you should label that point on the axis with the price of 100). Please limit your depictions of supply and...
Please Reply with an answer as soon as possible, will appreciate it so much. Thanks in...
Please Reply with an answer as soon as possible, will appreciate it so much. Thanks in advance. Case Problem: You are a HR assistant manager in a company employing many expatriates from around the world. Your company has selected ‘FutureFunds Pension Planners’ to provide your employees with an international pension plan that takes advantage of tax laws. The plan allows the company to make tax free contributions to the employee pension funds. It also allows Individuals enrolling in the plan...
Please give a detailed explanation, not just the answer. Thanks in advance! Use the data in...
Please give a detailed explanation, not just the answer. Thanks in advance! Use the data in the given table to fill in the missing coefficients. Round your answers to 3 decimal places. x y 2 13.524 7.5 19.125 13 23.463 18.5 28.937 24 33.6 29.5 37.779 35 43.065 y=_____x +_______
I need the code for following in C++ working for Visual studio please. Thanks Use a...
I need the code for following in C++ working for Visual studio please. Thanks Use a Struct to create a structure for a Player. The Player will have the following data that it needs maintain: Struct Player int health int level string playerName double gameComplete bool isGodMode Create the 2 functions that will do the following: 1) initialize(string aPlayerName) which takes in a playername string and creates a Player struct health= 100 level= 1 playerName = aPlayerName gameComplete = 0...
write in C++ as simple as possible please and thanks don't use header file <bits/stdc++.h> All...
write in C++ as simple as possible please and thanks don't use header file <bits/stdc++.h> All programs work with binary numbers which are powers of 2 (2, 4, 8, …).  Write a program that will have a user enter a number (n) less than 10,000. Then have the program put each power of 2 (int) into an array up to and possibly including the number n. This means you don't know at the start how large the array will be, so...
I need Q1,2 and 3 ASAP please, thanks 1. Identify three applications of integration. 2. Give...
I need Q1,2 and 3 ASAP please, thanks 1. Identify three applications of integration. 2. Give two specific examples of how we use integration to solve real-world problems. 3. Write a paragraph about how integration is applied in non-STEM disciplines. You must start a thread before you can read and reply to other threads
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT