Thursday, December 4, 2014

cs Oct 9, 2014 lab



/*{\clearpage
  This tests
}*/

  c4.withdraw(1000); test_(c4.getbalance() == -1000);
  c4.withdraw(4000);test_(c4.getbalance() == -5000);
  try {c4.withdraw(10); fail_("should not have withdrawn 10");}
   catch (const char*) {succeed_();}
  test_(c4.getBalance() == -5000);

// withdraw avail and deposit
int amt = c4.withdrawAvail();
 cerr << " amt :" << amt << "limit:" << limit << "balance: "<<c4.getBalance() << std::endl;
test_(amt == c4.limit + c4.getBalance());
test_(c4.getBalance() == -c4.limit);
c4.deposit(2000);   //expect balance = -3000
test_(c4.getBalance() == 3000);
amt = c4.withdrawAvail(); // amt should be  be -2000


credit_card.cpp

void CreditCard::withdraw(unsigned int a)
{
   balance -= a;

  if (check_invariant == false )
     balance += a;
}
void CreditCard::deposit(unsigned int){
  balance += amt;
}
int CreditCard::withdrawAvail(){
 { temp =balance;
  balance = -limit;
return (int) limit + temp;
}



getbalance
  return balance;
}


\includepdf[pages=-]{credit_card.cpp.pdf}

tce-load -wio ImageMagick

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home