Pianomahnn
03-22-2002, 04:51 PM
Im a novice...so just say "you are on your way to greatness, pmahnn." :)
This program took this data (student ID, major, under/grad, course data)
<i>
U 111234 2907
515 160 3 A
515 168 4 A
540 155.01 3 B
420 101.01 3 C
515 254 3 A
348 120 2 B
540 100 1 A
U 332345 105
550 130 4 D
550 135 3 C
360 155.02 3 W
515 168 4 B
447 101 2 B
G 553456 2900
515 275 4 B
515 375.05 3 A
515 378.05 3 C
515 432 3 B
515 460 3 C
515 353.05 3 A
515 467 3 B
515 485 3 B
515 485 3 A
E
</i>
And turns it into this:
<i>
STUDENT MAJOR U/G GPA GRADE HOURS GPA STATUS
ID CODE HOURS POINTS EARNED
EARNED
--------------------------------------------------------------------------------
111234 2907 U 3 12 3 4.00 Good
332345 105 U 4 4 4 1.00 Probabtion
553456 2900 G 4 12 4 3.00 Good
Number of students in good standing: 2
Number of students on probation: 1
Number of undergraduates: 2
Number of graduates: 1
</i>
/***********************************************************************************
* PROGRAMMER: Chris Tinnon
*
* DATE: March 26, 2002
*
* FILE NAME: program2.cpp
*
* This program processes student course data from a file and produces a report
* showing current student grade point averages. The report will be printed to the
* screen and in an output file.
*
* INPUT FILES: a:students.txt
*
* OUTPUT FILES: a:gpa.txt
*
* MODULES USED IN PROGRAM:
* header: Outputs the header to the screen and output file
* read: Reads student data from the input file. Sends data to calculate
* Outputs student gpa data to the screen and output file.
* calculate: Calculates the student gpa data and sends it to module read.
*
* COURSE: ACS 168
* INSTRUCTOR: Sally Scott
* SECTION: 13
***********************************************************************************/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <cstring>
using namespace std;
void header(istream& in, ostream& out);
void read(istream& in, ostream& out);
void calculate(istream& in, ostream& out, int& hours, char& grade, int& gpa_hours, int& gp_earned,
int& hours_earned, double& gpa);
void main()
{
ifstream in;
ofstream out;
in.open("a:students.txt"); //opens input file
out.open("a:gpa.txt"); //opens output file
header(in, out); //calls header function
read(in, out); //calls read function
in.close(); //closes input file
out.close(); //closes output file
}
/********************************************************************************
* This writes the headings to the screen and output file
*
* Preconditions: The files are open, but nothing has been read or written
*
* Postconditions: The files have been written to, and the screen also
********************************************************************************/
void header(istream& in, ostream& out)
{
out.setf(ios::left); //Set justification for output file
out << setw(10) << "STUDENT" << setw(10) << "MAJOR" << setw(10) << "U/G" << setw(10) << "GPA" << setw(10) <<
"GRADE" << setw(10) << "HOURS" << setw(10) << "GPA" << setw(10) << "STATUS" << endl;
out << setw(10) << "ID" << setw(10) << "CODE" << setw(10) << " " << setw(10) << "HOURS" << setw(10) <<
"POINTS" << setw(10) << "EARNED" << setw(10) << " " << setw(10) << " " << endl;
out << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << "EARNED"
<< endl;
out << "--------------------------------------------------------------------------------" << endl;
cout.setf(ios::left); //set justification for screen output
cout << setw(10) << "STUDENT" << setw(10) << "MAJOR" << setw(10) << "U/G" << setw(10) << "GPA" << setw(10) <<
"GRADE" << setw(10) << "HOURS" << setw(10) << "GPA" << setw(10) << "STATUS" << endl;
cout << setw(10) << "ID" << setw(10) << "CODE" << setw(10) << " " << setw(10) << "HOURS" << setw(10) <<
"POINTS" << setw(10) << "EARNED" << setw(10) << " " << setw(10) << " " << endl;
cout << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << "EARNED"
<< endl;
cout << "--------------------------------------------------------------------------------" << endl;
}
/************************************************************************************
* This functions reads from the input file and passes data to the function calculate
* to be processed. The data is then passed back from calculate to be printed to
* the screen and to the output file.
*
* Preconditions: There are headings on the screen and in the output file.
*
* Postconditions: The gpa values have been calculated and all have been printed to
* the screen and output file.
************************************************************************************/
void read(istream& in, ostream& out)
{
//Variable Declarations
char input;
char grad, grade;
int id, major, dept, hours, grad_count = 0, undergrad_count = 0, gpa_hours = 0, gp_earned = 0,
hours_earned = 0;
int good = 0, prob = 0;
double course, gpa;
//Sets output file precision
out.precision(2);
out.setf(ios::fixed);
out.setf(ios::showpoint);
//Sets screen outpuf precision
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
do //Begin loop for reading and processing data to and from files and screen
{
in.get(input);
if((input == 'U') || (input == 'G'))
{
if(hours_earned != 0)
{
out << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
cout << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
if(((grad == 'G') && (gpa >= 3.0)) || ((grad == 'U') && (gpa >= 2.0)))
{
out << setw(10) << "Good" << endl;
cout << setw(10) << "Good" << endl;
good++;
}
else
{
out << setw(10) << "Probabtion" << endl;
cout << setw(10) << "Probabtion" << endl;
prob++;
}
gpa_hours = 0;
gp_earned = 0;
hours_earned = 0;
} //end if statement
in.putback(input);
in >> grad >> id >> major;
out << setw(10) << id << setw(10) << major << setw(10) << grad;
cout << setw(10) << id << setw(10) << major << setw(10) << grad;
if(grad == 'U')
{
undergrad_count++;
}
if(grad == 'G')
{
grad_count++;
}
} //end if statement
if((input != 'U') && (input != 'G') && (input != 'E'))
{
in.putback(input);
in >> dept >> course >> hours >> grade;
//Calls Caldulate function
calculate(in, out, hours, grade, gpa_hours, gp_earned, hours_earned, gpa);
do
{
in.get(input);
} while(input != '\n'); //Gets to next line
} //end if statement
if(input == 'E')
{
break;
}
}while(! in.eof()); //end do while statement
if(hours_earned != 0) //Needed for last line processing
{
out << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
cout << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
if(((grad == 'G') && (gpa >= 3.0)) || ((grad == 'U') && (gpa >= 2.0)))
{
out << setw(10) << "Good" << endl;
cout << setw(10) << "Good" << endl;
good++;
}
else
{
out << setw(10) << "Probabtion" << endl;
cout << setw(10) << "Probabtion" << endl;
prob++;
}
//resets data
gpa_hours = 0;
gp_earned = 0;
hours_earned = 0;
} //end if statement
out << endl << endl;
out << setw(40) << "Number of students in good standing:" << setw(2) << good << endl;
out << setw(40) << "Number of students on probation:" << setw(2) << prob << endl;
out << setw(40) << "Number of undergraduates:" << setw(2) << undergrad_count << endl;
out << setw(40) << "Number of graduates:" << setw(2) << grad_count << endl << endl << endl;
cout << endl << endl;
cout << setw(40) << "Number of students in good standing:" << setw(2) << good << endl;
cout << setw(40) << "Number of students on probation:" << setw(2) << prob << endl;
cout << setw(40) << "Number of undergraduates:" << setw(2) << undergrad_count << endl;
cout << setw(40) << "Number of graduates:" << setw(2) << grad_count << endl << endl << endl;
}
/*************************************************************************************
* This function receieves data from read and calculates the gpa values.
*
* Preconditions: There is data to be processed from read.
*
* Postconditions: GPA data has been calculated.
*************************************************************************************/
void calculate(istream& in, ostream& out, int& hours, char& grade, int& gpa_hours, int& gp_earned,
int& hours_earned, double& gpa)
{
if((grade == 'A') || (grade == 'B') || (grade == 'C') || (grade == 'D'))
{
hours_earned += hours;
}
gpa_hours += hours;
if(grade == 'A')
{
gp_earned += (4 * hours);
}
if(grade == 'B')
{
gp_earned += (3 * hours);
}
if(grade == 'C')
{
gp_earned += (2 * hours);
}
if(grade == 'D')
{
gp_earned += (1 * hours);
}
gpa = double(gp_earned) / double(gpa_hours);
}
This program took this data (student ID, major, under/grad, course data)
<i>
U 111234 2907
515 160 3 A
515 168 4 A
540 155.01 3 B
420 101.01 3 C
515 254 3 A
348 120 2 B
540 100 1 A
U 332345 105
550 130 4 D
550 135 3 C
360 155.02 3 W
515 168 4 B
447 101 2 B
G 553456 2900
515 275 4 B
515 375.05 3 A
515 378.05 3 C
515 432 3 B
515 460 3 C
515 353.05 3 A
515 467 3 B
515 485 3 B
515 485 3 A
E
</i>
And turns it into this:
<i>
STUDENT MAJOR U/G GPA GRADE HOURS GPA STATUS
ID CODE HOURS POINTS EARNED
EARNED
--------------------------------------------------------------------------------
111234 2907 U 3 12 3 4.00 Good
332345 105 U 4 4 4 1.00 Probabtion
553456 2900 G 4 12 4 3.00 Good
Number of students in good standing: 2
Number of students on probation: 1
Number of undergraduates: 2
Number of graduates: 1
</i>
/***********************************************************************************
* PROGRAMMER: Chris Tinnon
*
* DATE: March 26, 2002
*
* FILE NAME: program2.cpp
*
* This program processes student course data from a file and produces a report
* showing current student grade point averages. The report will be printed to the
* screen and in an output file.
*
* INPUT FILES: a:students.txt
*
* OUTPUT FILES: a:gpa.txt
*
* MODULES USED IN PROGRAM:
* header: Outputs the header to the screen and output file
* read: Reads student data from the input file. Sends data to calculate
* Outputs student gpa data to the screen and output file.
* calculate: Calculates the student gpa data and sends it to module read.
*
* COURSE: ACS 168
* INSTRUCTOR: Sally Scott
* SECTION: 13
***********************************************************************************/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cctype>
#include <cstdlib>
#include <cstring>
using namespace std;
void header(istream& in, ostream& out);
void read(istream& in, ostream& out);
void calculate(istream& in, ostream& out, int& hours, char& grade, int& gpa_hours, int& gp_earned,
int& hours_earned, double& gpa);
void main()
{
ifstream in;
ofstream out;
in.open("a:students.txt"); //opens input file
out.open("a:gpa.txt"); //opens output file
header(in, out); //calls header function
read(in, out); //calls read function
in.close(); //closes input file
out.close(); //closes output file
}
/********************************************************************************
* This writes the headings to the screen and output file
*
* Preconditions: The files are open, but nothing has been read or written
*
* Postconditions: The files have been written to, and the screen also
********************************************************************************/
void header(istream& in, ostream& out)
{
out.setf(ios::left); //Set justification for output file
out << setw(10) << "STUDENT" << setw(10) << "MAJOR" << setw(10) << "U/G" << setw(10) << "GPA" << setw(10) <<
"GRADE" << setw(10) << "HOURS" << setw(10) << "GPA" << setw(10) << "STATUS" << endl;
out << setw(10) << "ID" << setw(10) << "CODE" << setw(10) << " " << setw(10) << "HOURS" << setw(10) <<
"POINTS" << setw(10) << "EARNED" << setw(10) << " " << setw(10) << " " << endl;
out << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << "EARNED"
<< endl;
out << "--------------------------------------------------------------------------------" << endl;
cout.setf(ios::left); //set justification for screen output
cout << setw(10) << "STUDENT" << setw(10) << "MAJOR" << setw(10) << "U/G" << setw(10) << "GPA" << setw(10) <<
"GRADE" << setw(10) << "HOURS" << setw(10) << "GPA" << setw(10) << "STATUS" << endl;
cout << setw(10) << "ID" << setw(10) << "CODE" << setw(10) << " " << setw(10) << "HOURS" << setw(10) <<
"POINTS" << setw(10) << "EARNED" << setw(10) << " " << setw(10) << " " << endl;
cout << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << " " << setw(10) << "EARNED"
<< endl;
cout << "--------------------------------------------------------------------------------" << endl;
}
/************************************************************************************
* This functions reads from the input file and passes data to the function calculate
* to be processed. The data is then passed back from calculate to be printed to
* the screen and to the output file.
*
* Preconditions: There are headings on the screen and in the output file.
*
* Postconditions: The gpa values have been calculated and all have been printed to
* the screen and output file.
************************************************************************************/
void read(istream& in, ostream& out)
{
//Variable Declarations
char input;
char grad, grade;
int id, major, dept, hours, grad_count = 0, undergrad_count = 0, gpa_hours = 0, gp_earned = 0,
hours_earned = 0;
int good = 0, prob = 0;
double course, gpa;
//Sets output file precision
out.precision(2);
out.setf(ios::fixed);
out.setf(ios::showpoint);
//Sets screen outpuf precision
cout.precision(2);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
do //Begin loop for reading and processing data to and from files and screen
{
in.get(input);
if((input == 'U') || (input == 'G'))
{
if(hours_earned != 0)
{
out << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
cout << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
if(((grad == 'G') && (gpa >= 3.0)) || ((grad == 'U') && (gpa >= 2.0)))
{
out << setw(10) << "Good" << endl;
cout << setw(10) << "Good" << endl;
good++;
}
else
{
out << setw(10) << "Probabtion" << endl;
cout << setw(10) << "Probabtion" << endl;
prob++;
}
gpa_hours = 0;
gp_earned = 0;
hours_earned = 0;
} //end if statement
in.putback(input);
in >> grad >> id >> major;
out << setw(10) << id << setw(10) << major << setw(10) << grad;
cout << setw(10) << id << setw(10) << major << setw(10) << grad;
if(grad == 'U')
{
undergrad_count++;
}
if(grad == 'G')
{
grad_count++;
}
} //end if statement
if((input != 'U') && (input != 'G') && (input != 'E'))
{
in.putback(input);
in >> dept >> course >> hours >> grade;
//Calls Caldulate function
calculate(in, out, hours, grade, gpa_hours, gp_earned, hours_earned, gpa);
do
{
in.get(input);
} while(input != '\n'); //Gets to next line
} //end if statement
if(input == 'E')
{
break;
}
}while(! in.eof()); //end do while statement
if(hours_earned != 0) //Needed for last line processing
{
out << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
cout << setw(10) << gpa_hours << setw(10) << gp_earned << setw(10) << hours_earned <<
setw(10) << gpa;
if(((grad == 'G') && (gpa >= 3.0)) || ((grad == 'U') && (gpa >= 2.0)))
{
out << setw(10) << "Good" << endl;
cout << setw(10) << "Good" << endl;
good++;
}
else
{
out << setw(10) << "Probabtion" << endl;
cout << setw(10) << "Probabtion" << endl;
prob++;
}
//resets data
gpa_hours = 0;
gp_earned = 0;
hours_earned = 0;
} //end if statement
out << endl << endl;
out << setw(40) << "Number of students in good standing:" << setw(2) << good << endl;
out << setw(40) << "Number of students on probation:" << setw(2) << prob << endl;
out << setw(40) << "Number of undergraduates:" << setw(2) << undergrad_count << endl;
out << setw(40) << "Number of graduates:" << setw(2) << grad_count << endl << endl << endl;
cout << endl << endl;
cout << setw(40) << "Number of students in good standing:" << setw(2) << good << endl;
cout << setw(40) << "Number of students on probation:" << setw(2) << prob << endl;
cout << setw(40) << "Number of undergraduates:" << setw(2) << undergrad_count << endl;
cout << setw(40) << "Number of graduates:" << setw(2) << grad_count << endl << endl << endl;
}
/*************************************************************************************
* This function receieves data from read and calculates the gpa values.
*
* Preconditions: There is data to be processed from read.
*
* Postconditions: GPA data has been calculated.
*************************************************************************************/
void calculate(istream& in, ostream& out, int& hours, char& grade, int& gpa_hours, int& gp_earned,
int& hours_earned, double& gpa)
{
if((grade == 'A') || (grade == 'B') || (grade == 'C') || (grade == 'D'))
{
hours_earned += hours;
}
gpa_hours += hours;
if(grade == 'A')
{
gp_earned += (4 * hours);
}
if(grade == 'B')
{
gp_earned += (3 * hours);
}
if(grade == 'C')
{
gp_earned += (2 * hours);
}
if(grade == 'D')
{
gp_earned += (1 * hours);
}
gpa = double(gp_earned) / double(gpa_hours);
}