Description The purpose of this challenge is to use overloaded functions with de
ID: 3591699 • Letter: D
Question
Description
The purpose of this challenge is to use overloaded functions with default parameters. This functions simulates an insurance application calculator for life and auto.
Requirements
Write a function double calc_premium(int gender, int age, bool smoker = false). This function is used to calculate life insurance monthly premium. This function sets a base premium of 50.00 in the function. If the gender is 1 (male), add 25. If the gender is 2, don’t change the premium. If the age < 25, add 50. If the age > 55, add 30. If smoker is true, double the premium after factoring in gender and age.
Write an overloaded function double calc_premium(int year). This function (note the same name) is used to calculate auto insurance. Set a base rate of $33 in the function. If year < 2010, set premium to 1.25% of the base rate. If the year >= 2010, set premium to 0.95 of the base rate.
In main, call the above functions in various ways making sure to test all variations.
Sample main()
Explanation / Answer
#include<iostream>
using namespace std;
double calc_premium(int gender, int age, bool smoker = false){
double bp = 50;
double p = 0;
p = bp;
if (gender == 1)
p = p + 25;
if (age < 25)
p = p + 50;
if (age > 55)
p = p + 30;
if (smoker)
p = 2 * p;
return p;
}
double calc_premium(int year){
double bp = 33;
double p;
if (year < 2010)
p = .0125 * 33;
if (year >= 2010)
p = 0.95 * 33;
return p;
}
int main(){
cout << calc_premium(1, 18) << endl; // male, 18 yrs , nonsmoker
cout << calc_premium(1, 30) << endl; // male, 30 yrs, nonsmoker
cout << calc_premium(1, 58) << endl; // male, 58 yrs, nonsmoker
cout << calc_premium(2, 18) << endl; // female, 18 yrs, nonsmoker
cout << calc_premium(2, 30) << endl; // female, 30 yrs, nonsmoker
cout << calc_premium(2, 58) << endl; // female, 58 yrs, nonsmoker
cout << calc_premium(1, 18, true) << endl; // male, 18 yrs, smoker
cout << calc_premium(1, 30, true) << endl; // male, 30 yrs, smoker
cout << calc_premium(1, 58, true) << endl; // male, 58 yrs, smoker
cout << calc_premium(2, 18, true) << endl; // female, 18 yrs, smoker
cout << calc_premium(2, 30, true) << endl; // female, 30 yrs, smoker
cout << calc_premium(2, 58, true) << endl; // female, 58 yrs, smoker
// AUTO INSURANCE
cout << calc_premium(2000) << endl; // OLD car
cout << calc_premium(2015) << endl; // NEW car
return 0;
}