Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Christian Ballard
- // COSC 1336 - 001
- // March 25th 2015
- // This program will read user input and generate a grade report.
- #include "genericCDB.h"
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- /*Five global column widths*/
- string studentName = "Student Name ";
- string minimum = "Min ";
- string maximum = "Max ";
- string average = "Average ";
- string grade = "Grade";
- const int NUM_GRADES = 10;
- void displayReportHeading(string fileName);
- void readStudentRecord(ifstream &fin, string &studentName, const int arrGrades[], const int NUM_GRADES);
- void displayStudentRecord(string &studentName, const int arrGrades[], const int NUM_GRADES);
- int main()
- {
- int grades[NUM_GRADES];
- string studentName;
- string fileName = "COSC 1336 001 S15.txt";
- ifstream fin; // Object to read data from input file.
- ofstream fout; // Object to write results to output file.
- fin.open(fileName); // Attach the file stream to the physical file.
- if (fin.fail()) // Test for successful file opening.
- {
- cout << "\nError opening input file: " << fileName << ".\n";
- fin.close();
- system("pause");
- return EXIT_FAILURE; // Terminate program.
- }
- displayReportHeading(fileName);
- //readStudentRecord(fin, studentName, grades, NUM_GRADES);
- displayStudentRecord(studentName, grades, NUM_GRADES);
- system("pause");
- return 0;
- }
- // Displays the title line, column headings, and students records.
- void displayReportHeading(string fileName)
- {
- string::size_type recordLineLength = studentName.length() + minimum.length() + maximum.length() + average.length() + grade.length();
- string::size_type titleLength = 0;
- string title = "Grade Report for " + fileName + " - March 2015";
- string recordLine = studentName + minimum + maximum + average + grade;
- cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
- << title << endl;
- cout << right << setw((recordLineLength - titleLength) / 2 + titleLength)
- << recordLine << endl;
- for (size_t i = 0; i < title.length(); i++)
- {
- cout << "-";
- } cout << endl;
- }
- // Reads and returns the student grade data from the input file.
- void readStudentRecord(ifstream &fin, string &studentName, const int *arrGrades[], const int NUM_GRADES)
- {
- int position = 0;
- getline(fin, studentName, '\t');
- while (!fin.eof() && position < NUM_GRADES)
- {
- getline(fin, arrGrades[position]); //reading one character from file to array
- position++;
- }
- arrGrades[position - 1] = '\0'; //placing character array terminating character
- }
- // Displays each student's grade data.
- void displayStudentRecord(string &studentName, const int arrGrades[], const int NUM_GRADES)
- {
- const int size = 5;
- int test[size] = { 6, 5, 4, 3, 2 };
- double average1 = 0.0;
- /*arrGrades[NUM_GRADES];
- int dog;
- dog = min(arrGrades, NUM_GRADES);*/
- average1 = average(test, size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement