#include #include #include using namespace std; void readStudData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany); float mean(int scores[], int count); void printTable(int score[], int ID[], int count); void printGrade(int oneScore, float average); // Only accept MAX_SIZE entries, this will be the size of our arrays const int MAX_SIZE = 10;

Systems Architecture
7th Edition
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Stephen D. Burd
Chapter3: Data Representation
Section: Chapter Questions
Problem 12VE
icon
Related questions
Question

CODE to Copy & Paste

 

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

void readStudData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany);
float mean(int scores[], int count);
void printTable(int score[], int ID[], int count);
void printGrade(int oneScore, float average);
// Only accept MAX_SIZE entries, this will be the size of our arrays
const int MAX_SIZE = 10;
int main()
{
  // variables. Need to create two int arrays: scores and ID.
  // Need to create one int: count. Need to create one bool: tooMany
  int scores[MAX_SIZE];
  int ID[MAX_SIZE];
  int count;
  bool tooMany;
  // Call readStudData to read data from the file that was opened above
  // inFile is the name of the file opened
  ifstream inFile;
  inFile.open("scores.txt");
  readStudData(inFile, scores, ID, count, tooMany);
  // Don't forget to close the file
  inFile.close();
  // If there are more than MAX_SIZE records in the file, then tooMany should be
  // set to true. We need to warn the user that not all the records were used
  if( tooMany ) cout << "\nWarning! Some data is missing\n";
  // Print the data
  printTable(scores, ID, count);
  cout << endl;
  system("Pause");
  return 0;
}

void readStudData(ifstream &rss, int scores[], int id[], int &count, bool &tooMany)
{
  // Set tooMany to false and count to 0
  tooMany = false;
  count = 0;
  
  while(!rss.eof())
  {
    if(count == MAX_SIZE) break;
    rss >> id[count] >> scores[count];
    count++;
  }
  // Determine if we have too many records in the file
  if( !rss.eof() && count == MAX_SIZE ) tooMany = true;
}

float mean(int scores[], int count)
{
  // Store the sum of the scores here
  int sum = 0;
  // Loop through and accumulate the scores from the array
  for(int i = 0; i < count; i++)
  {
    sum += scores[i];
  }
  // Return the average
  return (float)sum/count;
}

void printTable(int score[], int ID[], int count)
{
  // Need the average
  float average = mean(score, count);
  // Display the average to the user
  cout << "Average: " << average << endl;
  // Display the header for the table
  cout << "ID\t" << "Score\t" << "Grade" << endl;
  
  
  for(int i = 0; i < count; i++)
  {
    cout << ID[i] << '\t' << score[i] << '\t';
    printGrade(score[i], average);
  }
}

void printGrade(int oneScore, float average)
{
  
  if(oneScore < average + 10 && oneScore > average - 10) cout << "Satisfactory\n";
  else if(oneScore > average + 10) cout << "Outstanding\n"; 
  else cout << "Unsatisfactory\n"; 
}

 

TASK

Redo using a struct to store each student’s data and an array of structs to store the whole class. The struct should have data members for id, score, and grade.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning