/* Summary: returns a string representation of the account object that allows the object to be persisted in a text file Pre: none Post: string representation (std::string) is returned */ std::string toString() { stringstream ss; ss << getAccountId() << ", "; ss << getCustomerId() << ", "; ss << getAccountName() << ", "; ss << getInterestRate() << ", "; ss << getBalance(); std::string str; getline(ss, str); return str; }
/* Main function of the program*/ int main () { /* Program Variables */ int costumerID; int creditScore; int yearsFinancing; float carCost; float deposit; float financed; float interestRate; float interest; float monthlyPayment; FILE* file_in; FILE* file_out; /* Open input.txt/output.txt files */ file_in = fopen("input.txt", "r"); file_out = fopen("output.txt", "w"); /* Checking if files opened succesfully */ if (file_in != NULL && file_out != NULL) { fscanf(file_in,"%d %d %f %f %d",&costumerID, &creditScore, &carCost, &deposit, &yearsFinancing); while(costumerID != 0) { financed = getFinanceAmt(carCost,deposit); interestRate = getInterestRate(creditScore); interest = getInterest(financed, interestRate); monthlyPayment = calculatePayment(interest, financed, yearsFinancing); fprintf(file_out,"%d %0.2f\n\n",costumerID, monthlyPayment); fscanf(file_in,"%d %d %f %f %d",&costumerID, &creditScore, &carCost, &deposit, &yearsFinancing); } fclose(file_in); fclose(file_out); } else { printf("The input.txt/output.txt could not be opened. Exitcode: 1\n"); return 1; } return 0; }
float computeInterest(float currentBal) { float currentRate = getInterestRate(); float newBal = currentBal*currentRate; return newBal; }