Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
Check Mark
Step 1

C++ Language

Python is slower than C++ because C++ is statically typed, which speeds up code compilation. Python employs the interpreter, which slows down compilation, and it supports dynamic typing, which makes it slower than C++.

Knowledge Booster
Background pattern image
Computer Engineering
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY