1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ValentinkaMS [17]
3 years ago
13

Write a program to sort the student’s names (ascending order), calculate students’ average test scores and letter grades (Use th

e 10 point grading scale). In addition, count the number of students receiving a particular letter grade. You may assume the following input file data :
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 48
Gupta 92 83 30 69 87
Muhammed 23 45 96 38 59
Clark 60 85 45 39 67
Patel 77 31 52 74 83
Abara 93 94 89 77 97
Abebe 79 85 28 93 82
Abioye 85 72 49 75 63
(40%) Use four arrays: a one-dimensional array to store the students’ names, a (parallel) two dimensional array to store the test scores, a one-dimensional array to store the student’s average test scores and a one-dimensional array to store the student’s letter grades.
(60%) Your program must contain at least the following functions :
A function to read and store data into two arrays,
A function to calculate the average test score and letter grade,
A function to sort all the arrays by student name, and
A function to output all the results (i.e. sorted list of students and their corresponding grades)
Have your program also output the count of the number of students receiving a particular letter grade.
NOTE : No non-constant global variables are to be used. You can name the arrays and functions anything you like. You can use the operator >= to sort the strings.
In C++
Engineering
1 answer:
xeze [42]3 years ago
7 0

Answer:

// testscores.txt

Johnson 85 83 77 91 76

Aniston 80 90 95 93 48

Cooper 78 81 11 90 48

Gupta 92 83 30 69 87

Muhammed 23 45 96 38 59

Clark 60 85 45 39 67

Patel 77 31 52 74 83

Abara 93 94 89 77 97

Abebe 79 85 28 93 82

Abioye 85 72 49 75 63

______________________

#include <fstream>

#include <iostream>

#include <iomanip>

using namespace std;

// function declarations

void readData(ifstream& dataIn, double** scores, string names[], int size);

void calculateGrade(double* avgs, char grades[], int size);

void outputResults(string names[], double** scores,double avgs[], char grades[], int size,int NUM_TESTS);

void calculateAverage(double **scores,double avgs[],int NUM_STUDENTS,int NUM_TESTS);    

void sortByName(string names[],double avgs[],char grades[],int NUM_STUDENTS);

void countStudents(string names[],char grades[],char gradeLetter,int NUM_STUDENTS);

int main()

{

  const int NUM_STUDENTS = 10;

const int NUM_TESTS = 5;

// Declaring variables

string name;

int score;

char ch;

// defines an input stream for the data file

ifstream dataIn;

// Defines an output stream for the data file

ofstream dataOut;

// setting the precision to two decimal places

std::cout << std::setprecision(2) << std::fixed;

// Opening the input file

dataIn.open("testscores.txt");

// checking whether the file name is valid or not

if (dataIn.fail())

{

cout << "** File Not Found **";

return 1;

}

else

{

 

// Creating 2-D array Dynamically

double** scores = new double*[NUM_STUDENTS];

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

scores[i] = new double[NUM_TESTS];

// Creating array dynamically

string* names = new string[NUM_STUDENTS];

char* grades = new char[NUM_STUDENTS];

double* avgs = new double[NUM_STUDENTS];

// Closing the intput file

dataIn.close();

// calling the functions

readData(dataIn, scores, names, NUM_STUDENTS);

 

calculateAverage(scores,avgs,NUM_STUDENTS,NUM_TESTS);    

     

 

calculateGrade(avgs, grades, NUM_STUDENTS);

 

sortByName(names,avgs,grades,NUM_STUDENTS);

outputResults(names, scores,avgs, grades, NUM_STUDENTS,NUM_TESTS);

cout<<"Enter Grade Letter :";

cin>>ch;

countStudents(names,grades,ch,NUM_STUDENTS);

 

}

return 0;

}

/* This function will read the data from

* the file and populate the values into arrays

*/

void readData(ifstream& dataIn, double** scores, string names[], int size)

{

// Opening the input file

dataIn.open("testscores.txt");

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

{

dataIn >> names[i];

for (int j = 0; j < 5; j++)

{

dataIn >> scores[i][j];

}

}

dataIn.close();

}

/* This function will find the average of

* each student and find the letter grade

*/

void calculateGrade(double* avgs, char grades[], int size)

{

 

char gradeLetter;

 

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

{

if (avgs[i]>=90 && avgs[i]<=100)

gradeLetter = 'A';

else if (avgs[i]>=80 && avgs[i]<=89.99)

gradeLetter = 'B';

else if (avgs[i]>=70 && avgs[i] <=79.99)

gradeLetter = 'C';

else if (avgs[i]>=60 && avgs[i] <=69.99)

gradeLetter = 'D';

else if (avgs[i]<=59.99)

gradeLetter = 'F';

grades[i] = gradeLetter;

}

}

// This function will display the report

void outputResults(string names[], double** scores,double avgs[], char grades[], int size,int NUM_TESTS)

{

cout << "Name\t\tTest1\tTest2\tTest3\tTest4\tTest5\tAverage\tGrade" << endl;

cout << "----\t\t-----\t-----\t-----\t-----\t-----\t-------\t-----" << endl;

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

{

cout <<setw(8)<<left<< names[i] << "\t";

for (int j = 0; j <NUM_TESTS; j++)

{

cout << scores[i][j] << "\t";

}

cout<<avgs[i]<<"\t"<<grades[i] << endl;

}

}

/* calculates the average test score per student

* and stores it as the last column of the test score array

*/

void calculateAverage(double **scores,double avgs[],int NUM_STUDENTS,int NUM_TESTS)

