Challenge 7

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

  1. 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.
  2. 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.
  3. In main, call the above functions in various ways making sure to test all variations.

Sample main()

int main()
{
  // LIFE INSURANCE
  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;
}

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0007

Print Requirements