Question: In C++ modify this code to validate the input (not allow any negative numbers), and further format the output the user sees (make it fancy!!)

In C++ modify this code to validate the input (not allow any negative numbers), and further format the output the user sees (make it fancy!!)In C++ modify this code to validate the input (not allow anynegative numbers), and further format the output the user sees (make it

Copied code:

#include #include #include using namespace std;

class Loan { public : Loan(); //default constructor void setLoanAmount (double); void setInterestRate(double); void setNumberofYears(double); double getMonthlyPayment(); double getTotalAmount(); private: double loanAmount, interestRate, numberOfYears; }; Loan::Loan () { setLoanAmount(0); setInterestRate(0); setNumberofYears (0); }// end default constructor

void Loan::setLoanAmount (double myLoanAmount) { loanAmount = myLoanAmount; }// end function set LoanAmount void Loan::setInterestRate(double myInterestRate) { interestRate = myInterestRate/100; }// end function set Interest Rate void Loan::setNumberofYears(double myNumberOfYears) { numberOfYears = myNumberOfYears; }// end function set Number of Years double Loan::getMonthlyPayment() { double term = pow(( 1 + ( interestRate / 12)), (12 * numberOfYears)); double payment = (loanAmount * (interestRate / 12) * term) / (term - 1); return payment; } // end function getMonthlyPayment double Loan::getTotalAmount() { return ( 12 * numberOfYears * getMonthlyPayment() ); }// end function get Total Amount

int main() { // declare a variable/object of type Loan Loan myLoan; // declare other variables of the program char choice; double loan, rate, year; do { // prompt and read the input from the user cout > loan; cout > rate; cout > year; // modify the values of the object myLoan.setLoanAmount(loan); myLoan.setInterestRate(rate); myLoan.setNumberofYears(year); // print the result to the user cout > choice; } while ( tolower( choice ) != 'n' ); // end do-while return 0; };

#include #include 8 #include 9 using namespace std; 11 class Loan public: 13 14 Loan //default constructor void setLoanAmount (double); void setInterestRate (double); void setNumberofYears (double) 17 19 double getMonthlyPayment); double getTotalAmount); private: double loanAmount, interestRate, numberOfYears; 24 25 26 27 Loan: Loan) 28 setLoanAmount (0); setInterestRate (0); setNumberofYears (0) end default constructor 31 32 34 void Loan::setLoanAmount double myLoanAmount) 35 loanAmount myLoanAmount; // end function set LoanAmount 36 void Loan: :setInterestRate (double myInterestRate) 37 interestRatemyInterestRate/100; // end function set Interest Rate 38 void Loan::setNumberofYears (double myNumberOfYears) 39numberOfYears myNumberOfYears; // end function set Number of Years 40 double Loan: :getMonthlyPayment) double termpow(1interestRate 12)), (12numberOfYears)); double payment(loanAmount (interestRate / 12) term) (term - 1); return payment: 45 end function getMonthlyPayment 6 double Loan::getTotalAmount) return 12numberOfYearsgetMonthlyPayment); // end function get Total Amount 49 int main() // declare a variable/object of type Loan Loan myLoan; // declare other variables of the program char choice; double loan, rate, year; 54 56 57 58 // prompt and read the input from the user cout >loan; cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!