Question

In: Computer Science

Here we will be taking data in as a file. Note that the sample file provided...

Here we will be taking data in as a file. Note that the sample file provided here is not the file that I will use to grade your assignment but the formatting will be the same.

The file you will be imputing to your program is a grade sheet. You will be taking in the grade sheet of 5 students with an unknown amount of grades (the number of possible grades is from 2 to 8). The number of grades will be provided at the top of the file. Your job is to take in the grades average them for each of the 5 students and output the grades in order from greatest to least.

Example input:

Grades 4

Bob 90 89 72 89

Tim 65 60 78 88

Kelly 99 67 75 81

Wesley 44 76 58 67

Anel 100 91 90 96

Example output:

Anel 94.25

Bob 85

Kelly 80.5

Tim 72.75

Wesley 61.25

Final submission should be your .cpp file only

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// gradesData.txt

Grades 4
Bob 90 89 72 89
Tim 65 60 78 88
Kelly 99 67 75 81
Wesley 44 76 58 67
Anel 100 91 90 96

____________________

#include <iostream>
#include <fstream>
#include <iomanip>

using namespace std;
//Function declarations.
void sort(string names[],double avgs[],int size);
void display(string names[],double avgs[],int size);
int main()

{
   //Declaring constant
   const int SIZE=5;
   //Declaring variables
   string str;
   int grades;
ifstream dataIn;
double avg=0,grade,sum=0;
//Declaring arrays
string names[SIZE];
double avgs[SIZE];
  
//Opening the input file
dataIn.open("gradesData.txt");
if(dataIn.fail())
{
   cout<<"** File Not Found **"<<endl;
   return 1;
       }
       else
       {
           //Read the data from the file(i.e no of grades of each student)
           dataIn>>str>>grades;
          
           /* Reading the data from the fiel and
           * populate the values in the array
           */
       for(int i=0;i<SIZE;i++)
       {
           dataIn>>str;
           names[i]=str;
           for(int j=0;j<grades;j++)
           {
               dataIn>>grade;
               sum+=grade;
               }
               avg=sum/grades;
               avgs[i]=avg;
               sum=0;
           }
           //calling the functions
           sort(names,avgs,SIZE);
           display(names,avgs,SIZE);
       }

return 0;

}
//This function will sort the averages in decending order
void sort(string names[],double avgs[],int size)
{
       //This Logic will Sort the Array of elements in Decending order
   double temp;
   string tempName;
   for (int i = 0; i < size; i++)
{
for (int j = i + 1; j < size; j++)
{
if (avgs[i] < avgs[j])
{
temp = avgs[i];
avgs[i] = avgs[j];
avgs[j] = temp;
  
tempName = names[i];
names[i] = names[j];
names[j] = tempName;
  
}
}
}
}
//This function will diasplay the names and averages after sorting
void display(string names[],double avgs[],int size)
{
   for(int i=0;i<size;i++)
   {
       cout<<names[i]<<"\t"<<avgs[i]<<endl;
   }
}

___________________________

// Output;

_______________Could you plz rate me well.Thank You


Related Solutions

Here we will be taking data in as a file instead of from the command line...
Here we will be taking data in as a file instead of from the command line (no cin). Note that the sample file provided here is not the file that I will use to grade your assignment but the formatting will be the same. File input is very similar to how data comes in from the user through cin (using the same operators) but we will need to setup the stream ourselves. First we need to include <fstream> at the...
Here we will be taking data in as a file instead of from the command line...
Here we will be taking data in as a file instead of from the command line (no cin). Note that the sample file provided here is not the file that I will use to grade your assignment but the formatting will be the same. File input is very similar to how data comes in from the user through cin (using the same operators) but we will need to setup the stream ourselves. First we need to include <fstream> at the...
. The file contains information about baseball players in a fictitious league. Here is a sample...
. The file contains information about baseball players in a fictitious league. Here is a sample of the data: Janet Littleton,6,7,14 Frank Edbrooke,17,9,31 Robert Hovery,25,1,18 Thomas Bingham,21,8,2 Stephen Bruce,7,9,23 For each player it shows: Her name, How many doubles she hit, How many triples she hit, How many home runs she hit [End of Line] For example, Janet Littleton hit 6 doubles, 7 triples and 14 home runs. Frank Edbrooke hit 17 doubles, 9 triples and 31 home runs. Your...
We want to estimate the proportion of unemployed people in Quebec. Taking a sample of 350...
We want to estimate the proportion of unemployed people in Quebec. Taking a sample of 350 adults randomly selected from the workforce, we find that 42 people are out of work. Build a 99% confidence interval for the true proportion of unemployed in Quebec.
choose a note-taking strategy and answer the following questions: What note-taking strategy did you select? Why?...
choose a note-taking strategy and answer the following questions: What note-taking strategy did you select? Why? How will the note-taking strategy you selected help you study? How does this compare to other note-taking strategies you looked at this week? Your Discussion should be at least 250 words in length, but not more than 750 words. Use APA citations and references for the textbook and any other sources used. Be sure to attach your notes on the chapter to your discussion...
The file provided contains data on the carpace lengths, in mm, of two samples of Midland...
The file provided contains data on the carpace lengths, in mm, of two samples of Midland Painted Turtles (Chrysemys picta marginata). One sample is for female turtles and the other sample is for male turtles. (i) Use the sample data to carry out a hypothesis test to test the claim that the variability of the carpace lengths is different for female Midland Painted Turtles compared to male Midland Painted Turtles. Use a significance level of 0.05. Your answer should include:...
Using the data provided in the excel file, show all of your work for the following...
Using the data provided in the excel file, show all of your work for the following calculations: a.) mean temperature of unmixed reagents (oC) b.) δελταT from graph (oC) c.) q absorbed by reaction mixture (J) d.) q absorbed by calorimeter, stirrer, and thermometer (J) e.) q total absorbed (J) f.) q total released (J) g.) calculation to show limiting reagent h.) deltaH neutralization for the reaction (kJ/mole of acid) A student reacted 100.0 mL of 0.9800 M HCl with...
1)     The provided sched.cpp file is missing a few lines to read in some of the data....
1)     The provided sched.cpp file is missing a few lines to read in some of the data. The comments in the code describe how there is yet another stream library that works like iostream and fstream, but for processing string’s. Fill in the necessary statements and uncomment the indicated cout statements to get the output below for the attached “sched.txt” file: CS100 Section 1 has 17 open seats It is held on MW from 8:00A to 9:15A in SC-S146 It is...
Using the provided m1_mbox.txt, write a program that reads the data from the file, locates the...
Using the provided m1_mbox.txt, write a program that reads the data from the file, locates the lines containing sender information (those lines begin with 'From:'), and extracts just the email address of the sender of each message. It should then duplicate the set of email addresses for senders, and write the duplicated list to a file called senders.txt, so that each sender appears in the output file only once. In addition, your program should print to the screen the following...
Here are some data for a regular Treasury Note observed on January 15, 2020.  The accrued interest...
Here are some data for a regular Treasury Note observed on January 15, 2020.  The accrued interest on this note as of January 15, 2020 is approximately Maturity Coupon Bid Asked Chg Asked yield 2/15/2021 7.875 106.2120 106.2160 0.0020 1.618 6.56 7.22 0.66 3.28 1.31 Continuing the previous question, if you sold this note to a dealer on January 15, 2020, then the amount you would receive (ignoring commissions) would be approximately 106.212 plus accrued interest 106.216 plus accrued interest 106.216...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT