LoanOfficer.h
class LoanOfficer
{
//private class variables
private:
MortCalc mc;
double intRate;
double monthlyIncome;
double term;
double monExpenses, principal;
double rule;
bool bLoanApprove, bOpen;
string userName, fileName,lenderName;
string loanOfficer, Welcome;
int counter;
void calculate();
LoanOfficer.cpp
LoanOfficer::LoanOfficer()
{
//initializing variables;
intRate = 4.1;
term = 30;
counter=1;
principal=0;
lenderName="John's Bank";
Welcome ="";
calculate();
}
void LoanOfficer::calculate()
{
rule = ((mc.GetMonPymt() + monExpenses) / monthlyIncome)* 100;
//i have a getter in my Mortcalc class which get's the monthly Payment.
}
bool LoanOfficer::isApproved()
{
if(rule>50)
{
bLoanApprove = true;
}
else{
bLoanApprove = false;
}
return bLoanApprove;
}
string LoanOfficer::getApproval()
{
if(bLoanApprove==true)
{
stringstream ss;
ss<<"\n\nLoan Approval Status: Yes"
<<"\nLoan amount: "
<<principal
<<"\nInterest Rate: "
<<intRate
<<"\nMonthly Payment: "
<<monPayment
<<"\nTotalLoan: "
<<mc.GetTotalLoan()
<<"\nTotal Interest"
<<mc.GetTotalInt()
<<"\n\nCongratulations We're looking to do business with you "
<<userName<<"!";
loanOfficer = ss.str();
}
else
{
stringstream ss;
ss<<"\n\nLoan Approval Status: No"
<<"\n\n Income vs Montly Payment and expenses does not meet "
<<"\n the 50% criteria net income that is necessary for this"
<<"\n institution to approve this loan";
loanOfficer = ss.str();
}
return loanOfficer;
}
void LoanOfficer::setPrincipal(double p)
{
mc.setPrin(p);
principal = p;
}
bool LoanOfficer::isOpen()
{
return bOpen;
}
void LoanOfficer::setMonInc(double mi)
{
monthlyIncome = mi;
}
void LoanOfficer::setExpenses(double ex)
{
monExpenses = ex;
}
void LoanOfficer::setAppName(string n)
{
userName = n;
}
string LoanOfficer::getFilename()
{
return fileName;
}
string LoanOfficer::getIntro()
{
stringstream ss;
ss<<"Hi Welcome to " <<lenderName
<<"\n Please enter your information below to see if you're approved for a loan."
<<"\nWe have a fixed interest rate of 4.1 and term of loan is 30 years."
<<"\nThe way we determine our loan approvals is by adding
loan payment and monthly expenses,"
<<"\nand that is greater than 50% of your monthly income the loan
is notapproved.\n\n";
Welcome = ss.str();
return Welcome;
}
void LoanOfficer::writeStatus()
{
stringstream ss;
ss<<userName<<"_"<<counter<<".txt";
fileName = ss.str();
ofstream receiptOut;
receiptOut.open(fileName.c_str());
//Writing report setting precision to 2 decimal places
//returning true if able to write receipt.
receiptOut<<" CUSTOMER LOAN INFORMATION "
<<month+1<<"/"<<day<<"/"<<year+1900<<"\n\n"
<<"********************************"
<<"\n Your Loan Information: "
<< "\n\n Principal: "<<"$" << fixed << setprecision (2)
<< principal
<< "\n\n Interest rate: "<< fixed << setprecision (2)
<< intRate << "%"
<< "\n\n Monthly Payment: "<<"$" << fixed << setprecision (2)
<< mc.GetMonPymt()
//here it obtains the correct monthly payment. I've checked through
//debugging.
<< "\n\n Total Interest paid: " <<"$"<< fixed << setprecision (2)
<< mc.GetTotalInt()
<<"\n\n Total Cost of the Loan: "<<"$" << fixed << setprecision (2)
<< mc.GetTotalLoan()
<<"\n*********************************"
<<"\n\n\nThank You for using my calculator. Have a Nice Day."
<<"\n****************************************************";
receiptOut.close();
counter++;
}
的main.cpp
double principal,monthlyIncome,monthlyExpenses;
string name, answer;
string fAnswer
//class object
LoanOfficer lo;
cout<<lo.getIntro();
cout<<"Please enter your name: ";
cin>>name;
//passing name to setName class method.
lo.setAppName(name);
//start of do loop
do
{
//presenting the user a menu accessed from otherFunctions.cpp
//checking which choice user entered with switch statements
cout<<"\nPlease enter the amount you want to borrow: ";
cin>>principal;
cin.ignore();
lo.setPrincipal(principal);
cout<<"\nPlease enter your monthly income after taxes: ";
cin>>monthlyIncome;
cin.ignore();
lo.setMonInc(monthlyIncome);
cout<<"\nPlease enter your monthly expenses: ";
cin>>monthlyExpenses;
cin.ignore();
lo.setExpenses(monthlyExpenses);
cout<<lo.getApproval();
cout<<"\n\n Would you like to write a file? Enter y for yes and n for no\n";
cin>>fAnswer;
if(fAnswer =="y")
{
lo.writeStatus();
cout<<"\n\nReport is located in: "
<<lo.getFilename();
}
else
{
cout<<"\n\nNo report printed out.";
}
//ask if user would like to do another
cout<<"\n\nWould you like to do another loan? Enter y for yes and n for no\n";
cin>>answer;
cout<<"\n";
}while(answer =="y");
//end do/while
//Goodbye message
{
cout <<"\n Thanks for calculating. Goodbye!\n\n"; //when loop is done
}
return 0;
}
答案 0 :(得分:0)
更改业务逻辑!
你的想法与你的实现相矛盾
让我们在你的问题中仔细看看这句话:
“规则是这样的:如果每月支付的贷款(从我的MortCalc类获得)和每月支出总额大于月收入的50%那么贷款就不会被批准。”并在您的代码中找到位置实现了这个业务逻辑,这里是:
bool LoanOfficer::isApproved()
{
if(rule>50)
{
bLoanApprove = true;
}
else{
bLoanApprove = false;
}
从代码提取中可以很容易地发现它与您的业务逻辑相矛盾 解决方案:
bool LoanOfficer::isApproved()
{
if(rule>50)
{
return false;
}
return true;