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
The design product will be a description of the most efficient thermodynamic cycle required to supply 750 MW of electric power.
vlabodo [156]

Answer:

I'm 50s I be sliding on them crabs and we be posting 5 inta a Snapple

3 0
2 years ago
Consider a circular grill whose diameter is 0.3 m. The bottom of the grill is covered with hot coal bricks at 961 K, while the w
soldi70 [24.7K]

Answer:

Step 1

Given

Diameter of circular grill,   D = 0.3m

Distance between the coal bricks and the steaks,  L = 0.2m

Temperatures of the hot coal bricks,  T₁ = 950k

Temperatures of the steaks, T₂ = 5°c

Explanation:

See attached images for steps 2, 3, 4 and 5

4 0
3 years ago
A reversible compression of 1 mol of an ideal gas in a piston/cylinder device results in a pressure increase from 1 bar to P2 an
Mashutka [201]

Answer:

attached below

Explanation:

6 0
3 years ago
Technician A says that TSBs are typically updates to the owner's manual. Technician B says that TSBs are generally
vichka [17]

Answer:

Technician A says that TSBs are typically updates to the owner's manual. Technician B says that TSBs are generally

updated information on model changes that do not affect the technician. Who is correct? the answer is c

4 0
3 years ago
Creating vacancies in ceramics. Consider doping ZrO2 with small concentrations of Nb205. The valence of Nb is 5. Assume that Nb
Murljashka [212]

Answer:

Creating vacancies in ceramics. Consider doping ZrO₂ with small concentrations of Nb205. The valence of Nb is 5. Assume that Nb ions sit in Zr ion sites

a. A substitutional defect will be produced.

b. With this dopping, the Nb increases electron band conduction and decreases oxygen anion conduction in ZrO₂.

Explanation:

(a) The defect produced by dopping a little concentration of Nb₂O5 with Nb in the +5 charge state is known as a substitutional defect.

(b) With this dopping, the Nb increases electron band conduction and decreases oxygen anion conduction in ZrO₂.

Moreover, if oxygen vacancies are rate-limiting defect, the corrosion of ZrO₂ decreases and if electrons are rate-limiting then the corrosion of ZrO₂ is accelerated.

7 0
4 years ago
Other questions:
  • When choosing building-construction materials, what kinds of materials would you choose, all other things being equal?
    6·1 answer
  • Nearly__________ of all serious occupational injuries and illnesses stem from overexertion of repetitive motion.a. 1/2b. 1/4c. A
    10·1 answer
  • The elastic settlement of an isolated single pile under a working load similar to that of piles in the group it represents, is p
    8·1 answer
  • How do we define energy efficiency
    9·2 answers
  • What is the output of a system with the transfer function s/(s + 3)^2 and subject to a unit step input at time t = 0?
    5·1 answer
  • BlockPy: #43.1) Dictionaries vs. Tuples Create a dictionary to store the dimensions for a box. Then, create a tuple to store the
    9·1 answer
  • Technicians are normally paid in all of the following methods except:
    8·2 answers
  • Responding to the campaign of 4 classes, 7A, 7B, 7C, 7D contributed the amount of support proportional to the numbers 8,6;7;5 kn
    5·1 answer
  • What plane is this? and when was it made?
    11·1 answer
  • if you were to create your own watershed using materials from your house, what materials would you need, and why would you need
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!