I had an assignment in which I had to ‘convert’ an Excel spreadsheet into a working C++ program. We were given several options to have it done but I decided to go by the Inheritance method so here it is a link of the Excel file if you want to download it. https://docs.google.com/spreadsheets/d/1jAlVNFKvbsjX1OmHkKLWzKibTGV6Vb7T/edit#gid=111073767.

Obviously that file is only for the Tarrant County Colleges so be aware that it might not work in your end if you decide to follow the same example without having to change the costs of your school.

Here it is the whole program:

/*
* https://docs.google.com/spreadsheets/d/1jAlVNFKvbsjX1OmHkKLWzKibTGV6Vb7T/edit#gid=111073767
*/
#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;

class CollegeCost {
  protected:
    double costPerCreditHour;
    double bookCostPerClass;
    double roomBoardCostPerMonth;
    double foodCostPerMonth;
    double travelCostPerMonth;
  public:
    CollegeCost(double cpch, double bcpc, double rmcpm, double fcpm, double tcpm): costPerCreditHour(cpch), bookCostPerClass(bcpc), roomBoardCostPerMonth(rmcpm),foodCostPerMonth(fcpm), travelCostPerMonth(tcpm) {};
};

class Semester : public CollegeCost {
  private:
    double hoursPerClass;
    double monthsInOneSemester;
    double hoursFullTimeStudentTakes;
    double hoursPartTimeStudentTakes;
    double hoursHalfTimeStudentTakes;
    double hoursInDegree;
    double semestersInYear;
  public:
    Semester(double cpch, double bcpc, double rmcpm, double fcpm, double tcpm): CollegeCost(cpch, bcpc, rmcpm, fcpm, tcpm) {}
    // Hours
    void setHoursPerClass(double hpc) { hoursPerClass = hpc; }
    double getHoursPerClass() const { return hoursPerClass; }
    // Months
    void setMonthsInOneSemester(double mios) { monthsInOneSemester = mios; }
    double getMonthsInOneSemester() const { return monthsInOneSemester; }
    // hours full times student takes
    void setHoursFullTimeStudentTakes(double hftst) { hoursFullTimeStudentTakes = hftst; }
    double getHoursFullTimeStudentTakes() const { return hoursFullTimeStudentTakes; }
    // hours part time student takes
    void setHoursPartTimeStudentTakes(double hptst) { hoursPartTimeStudentTakes = hptst; }
    double getHoursPartTimeStudentTakes() const { return hoursPartTimeStudentTakes; }
    // hours half student takes
    void setHoursHalfTimeStudentTakes(double hhtst) { hoursHalfTimeStudentTakes = hhtst; }
    double getHoursHalfTimeStudentTakes() const { return hoursHalfTimeStudentTakes; }
    // hours in degree
    void setHoursInDegree(double hid) { hoursInDegree = hid; }
    double getHoursInDegree() const { return hoursInDegree; }
    // semester in a year
    void setSemestersInYear(double siy) { semestersInYear = siy; }
    double getSemestersInYear() const { return semestersInYear; }
    /*
    *  Sum and Full Time Student
    */
    double sum() {
      double result = (hoursFullTimeStudentTakes * costPerCreditHour)+(roomBoardCostPerMonth * monthsInOneSemester)+(travelCostPerMonth * monthsInOneSemester)+(foodCostPerMonth * monthsInOneSemester) + ((hoursFullTimeStudentTakes / hoursPerClass) * bookCostPerClass);
      return result;
    }
    void showFullTimeStudent() {
      cout << "Tuition        $" << ( hoursFullTimeStudentTakes * costPerCreditHour ) << endl;
      cout << "Room and Board $" << ( roomBoardCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Travel         $" << ( travelCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Food           $" << ( foodCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Books          $" << ( (hoursFullTimeStudentTakes / hoursPerClass) * bookCostPerClass ) << endl;
      cout << "Total per Semester for Full Time Student $" << sum() << endl;
    }
    /*
    *  Sum and Part Time Student
    */
    double sum2() {
      double result = (hoursPartTimeStudentTakes * costPerCreditHour)+(roomBoardCostPerMonth * monthsInOneSemester)+(travelCostPerMonth * monthsInOneSemester)+(foodCostPerMonth * monthsInOneSemester) + ((hoursPartTimeStudentTakes / hoursPerClass) * bookCostPerClass);
      return result;
    }
    void showPartTimeStudent() {
      cout << "Tuition        $" << ( hoursPartTimeStudentTakes * costPerCreditHour ) << endl;
      cout << "Room and Board $" << ( roomBoardCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Travel         $" << ( travelCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Food           $" << ( foodCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Books          $" << ( (hoursPartTimeStudentTakes / hoursPerClass) * bookCostPerClass ) << endl;
      cout << "Total per Semester for Part Time Student $" << sum2() << endl;      
    }
    /*
    *  Sum and Half Time Student
    */
    double sum3() {
      double result = (hoursHalfTimeStudentTakes * costPerCreditHour)+(roomBoardCostPerMonth * monthsInOneSemester)+(travelCostPerMonth * monthsInOneSemester)+(foodCostPerMonth * monthsInOneSemester) + ((hoursHalfTimeStudentTakes / hoursPerClass) * bookCostPerClass);
      return result;
    }
    void showHalfTimeStudent() {
      cout << "Tuition        $" << ( hoursHalfTimeStudentTakes * costPerCreditHour ) << endl;
      cout << "Room and Board $" << ( roomBoardCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Travel         $" << ( travelCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Food           $" << ( foodCostPerMonth * monthsInOneSemester ) << endl;
      cout << "Books          $" << ( (hoursHalfTimeStudentTakes / hoursPerClass) * bookCostPerClass ) << endl;
      cout << "Total per Semester for Half Time Student $" << sum3() << endl;      
    }
    
};

int main() {
  Semester s(59, 100, 400, 150, 90);
  s.setHoursPerClass(3);
  s.setMonthsInOneSemester(4);
  s.setHoursFullTimeStudentTakes(12);
  s.setHoursPartTimeStudentTakes(9);
  s.setHoursHalfTimeStudentTakes(6);
  s.setHoursInDegree(60);
  s.setSemestersInYear(3);

  double timeFullTimeSem = s.getHoursInDegree() / s.getHoursFullTimeStudentTakes();
  double timePartTimeSem = s.getHoursInDegree()/s.getHoursPartTimeStudentTakes();
  double timeHalfTimeSem = ( s.getHoursInDegree()/s.getHoursHalfTimeStudentTakes() );
  double costFullTime = s.sum() * timeFullTimeSem;
  double costPartTime = s.sum2() * timePartTimeSem ;
  double costHalfTime = s.sum3() * timeHalfTimeSem ;
  double timeFullTimeYears = timeFullTimeSem / s.getSemestersInYear();
  double timePartTimeYears = timePartTimeSem / s.getSemestersInYear();
  double timeHalfTimeYears = timeHalfTimeSem / s.getSemestersInYear();
  cout << "Time for 60 hours @ full time (sem)    $" << round( timeFullTimeSem ) << endl;
  cout << "Time for 60 hours @ part time (sem)    $" << round( timePartTimeSem ) << endl;
  cout << "Time for 60 hours @ half time (sem)    $" << round( timeHalfTimeSem ) << endl;
  cout << "Cost for 60 hours @ full time          $" << fixed << setprecision(2) << ( costFullTime ) << endl;
  cout << "Cost for 60 hours @ part time          $" << fixed << setprecision(2) << ( costPartTime ) << endl;
  cout << "Cost for 60 hours @ half time          $" << fixed << setprecision(2) << ( costHalfTime ) << endl;
  cout << "Time for 60 hours @ full time (Years)  $" << fixed << setprecision(2) << ( timeFullTimeYears ) << endl;
  cout << "Time for 60 hours @ part time (Years)  $" << fixed << setprecision(2) << ( timePartTimeYears ) << endl;
  cout << "Time for 60 hours @ half time (Years)  $" << fixed << setprecision(2) << ( timeHalfTimeYears ) << endl;
  cout << "Tuitions Cost for Semester @ Full Time $" << fixed << setprecision(2) << ( s.sum() ) << endl;
  cout << "Tuitions Cost for Semester @ Part Time $" << fixed << setprecision(2) << ( s.sum2() ) << endl;
  cout << "Tuitions Cost for Semester @ Half Time $" << fixed << setprecision(2) << ( s.sum3() ) << endl;

  return 0;
}

That is it. This is a complete working program to help you get an idea of how much you might end up paying if you decide to go into a 4 years university while working, being a half and/or part time student. In the end, I highly recommend you to be a full time student as you will pay less in the long run!.

The repl.it of this program can be accessed to at Unit5_Inheritance_KevinUriel_AzuaraFonseca. Bye-Bye 🙂

Leave a Reply

Back to Top