Here is my class code and client code:
Code:
//Specification of the class "Applicant"
class Applicant
{
public:
float Calculate_BasicPremium (string, int, string);
//calculate the basic premium based on the applicant's gender, age, and coverage type
//Preconditions:
//valid data are provided, such as the applicant's first and last name, gender,
//age, type of coverage
//Postconditions:
//The basic premium is calculated based on the data provided
float Discount_Premium (float basic_premium, string club_member, string smoker);
//discount the basic premium based on the applicant's health status, and smoking
//status
//Preconditions:
//The Calculate_BasicPremium function has been executed, and a valid value has been
//returned, plus that the applicant's health club and smoking status are known
//Postconditions:
//Discount premium is calculated based on the information given above
float Adjust_Premium (float discount_premium, int zip_code);
//adjust the premium based on the zip code
//Preconditions:
//Both Calculate_BasicPremium and Discount_Premium functions have been executed, and
//the applicant's zip code is provided
//Postconditions:
//Applicant's final premium is calculated
Applicant(); //Constructor
private:
string first_name; //declare string variable first name
string last_name; //declare string variable last name
string gender; //declare string variable gender
int age; //declare int variable age
string type_coverage; //declare string variable type of coverage
string club_member; //declare string variable health club
//member
string smoker; //declare string variable smoker
int zip_code; //declare int variable zip code
float basic_premium; //declare float variable basic premium
float discount_premium; //declare float variable premium
float adjust_premium; //declare float variable adjust premium
float premium; //declare float variable variable premium
};
Here is the client code:
Code:
#include "applicant.h"
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
string first_name; //declare string variable first name
string last_name; //declare string variable last name
string gender; //declare string variable gender
int age; //declare int variable age
string type_coverage; //declare string variable type of coverage
string club_member; //declare string variable health club
//member
string smoker; //declare string variable smoker
int zip_code; //declare int variable zip code
float basic_premium; //declare float variable basic premium
float discount_premium; //declare float variable premium
float adjust_premium; //declare float variable adjust premium
float premium; //declare float variable variable premium
ifstream inFile; //declare file streams
ofstream outFile;
inFile.open("C:\\Windows\\C++\\project5\\proj5.in.txt"); //opens the input file
outFile.open("C:\\Windows\\C++\\project5\\proj5.out.txt"); //opens the output file
if (!inFile)
{
cout << "Input file failed!" << endl;
return 1; //terminates the program if input fails
}
inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
club_member >> smoker >> zip_code; //assigns input values from inFile
//prints subject line
outFile << "===================================" << endl;
outFile << " PREMIUM QUOTES " << endl;
outFile << "===================================" << endl;
outFile << "Name" << "\t" << "\t" << "Coverage Type" << "\t" << "Zip" <<
"\t" << "Premium" << endl << endl; //prints headline
while (inFile) //looping in capturing &
//processing input data
{
basic_premium = Applicant.Calculate_BasicPremium (gender, age, type_coverage);
discount_premium = Applicant.Discount_Premium (basic_premium, club_member, smoker);
premium = Applicant.Adjust_Premium (discount_premium, zip_code);
outFile << first_name << "\t" << last_name << "\t" << type_coverage
<< "\t" << "\t" << zip_code << "\t" << "$" << premium << endl;
//output premium to file output
inFile >> first_name >> last_name >> gender >> age >> type_coverage >>
club_member >> smoker >> zip_code; //assigns input values to inFile
}
if(!outFile)
{
cout << "Output file failed!" << endl;
return 1; //terminates the program if output fials
}
return 0;
}