steamengines

PA 9 - Grade report using arrays

May 1st, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. // Christian Ballard
  2. // COSC 1336 - 001
  3. // March 25th 2015
  4. // This program will read user input and generate a grade report.
  5.  
  6.  
  7. #include <iostream>
  8. #include <fstream>
  9. #include <string>
  10. #include <iomanip>
  11. #include <ctime>
  12. using namespace std;
  13. // Five global column widths
  14.  string studentName = "Student Name          ";
  15.  string minimum = "Min    ";
  16.  string maximum = "Max    ";
  17.  string average = "Average    ";
  18.  string grade = "Grade";
  19.  
  20. const int NUM_GRADES = 10;
  21.  
  22. void displayReportHeading(string fileName);
  23. void readStudentRecord(ifstream &fin, string &studentName, const int arrGrades[], const int numGrades);
  24.  
  25.  
  26. int main()
  27. {
  28.     int grades[10];
  29.     string studentName;
  30.     string fileName = "COSC 1336 001 S15.txt";
  31.     ifstream fin;               // Object to read data from input file.
  32.     ofstream fout;              // Object to write results to output file.
  33.  
  34.     fin.open(fileName);     // Attach the file stream to the physical file.
  35.  
  36.     if (fin.fail())             // Test for successful file opening.
  37.     {
  38.         cout << "\nError opening input file: " << fileName << ".\n";
  39.         fin.close();
  40.         system("pause");
  41.         return EXIT_FAILURE;    // Terminate program.
  42.     }
  43.    
  44.     displayReportHeading(fileName);
  45.     readStudentRecord(fin, studentName, grades, NUM_GRADES);
  46.    
  47.     system("pause");
  48.     return 0;
  49. }
  50. // Displays the title line, column headings, and students records.
  51. void displayReportHeading(string fileName)
  52. {
  53.     string::size_type recordLineLength = studentName.length() + minimum.length() + maximum.length() + average.length() + grade.length();
  54.     string::size_type titleLength = 0;
  55.     string title = "Grade Report for " + fileName + " - March 2015";
  56.     string recordLine = studentName + minimum + maximum + average + grade;
  57.    
  58.     cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
  59.         << title << endl;
  60.  
  61.     cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
  62.         << recordLine << endl;
  63.  
  64.     for (int i = 0; i < title.length(); i++)
  65.     {
  66.         cout << "-";
  67.     } cout << endl;
  68.  
  69.    
  70. }
  71.  
  72. void readStudentRecord(ifstream &fin, string &studentName, const int arrGrades[], const int numGrades)
  73. {
  74.     int pos1, pos2;
  75.  
  76.  
  77.     getline(fin, studentName, '\t');
  78.  
  79.     for (int i = 0; i < 11; i++)
  80.     {
  81.         /*fin >> arrGrades[i];*/
  82.         //getline(fin, arrGrades[i], '\t');
  83.     }
  84.    
  85. }
Advertisement
Add Comment
Please, Sign In to add comment