1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
//Project six Skeleton
// this program prompts the user to enter a student name, number of hours
// number of cummulitive hours, quality points, cummulitive quality points
// and all current courses enrolled in.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
using namespace std;
int I, j, coursenum, hours, total_hours, qp, total_qp;
float gpa;
char name[20], course[8], dummy;
string Name;
string CurH;
string CumH;
string QP;
string TotalH;
string CQP;
string TotalQP;
// setup the output data file
ofstream report("outfile.dat");
// send data to output file called outfile.dat
report << " CMPS 273-01 Program Three, Summer 2016 " << endl;
report << " ------------------------------------" << endl;
report << endl;
report << " "<< endl;
report << "=========================================================================" << endl;
// setup the for loop
for (I=1; I <= 2; I++)
{ // begin loop
// prompt user for a student name
cout << "Enter Student Name: "; // prompt user for a student name
cin.get(name,20);
cin.get(dummy); // read the extra new line into the dummy field
cout << endl;
cout << "Enter number of hours: "; // prompt user for current hours
cin >> hours;
cout << endl;
cout << "Enter number of cummulitive hours: "; // prompt user for cummulitive hours
cin >> total_hours;
cout << endl;
cout << "Enter number of quality points this semester: ";// prompt user for current quality points
cin >> qp;
cout << endl;
cout << "Enter number of total quality points: "; // prompt user for total quality points
cin >> total_qp;
cout << endl;
cout << "Enter # of courses enrolled for this semester: "; // acquire # of courses for this semester per student
cin >> coursenum;
cout << endl;
// use c++ commands to include decimal point in output
// add semester hours to cummulitive hours
CurH + CumH = TotalH;
// add cummulitive quality points to quality points
CQP + QP = TotalQP;
// caculate GPA
gpa = total_qp / total_hours;
// use c++ commands to include decimal point in output
report.setf(ios::fixed, ios::floatfield);
report.setf(ios::showpoint);
// output the data to the data file
report << I << " " << name << setw(j) << " " << " " << total_qp
<< " " << gpa << endl;
// acquire # of courses for this semester per student
for (j = 1; j <= coursenum; j++) // set up inner loop
{ // begin inner loop
cout << "Enter course name: ";
cin >> course;
cout << endl;
} // end inner loop
report << left << setw(50) << course[j] << endl;
report << "-------------------------------------------------------------------------" << endl;
cin.get(dummy);
} // end outter loop
report << endl;
report.close(); // close data file
return 0;
} // end program
|