Advertisement
steamengines

PA 9

May 5th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 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. #include "genericCDB.h"
  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.  
  15.  string studentName = "Student Name          ";
  16.  string minimum = "Min    ";
  17.  string maximum = "Max    ";
  18.  string average = "Average    ";
  19.  string grade = "Grade";
  20.  
  21.  
  22. const int NUM_GRADES = 10;
  23.  
  24. void displayReportHeading(string fileName);
  25. void readStudentRecord(ifstream &fin, string &studentName, const int arrGrades[], const int NUM_GRADES);
  26. void displayStudentRecord(string &studentName, const int arrGrades[], const int NUM_GRADES);
  27.  
  28. int main()
  29. {
  30.     int grades[NUM_GRADES];
  31.     string studentName;
  32.     string fileName = "COSC 1336 001 S15.txt";
  33.     ifstream fin;               // Object to read data from input file.
  34.     ofstream fout;              // Object to write results to output file.
  35.  
  36.     fin.open(fileName);     // Attach the file stream to the physical file.
  37.  
  38.     if (fin.fail())             // Test for successful file opening.
  39.     {
  40.         cout << "\nError opening input file: " << fileName << ".\n";
  41.         fin.close();
  42.         system("pause");
  43.         return EXIT_FAILURE;    // Terminate program.
  44.     }
  45.    
  46.     displayReportHeading(fileName);
  47.     //readStudentRecord(fin, studentName, grades, NUM_GRADES);
  48.     displayStudentRecord(studentName, grades, NUM_GRADES);
  49.  
  50.     system("pause");
  51.     return 0;
  52. }
  53. // Displays the title line, column headings, and students records.
  54. void displayReportHeading(string fileName)
  55. {
  56.     string::size_type recordLineLength = studentName.length() + minimum.length() + maximum.length() + average.length() + grade.length();
  57.     string::size_type titleLength = 0;
  58.     string title = "Grade Report for " + fileName + " - March 2015";
  59.     string recordLine = studentName + minimum + maximum + average + grade;
  60.  
  61.    
  62.     cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
  63.         << title << endl;
  64.  
  65.     cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
  66.         << recordLine << endl;
  67.  
  68.     for (size_t i = 0; i < title.length(); i++)
  69.     {
  70.         cout << "-";
  71.     } cout << endl;
  72.  
  73.    
  74. }
  75.  
  76. // Reads and returns the student grade data from the input file.
  77. void readStudentRecord(ifstream &fin, string &studentName, const int *arrGrades[], const int NUM_GRADES)
  78. {
  79.     int position = 0;
  80.  
  81.     getline(fin, studentName, '\t');
  82.  
  83.     while (!fin.eof() && position < NUM_GRADES)
  84.     {
  85.         getline(fin, arrGrades[position]); //reading one character from file to array
  86.         position++;
  87.     }
  88.     arrGrades[position - 1] = '\0'; //placing character array terminating character
  89.    
  90.  
  91. }
  92.  
  93. // Displays each student's grade data.
  94. void displayStudentRecord(string &studentName, const int arrGrades[], const int NUM_GRADES)
  95. {
  96.     const int size = 5;
  97.     int test[size] = { 6, 5, 4, 3, 2 };
  98.     double average1 = 0.0;
  99.     /*arrGrades[NUM_GRADES];
  100.     int dog;
  101.  
  102.     dog = min(arrGrades, NUM_GRADES);*/
  103.    
  104.     average1 = average(test, size);
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement