Esempio n. 1
0
void Transaction::on_loanButton_clicked()
{
    Loan loan;
    loan.setPrimaryKey(getPrimaryKey());
    loan.exec();

    loadLCD(getPrimaryKey());
    return ;
}
Esempio n. 2
0
int main(){
	fstream fout;
	Loan account[5];
	Loan tmp;		
	double totalLoan;
	cout<<"Select"<<endl;
	cout<<"0.Exit"<<endl;
	cout<<"1.Write"<<endl;
	cout<<"2.Read"<<endl;
	char ch;
	cin>>ch;
	while (true)
	{
		switch (ch)
		{
		case '0':
			return 0;
			break;
		case '1': 
			srand( (unsigned)time(NULL));
			fout.open("Exercise12_6.dat",ios::out|ios::binary|ios::app);
			for(int i=0;i<5;i++){
				account[i]=Loan(rand()%10+1,rand()%10+1,rand()%100000+1);
				fout.write(reinterpret_cast<char *>(&account[i]),sizeof(Loan));
			}	
			fout.close();
			cout<<"finish!!"<<endl;
			break;
		case '2':
			totalLoan=0;
			fout.open("Exercise12_6.dat",ios::in|ios::binary);
			while(!fout.eof()){
				fout.read(reinterpret_cast<char *>(&tmp),sizeof(Loan));
				if (fout.eof())
				{
					break;
				}
				totalLoan+=tmp.getLoanAmount();
				cout<<tmp.getLoanAmount()<<endl;
			}
			cout<<endl<<endl<<totalLoan<<endl;
			fout.close();
			cout<<"finish!!"<<endl;
			break;
		default:
			cout<<"please Again!"<<endl;
			break;
		}
		cin>>ch;
	}
}
Esempio n. 3
0
double calTotalLoanFromFile(char* filename)
{
    fstream input;
    input.open(filename, ios::in | ios::binary);
    Loan tmp;
    double totalAmount = 0;

    while(!input.eof())
    {
        input.read(reinterpret_cast<char *>(&tmp),sizeof(Loan));
        totalAmount += tmp.getLoanAmount();
    }

    input.close();
    return totalAmount;
}
Esempio n. 4
0
int main() {
  // Effective April 1, 2013
  std::map<std::string, Loan> loans;
  float extra = 0.0f;

  loans["ford"]     = Loan(11352.00f, 0.00f,  500.00f);
  loans["ford_esp"] = Loan( 1369.60f, 0.00f,  105.35f);
  loans["mancini"]  = Loan( 2000.00f, 0.00f,  200.00f);
  loans["ucsc"]     = Loan(63609.87f, 0.068f, 750.00f);
  loans["crv"]      = Loan( 5054.00f, 0.030f, 107.47f);
  loans["calpoly"]  = Loan(13988.00f, 0.068f, 219.34f);
  loans["bauman"]   = Loan();
  loans["house"]    = Loan();
  Loan big_loan = Loan(10000000.0f, 0.0f, 0.0f);

  printf("    -- ");
  for(std::map<std::string, Loan>::iterator it = loans.begin(); it != loans.end(); ++it) {
    printf("%12s  ", it->first.c_str());
  }
  std::cout << std::endl;

	for(int month = 0; month < 180; ++month) {
    if(month == 12) {
      loans["bauman"] = Loan(10000.00f, 0.00f, 555.55f);
    }
    if(month == 24) {
      loans["house"] = Loan(500000.00f, 0.035f, 2500.00f);
    }

    extra += 120.00;
    printf("%03d -- ", month);
    Loan *extra_target = &big_loan;
    for(std::map<std::string, Loan>::iterator it = loans.begin(); it != loans.end(); ++it) {
      if(it->second.getBalance() > 0) {
        if(it->second.getBalance() < extra_target->getBalance()) {
          extra_target = &(it->second);
        }
      }
    }

	  for(std::map<std::string, Loan>::iterator it = loans.begin(); it != loans.end(); ++it) {
		  Loan *loan = &(it->second);
      loan->printBalance();

		  loan->addInterest(30);
      if(loan == extra_target) {
        extra = loan->makePayment(extra);
      } else {
        extra += loan->makePayment();
      }
	  }
    std::cout << std::endl;
	}

  for(std::map<std::string, Loan>::iterator it = loans.begin(); it != loans.end(); ++it) {
    printf("%12s -- \n", it->first.c_str());
    printf("             --  Total Paid:       %8.2f\n", it->second.getTotalPaid());
    printf("             --  Interest Accrued: %8.2f\n", it->second.getInterestAccrued());
    std::cout << std::endl;
  }

  return 0;
}