cs Oct 23
Class Enumeration v/s Plain Enumeration
Month::jan
Month m = jan;
enum class Month, have to always use Month::jan , scope to use
enum Month
FINAL : given enum for Month do an operloading for the ++ operator.
lab5.cpp.pdf has a dependency on CreditCards.tex
after every operation , do a check_invariant..
credit_cards.cpp
#include "credit_cards.h"
#include <stdexcept>
bool CreditCards::invariant_violation()
{
bool r = (coomonlimit != 1000 and ..;
for (CreditCard* x: cards) if (x->limit != commonlimit) r = true; // r should be true ?
return r;
}
CreditCards::CreditCards(unsigned int limit)
:commonlimit(limit)
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
void CreditCards::add(CreditCard* c)
{
if(cards.find(c) ! = cards.end()) throw std::runtime_error("pre-condition violation");
cards.insert(c);
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
void CreditCards::card_delete(CreditCard* c)
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
void CreditCards::withdraw(CreditCard* c, unsigned int)
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
void CreditCards::deposit(CreditCard* c, unsigned int)
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
void CreditCards::withdrawAvail(CreditCard* c)
{
if (invariant_violation()) throw std::runtime_error("invariant violation");
}
CreditCars cc(3000); fail_("should be failed to create cc with invalid limit");
catch(runtime_error) {succeed_(); }
try(CreditCards cc(5000); succeed_(); }
catch(runtime_error) { fail_("should not have failed to create cc with valid limit");}
CreditCard c1(1000);
CreditCards cc(2000);
try(cc.add(&c1); fail_("illegal to have different limit");} catch(){succeed_();}
CreditCard c2(2000);
try(cc.add(&c2); succeed_();}fail_("illegal to have different limit");} catch(){succeed_();}

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home