/*************************************************************
  File: Main.cpp
  Name: CDR B. A. Osborn
  Lab 4 part 1
  Date: 1 February 2006
  Description: Compute weighted GPA from console input
 ************************************************************/
#include <iostream>
using namespace std;
 
int main()
{
        double gpa;
        int total_points, total_hours, hours;
        char grade;
 
        total_hours = 0;
        total_points = 0;
 
        cout << "Input letter grade and hours (or Q to quit): ";
        cin >> grade;
 
        while ((grade != 'Q') && (grade !='q'))
        {
               cin >> hours;
 
               if (grade == 'A' || grade == 'a')
               {
                       total_hours += hours;
                       total_points += (hours * 4);
               }
               else if (grade == 'B' || grade == 'b')
               {
                       total_hours += hours;
                       total_points += (hours * 3);
               }
               else if (grade == 'C' || grade == 'c')
               {
                       total_hours += hours;
                       total_points += (hours * 2);
               }
               else if (grade == 'D' || grade == 'd')
               {
                       total_hours += hours;
                       total_points += (hours * 1);
               }
               else if (grade == 'F' || grade == 'f')
               {
                       total_hours += hours;
                       total_points += (hours * 0);
               }
 
               cout << "Input letter grade and hours (or Q to quit): ";
               cin >> grade;
        }
 
               gpa = double(total_points)/double(total_hours);
 
               cout << "GPA = " << gpa << endl;
 
        return 0;
}
 
 
 
/*************************************************************
  File: Main.cpp
  Name: CDR B. A. Osborn
  Lab 4 part 2
  Date: 1 February 2006
  Description: Compute weighted GPA from grades read
               from a file.  The user enters the file name.
 ************************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
int main()
{
        double gpa;
        int total_points, total_hours, hours;
        char grade;
        string file_name;
 
        total_hours = 0;
        total_points = 0;
 
        cout << "Enter file name: ";
        cin >> file_name;
 
        ifstream grades_in(file_name.c_str());
 
 
        if (!grades_in) 
        {
               cout << "Error! File <" << file_name << "> not found!" << endl;
        }
        else
        {
               while (grades_in >> grade >> hours)
               {
                       if (grade == 'A' || grade == 'a')
                       {
                               total_hours += hours;
                               total_points += (hours * 4);
                       }
                       else if (grade == 'B' || grade == 'b')
                       {
                               total_hours += hours;
                               total_points += (hours * 3);
                       }
                       else if (grade == 'C' || grade == 'c')
                       {
                               total_hours += hours;
                               total_points += (hours * 2);
                       }
                       else if (grade == 'D' || grade == 'd')
                       {
                               total_hours += hours;
                               total_points += (hours * 1);
                       }
                       else if (grade == 'F' || grade == 'f')
                       {
                               total_hours += hours;
                               total_points += (hours * 0);
                       }
 
               }
        
               gpa = double(total_points)/double(total_hours);
               cout << "GPA = " << gpa << endl;
 
        }
 
 
        return 0;
}

 

 

 
/*************************************************************
  File: Main.cpp
  Name: CDR B. A. Osborn
  Lab 4 part 3
  Date: 1 February 2006
  Description: Compute weighted GPA from grades read
               from a file.  The user enters the file name.
                          Output the grades and GPA to a file in 
                          HTML format.  The user enters the output
                          file name as well.
 ************************************************************/
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
int main()
{
        double gpa;
        int total_points, total_hours, hours;
        char grade;
        string input_file, output_file;
 
        total_hours = 0;
        total_points = 0;
 
        cout << "Enter input file name: ";
        cin >> input_file;
 
        ifstream grades_in(input_file.c_str());
 
        cout << "Enter output file name: ";
        cin >> output_file;
 
        ofstream gpa_out(output_file.c_str());
 
        if (!grades_in) 
        {
               cout << "Error! File <" << input_file << "> not found!" << endl;
        }
        else
        {
               gpa_out << "<html><body><table border = \"2\">" << endl;
               gpa_out << "<tr><td>" << "Grade" << "</td><td>" << "Hours" << "</td></tr>" << endl; 
 
               while (grades_in >> grade >> hours)
               {
                       if (grade == 'A' || grade == 'a')
                       {
                               total_hours += hours;
                               total_points += (hours * 4);
                       }
                       else if (grade == 'B' || grade == 'b')
                       {
                               total_hours += hours;
                               total_points += (hours * 3);
                       }
                       else if (grade == 'C' || grade == 'c')
                       {
                               total_hours += hours;
                               total_points += (hours * 2);
                       }
                       else if (grade == 'D' || grade == 'd')
                       {
                               total_hours += hours;
                               total_points += (hours * 1);
                       }
                       else if (grade == 'F' || grade == 'f')
                       {
                               total_hours += hours;
                               total_points += (hours * 0);
                       }
 
                       if (grade >= 97) grade = grade - 32;
 
                       gpa_out << "<tr><td>" << grade << "</td><td>" << hours << "</td></tr>" << endl;
 
               }
        
               gpa = double(total_points)/double(total_hours);
               gpa_out << "<tr><td>" << "GPA" << "</td><td>" << gpa << "</td></tr>" << endl; 
               gpa_out << "</table></body></html>" << endl;
 
        }
 
 
        return 0;
}

 


syntax highlighted by Code2HTML, v. 0.9.1