Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************************************************************
- // Programmer: Codye Watson
- // Course: CS-1313
- // Program: 6
- // Date: 12/09/2011
- // Purpose:
- // Input:
- // Calculate:
- // Output:
- //***********************************************************************
- #include <iostream>
- #include <iomanip>
- #include <fstream> //Needed to use files
- using namespace std;
- // This function opens the file datafile.txt, reads a collection of student records, and keeps track of the
- // number of records in variable size.
- void read(string name[ ], float gpa[ ], int &size);
- // This function outputs each student name and GPA on a line.
- // The output will be aligned.
- void output(string name[ ], float gpa[ ], int size);
- // This function receives a list of GPAs, and the number of students.
- // It calculates and returns the average GPA.
- float average(float gpa[ ], int size);
- // This function receives student names and GPAs. It outputs each name, GPA, and the corresponding
- // letter grade on a line. The output will be aligned.
- void outputGrades(string name[], float gpa[], int size);
- // This function receives a list of GPAs and returns the array index of the highest GPA.
- int highest(float gpa[], int size);
- // This function receives a list of GPAs and returns the array index of the lowest GPA.
- int lowest(float gpa[], int size);
- // This function receives GPAs. It outputs the total number of .A.s, .B.s. .C.s, .D.s, and .F.s.
- // Frequency ranges: "A" = 4.0, "B" = 3.0 to 3.9, "C" = 2.0 to 2.9, "D", 1.0 to 1.9, "F" = 0.0 to 0.9.
- void outputStats(float gpa[ ], int size);
- int main(){
- const int MAXSIZE = 100;
- string name[MAXSIZE];
- float gpa[MAXSIZE];
- int size;
- read(name, gpa, size); // Call the read function to read the file and store in arrays
- output(name, gpa, size); // Call the output function to display the arrays and num of students
- //outputGrades(name, gpa, size); // Call the outputGrades function to calculate and output grades
- //cout << "Average GPA: " << average(gpa, size) << endl; // Output the average GPA
- //index = highest(gpa, size); // Call the highest function to find the index of the highest GPA
- //cout << "Highest GPA: " << name[index] << " " << gpa[index] << endl;
- return 0;
- }
- void read(string name[], float gpa[], int &size){
- int index = 0;
- //Open the data file
- ifstream inputFile;
- inputFile.open("datafile.txt");
- if (inputFile.fail()){
- cout << "Error: The file did not open." << endl;
- exit(1);
- }
- // read the entire data file and store in arrays name and gpa
- else {
- inputFile >> name[0];
- inputFile >> gpa[0];
- while(!inputFile.eof()){
- index++;
- inputFile >> name[index];
- inputFile >> gpa[index];
- }
- }
- exit(1);
- }
- void output(string name[], float gpa[], int size){
- for (int index = 0; index < size; index++){
- cout << name[index] << endl;
- }
- }
- float average(float gpa[], int size){
- }
- void outputGrades(string name[], float gpa[], int size){
- }
- int highest(float gpa[], int size){
- }
- int lowest(float gpa[], int size){
- }
Add Comment
Please, Sign In to add comment