Create a program in Microsoft Visual Basic 2010 using C++ to simulate how a car
ID: 3539157 • Letter: C
Question
Create a program in Microsoft Visual Basic 2010 using C++ to simulate how a car insurance company determines your premium. The user provides the requested information and the program determines the insurance premium. The insurance premium is based on the user's gender, age, and number of traffic tickets he has received (numTix). The formula for determining the insurance premium is:
Gender
Age
Premium
Male
Under 21
1500 + 200 * numTix
Male
21 to 29
1200 + 100 * numTix
Male
Over 29
1000 + 100 * numTix
Female
Under 21
1200 + 200 * numTix
Female
21 and over
1000 + 100 * numTix
Gender
Age
Premium
Male
Under 21
1500 + 200 * numTix
Male
21 to 29
1200 + 100 * numTix
Male
Over 29
1000 + 100 * numTix
Female
Under 21
1200 + 200 * numTix
Female
21 and over
1000 + 100 * numTix
Explanation / Answer
#include using namespace std; int main() { char gender; // The customer's gender int age; // The customer's age int numTix; // Number of tickets the customer has had int premium; // Customer's insurance premium // Get information from the user // We will assume that the user always enters correct input // Get the user's gender cout > gender; // Get the user's age cout > age; // Get the number of tickets cout > numTix; // Use nested if statements to calculate the insurance premium // Outer if statement: Test the gender if ( gender == 'M' ) { // The inner series of if, else if, and else statements tests // the age and determines the premium. if ( age < 21 ) { premium = 1500 + 200 * numTix; } else if ( age >= 21 && age < 30 ) { premium = 1200 + 100 * numTix; } else // Only other option is 30 or older { premium = 1000 + 100 * numTix; } } // end if gender is male // Matching else for the outer if statement else // Use else because the only other option is gender == 'F' { // The inner series of if, else if, and else statements tests // the age and determines the premium. if ( age < 21 ) { premium = 1200 + 200 * numTix; } else // Only other option is 21 or older { premium = 1000 + 100 * numTix; } } // end gender else // Print the result coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.