{

double average=0.0,tot=0,totAvg=0,overallAvg=0.0;

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

{

tot = 0;

for (int j = 0; j < NUM_TESTS; j++)

{

tot += scores[i][j];

}

average = tot / NUM_TESTS;

avgs[i]=average;

}

}

void sortByName(string names[],double avgs[],char grades[],int NUM_STUDENTS)

{

  string tempName;

  double tempAvg;

  char tempGrade;

  //This Logic will Sort the Array of elements in Ascending order

  int temp;

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

{

for (int j = i + 1; j < NUM_STUDENTS; j++)

{

if (names[i]>names[j])

{

tempName = names[i];

names[i] = names[j];

names[j] = tempName;

 

tempAvg = avgs[i];

avgs[i] = avgs[j];

avgs[j] = tempAvg;

 

tempGrade = grades[i];

grades[i] = grades[j];

grades[j] = tempGrade;

 

}

}

 

}

}

void countStudents(string names[],char grades[],char gradeLetter,int NUM_STUDENTS)

{

  int cnt=0;

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

  {

      if(grades[i]==gradeLetter)

      {

          cnt++;

      }

  }

  cout<<"No of Students Who got the grade letter '"<<gradeLetter<<"' is :"<<cnt<<endl;

}

You might be interested in
A college student volunteers with the elderly in a hospice program and discovers her clients complain of dry skin. She has an id
daser333 [38]

Answer:

D

Explanation: She hopes to be able to make this, however she hasn't yet...therefore she is thinking of a concept and it's development

3 0
3 years ago
Read 2 more answers
Proper ventilation is required when welding, so that you don't ____________.
galben [10]
I say the answers is A but if you mean ventilation in the area of the room then answer B
4 0
3 years ago
Read 2 more answers
PLEASE QUICK!!! what phrase describes an ad hominem fallacy?
Igoryamba

Answer:

personal attack

Explanation:

it is personal attack

5 0
3 years ago
3. In order to obtain your commercial driver's license (CDL) you must first:
Murljashka [212]
A and C is the answer to the question. Be 15 years old & get a permit
8 0
3 years ago
The cantilevered W530 x 150 beam shown is subjected to a 9.8-kN force F applied by means of a welded plate at A. Determine the e
snow_lady [41]

The <em>equivalent force-couple system</em> at O is the force and couple experienced when at point O due to the applied force at point A

The <em>equivalent force couple</em> system at O due to force <em>F</em> are;

Force, F =  (<u>8.65·i - 4.6·j</u>) KN

Couple, M₀ ≈ <u>40.9 </u>k kN·m

The reason the above values are correct is as follows:

The known values for the <em>cantilever</em> are;

The <em>height </em>of the beam = 0.65 m

The <em>magnitude of </em>the applied <em>force</em>, F = 9.8 kN

The <em>length </em>of the beam = 4.9 m

The <em>angle </em>away from the vertical the force is applied = 26°

The required parameter:

The <em>equivalent force-couple system</em> at the centroid of the beam cross-section of the cantilever

Solution:

The <em>equivalent force-couple system</em> is the force-couple system that can replace the given force at centroid of the beam cross-section at the cantilever O ;

The <em>equivalent force</em> \overset \longrightarrow F = 9.8 kN × cos(28°)·i - 9.8 kN × sin(28°)·j

Which gives;

The <em>equivalent force</em> \overset \longrightarrow F ≈ (<u>8.65·i - 4.6·j</u>) KN

The <em>couple </em><em>acting </em>at point O due to the force <em>F</em> is given as follows;

The <em>clockwise moment</em> = <em>9.8 kN × cos(28°) × 4.9</em>

The <em>anticlockwise moment</em> = <em>9.8 kN × sin(28°) 0.65/2 </em>

The sum of the moments = Anticlockwise moment - Clockwise moments

∴ The <em>sum </em>of the moments, ∑M, gives the moment acting at point O as follows;

M₀ = <em>9.8 kN × sin(28°) 0.65/2 - 9.8 kN × cos(28°) × 4.9</em>  ≈ 40.9 kN·m

The couple acting at O, due to F,  M₀ ≈ <u>40.9 kN·m</u>

The equivalent force couple system acting at point O due the force, F, is as follows

F =  (8.65·i - 4.6·j) KN

M₀ ≈ <u>40.9 </u>k kN·m

Learn more about equivalent force systems here:

brainly.com/question/12209585

4 0
3 years ago
Other questions:
  • A solid circular rod that is 600 mm long and 20 mm in diameter is subjected to an axial force of P = 50 kN The elongation of the
    11·1 answer
  • Please help me with this question​
    8·1 answer
  • Talc and graphite are two of the lowest minerals on the hardness scale. They are also described by terms like greasy or soapy. B
    14·1 answer
  • A classroom that normally contains 40 people is to be air-conditioned with window air-conditioning units of 5 kW cooling capacit
    6·1 answer
  • 2. One of the many methods used for drying air is to cool the air below the dew point so that condensation or freezing of the mo
    12·1 answer
  • Crest is to high, as through is to
    12·2 answers
  • Please help me:<br> Use the Node analysis to find the power of all resistors
    9·1 answer
  • A bronze bushing 60 mm in outer diameter and 40 mm in inner diameter is to be pressed into a hollow steel cylinder of 120-mm out
    8·1 answer
  • 3. What is a caliber (relate it to rockets)
    14·1 answer
  • Which of the following is NOT one of the 3 technology bets we have made?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!