0

ここで2つのクラスを使用してローンプログラムを作成しています。LoanOfficerクラスの「MortCalc」クラスからオブジェクトを宣言します。ローンオフィサークラスは、ユーザーがローンの資格があるかどうかを判断するためのもので、ユーザーはローンの元本、月収、および月額費用を入力します。次に、ローンオフィサークラスは計算を行い、ローンが1つのルールを使用して承認されたかどうかをユーザーに報告します。ルールは次のとおりです。ローンの毎月の支払い(私のMortCalcクラスから取得)と毎月の費用の合計が毎月の収入の50%を超える場合、ローンは承認されません。私が遭遇した問題は、これを計算することです。計算を「ルール」変数に格納しようとしましたが、常に100に等しいため、ローンを承認することはありません。明らかに私はここで何か間違ったことをしていますが、私は何を理解することができません。

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;

}
4

1 に答える 1