// fee.cpp // Member function definitions for class fee. // W.England #include #include #include "fee.h" #include "info.h" // Function declarations for helpers int inputInteger(); double inputDouble(); int getBin(); // Default constructor, includes default constructor // for parent class. fee::fee() : info(0, "NONE") { creditHrs = 0; resFlag = 0; depFlag = 0; holdFlag = 1; lateFee = 100.00; specialFee = 75.00; } // Member functions // Prints the relevant info. void fee::printFee() { cout << "\n----------\nSTATEMENT\n"; cout << "ID: " << IDNum; cout << "\nStudent: " << name; cout << "\nCredit Hours: " << creditHrs; cout << (resFlag == 1? "\nIs ":"\nIs not ") << "a resident"; cout << (depFlag == 1? "\nIs ":"\nIs not ") << "a dependent."; cout << (holdFlag == 1?"\nHas ":"\nDoes not have ") << "to pay delinquent amount of $" << lateFee; cout << "\nOwes $" << specialFee << " in special fees."; } // Reads in the facts, just the facts. void fee:: readFee() { cout << "\nStudent ID: "; IDNum = inputInteger(); cout << "\nStudent Name: "; cin.getline(name, 20); cout << "Credit Hours: "; creditHrs = inputInteger(); cout << "For the next three questions, 1 = yes, 0 = no.\n"; cout << "Resident? "; setResFlag(getBin()); cout << "Dependant? "; setDepFlag(getBin()); cout << "Is there a hold? "; setHoldFlag(getBin()); cout << "Amount Delinquent? (Default of $100) "; lateFee = inputDouble(); if (lateFee == 0) lateFee = 100; cout << "Additional Special Fees? (Defalut of $75) "; specialFee = inputDouble(); if (specialFee == 0) specialFee = 75; } // Calculates the total fee for the student. float fee::calcFees() { float total = 0; if (creditHrs < 12) { if (resFlag == 1) total = 75 * creditHrs; else total == 125 * creditHrs; } else { if (resFlag == 1) total += 560; else total += 1050; } if (depFlag == 1 && resFlag == 1) total *= .6; if (holdFlag == 1) total += lateFee; total += specialFee; return total; } // helper functions for good, clean numeric input. int inputInteger() { int num; char strnum[10], *rptr; cin.getline(strnum, 9); num = strtol(strnum, &rptr, 0); while ((*rptr) != '\0') { cout << "\n\tError. Please Reenter: "; cin.getline(strnum, 9); num = strtol(strnum, &rptr, 0); } return(num); } double inputDouble() { double num; char strnum[20], *rptr; cin.getline(strnum, 19); num = strtod(strnum, &rptr); while ((*rptr) != '\0') { cout << "\n\tError. Please Reenter: "; cin.getline(strnum, 9); num = strtod(strnum, &rptr); } return(num); } int getBin() { int temp = inputInteger(); while (temp < 0 || temp > 1) { cout << " Error. Please enter 1 or 0: "; temp = inputInteger(); } return temp; }