Answer to Question #250305 in C++ for mohan

Question #250305

Define a class called CUSTOMER with the following members name_of_the_customer type_of_loan number_of_months principal_amount EMI There are 3 member functions. First one to set the value for name_of_the_customer, number_of_months, principal_amount and type_of_loan. Second one to print all the data members. Third function to calculate EMI and it is calculated as follows. If type_of_loan is “bike” then monthly interest rate is 9.2%. If type_of_loan is “Home” then monthly interest rate is 7.35%.


1
Expert's answer
2021-10-12T07:39:58-0400
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;


class Customer{
private:
	string name_of_the_customer;
	string type_of_loan;
	int number_of_months;
	double principal_amount;


public:
	// 3 member functions
	//First one to set the value for name_of_the_customer, number_of_months, principal_amount and type_of_loan. 


	void setValues(string name_of_the_customer,int number_of_months,double principal_amount,string type_of_loan){
		this->name_of_the_customer=name_of_the_customer;
		this->number_of_months=number_of_months;
		this->principal_amount=principal_amount;
		this->type_of_loan=type_of_loan;
	}
	// Second one to print all the data members. 
	void printAllDataMembers(){
		cout<<"The name of the customer: "<<name_of_the_customer<<"\n";
		cout<<"The type of loan: "<<type_of_loan<<"\n";
		cout<<"The number of months: "<<number_of_months<<"\n";
		cout<<"The principal amount: "<<principal_amount<<"\n";
	}
	//Third function to calculate EMI and it is calculated as follows. 
	void calculateEMI(){
		double monthlyInterestRate=0;
		//If type_of_loan is 'bike' then monthly interest rate is 9.2%. 
		if(type_of_loan=="bike"){
			 monthlyInterestRate=0.092;
			 double emi;
			 emi = (principal_amount * monthlyInterestRate * pow(1 + monthlyInterestRate, number_of_months)) / (pow(1 + monthlyInterestRate, number_of_months) - 1);
			 cout<<"\nEMI = "<<emi<<"\n\n";
		}
		//If type_of_loan is 'Home' then monthly interest rate is 7.35%.
		else if(type_of_loan=="home"){
			monthlyInterestRate=0.0735;
		}else{
			cout<<"\nWrong the type of loan.\n\n";
		}
	}
};




int main()
{
	string name_of_the_customer;
	string type_of_loan;
	int number_of_months;
	double principal_amount;


	cout<<"Enter the name of the customer: ";
	getline(cin,name_of_the_customer);
	cout<<"Enter type of loan (bike,home): ";
	getline(cin,type_of_loan);
	printf("Enter the number of months: ");
	cin>>number_of_months;
	printf("Enter the principal amount: ");
	cin>>principal_amount;


	Customer customer;
	customer.setValues(name_of_the_customer,number_of_months,principal_amount,type_of_loan);
	customer.printAllDataMembers();
	customer.calculateEMI();


	cin>>number_of_months;


	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS