SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Procedural Abstraction And Functions That Return A Value
Exercise:
Programming Projects
Question:8 | ISBN:9780321531346 | Edition: 7

Question

8. Write a program that computes the annual after-tax cost of a new house

for the first year of ownership. The cost is computed as the annual mortgage

cost minus the tax savings. The input should be the price of the

house and the down payment. The annual mortgage cost can be estimated

as 3% of the initial loan balance credited towCHAPTER 4 / Procedural Abstraction and Functions That Return a Value

loan principal plus 6% of the initial loan balance in interest. The initial

loan balance is the price minus the down payment. Assume a 35% marginal

tax rate and assume that interest payments are tax deductible. So, the

tax savings is 35% of the interest payment. Your program should use at

least two function definitions. Your program should allow the user to

repeat this calculation as often as the user wishesard paying off the

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

PROGRAM CODE:

//Header section
#include <iostream>
using namespace std;
// Function to calculate the annual mortgage cost
double calculateMortgageCost(double price, double downPayment) {
    double loanBalance = price - downPayment;
    double interestPayment = 0.06 * loanBalance;
    double mortgageCost = 0.03 * loanBalance + interestPayment;
    return mortgageCost;
}

// Function to calculate the tax savings
double calculateTaxSavings(double interestPayment) {
    double taxRate = 0.35;
    double taxSavings = taxRate * interestPayment;
    return taxSavings;
}

//main program
int main() 
{
    //Declare varaibles
    char choice;
    
    do 
    {
        double price, downPayment;
        
        // Get input from the user
        cout << "Enter the price of the house: $";
        cin >> price;
        cout << "Enter the down payment: $";
        cin >> downPayment;
        
        // Calculate the annual mortgage cost
        double mortgageCost = calculateMortgageCost(price, downPayment);
        
        // Calculate the tax savings
        double taxSavings = calculateTaxSavings(0.06 * (price - downPayment));
        
        // Calculate the annual after-tax cost
        double afterTaxCost = mortgageCost - taxSavings;
        
        // Output the result
        cout << "Annual after-tax cost: $" << afterTaxCost << endl;
        
        // Ask the user if they want to repeat the calculation
        cout << "Do you want to calculate again? (Y/N): ";
        cin >> choice;
        
    } while (choice == 'Y' || choice == 'y');
    
    return 0;
}

OUTPUT OF THE PROGRAM CODE:

Enter the price of the house: $3500000
Enter the down payment: $500000
Annual after-tax cost: $207000
Do you want to calculate again? (Y/N): y
Enter the price of the house: $2500000
Enter the down payment: $50000
Annual after-tax cost: $169050
Do you want to calculate again? (Y/N): n

 

0 0

Discussions

Post the discussion to improve the above solution.