void ribi::imcw::company::buy_click_card( person& customer, balance& account_euros, bank& the_bank, calendar& the_calendar ) { assert(customer.has_account(account_euros)); #ifndef NDEBUG const auto before = account_euros.get_value(); #endif the_bank.transfer( account_euros, money(click_card::cost_inc_vat_euros), m_balance_undistributed, the_calendar.get_today() ); #ifndef NDEBUG const auto after = account_euros.get_value(); assert(after < before); #endif //ClickCard will be valid the first day of the next month click_card c( the_calendar.get_today() //Purchase date ); customer.add_click_card(c); }
void person::sendMessage(person &friendName, string message) { bool found = false; if (&friendName == this) { cout << "You cannot send a message to yourself." << endl; return; } if (friends.size() == 0) { cout << "In order to send a message, you need to be friends with this person"; return; } for (int i = 0; i < friends.size(); i++ ) { if (friends[i]->name == friendName.name) { found = true; } } if(found) { string messageName = getDate() + "\n" + this->name + " " + message + "\n"; string firstName = friendName.getName(); text[firstName].push_back(messageName); friendName.receiveMessage(friendName, messageName); } else { cout << "In order to send a message, you need to be friends with this person"; } };
void ribi::imcw::company::buy_winner( person& customer, balance& account_euros, bank& the_bank, const boost::gregorian::date& the_day ) { #ifndef NDEBUG assert(customer.has_account(account_euros)); const auto before = account_euros.get_value(); #endif the_bank.transfer( account_euros, money(winner::price_vat_exempt_euros), m_balance_undistributed, the_day ); #ifndef NDEBUG const auto after = account_euros.get_value(); assert(after < before); #endif winner w(customer.get_name()); customer.add_winner(w); }
int main2(int argc, char**argv) { const person ira("Ira Pohl", 38, 1110111UL); ira.print(); ira.bday(); ira.print(); }
// remove the object from hash table void hashing::removeObject(person &personObj) { int index = Hash(personObj.getName()); item* delPtr; item* p1; item* p2; //case 0: bucket is empty if(HashTable[index] == NULL) cout << "Person not found in the hash table!\n"; //case 1: only 1 item contained in bucket and that item has matching name else if( HashTable[index]->hashedPerson == &personObj && HashTable[index]->next == 0) { HashTable[index] = NULL; cout << personObj.getName() << " item not found!\n"; } //case 2: match is located in the first item in the bucket but there are more items in the bucket else if(HashTable[index]->hashedPerson == &personObj) { delPtr = HashTable[index]; HashTable[index] = HashTable[index]->next; delete delPtr; delPtr = 0; cout << personObj.getName() << " is removed from the hash table!\n"; numberofentries--; } //case 3: bucket contains items but first item is not a match else { p1 = HashTable[index]->next; p2 = HashTable[index]; while(p1 != 0 && p1->hashedPerson != &personObj) { p2 = p1; p1 = p1->next; } //case 3.1 - no match if(p1 == 0) { cout << "Person not found in the hash table!\n"; } //case 3.2 - match is found else { delPtr = p1; p1 = p1->next; p2->next = p1; delete delPtr; delPtr = 0; cout << personObj.getName() << " is removed from the hash table!\n"; numberofentries--; } } }
void ribi::imcw::company::buy_winner_package( person& customer, const winner_package_name name, balance& account_euros, bank& the_bank, const boost::gregorian::date& the_day ) { if (customer.has_valid_click_card(the_day)) { std::stringstream s; s << __func__ << "Cannot buy a WinnerPackage when customer already has a ClickCard"; throw std::logic_error(s.str()); } assert(!is_customer(customer)); assert(customer.has_account(account_euros)); #ifndef NDEBUG const auto account_before = account_euros.get_value(); const auto n_customers_before = m_customers.size(); #endif // NDEBUG const winner_package p(name); const int n_winners = p.get_n_winners(); //Buy ClickCard { the_bank.transfer( account_euros, money(click_card::cost_inc_vat_euros), m_balance_undistributed, the_day ); click_card c(the_day); assert(!c.is_valid(the_day)); //Not valid yet customer.add_click_card(c); } assert(!customer.has_valid_click_card(the_day)); //Not valid yet //ClickCard makes person a customer m_customers.push_back(customer); //Winners for (int i=0; i!=n_winners; ++i) { buy_winner(customer,account_euros,the_bank,the_day); } assert(customer.get_n_winners() == n_winners); #ifndef NDEBUG const auto account_after = account_euros.get_value(); assert(account_after < account_before); const auto n_customers_after = m_customers.size(); assert(n_customers_after == n_customers_before + 1); #endif // NDEBUG }
bool operator<(person first_, person second_) { double _firstangle = first_.GetAngle(); double _secondangle = second_.GetAngle(); double _max = std::numeric_limits<double>::max(); if(_firstangle == _max && _secondangle == _max) { return first_.y_ > second_.y_; } if(_firstangle == _secondangle) return first_.x_ < second_.x_; return first_.GetAngle() < second_.GetAngle(); }
void test(person argp) { person testp; ; argp.print(); testp = argp; argp.print(); testp.print(); ; }
void marriage::display() { if(animate) { draw(); return; } glColor3f(color[0],color[1],color[2]); glBegin(GL_QUADS); glVertex2i(xLeft,y); glVertex2i(xLeft,y-WIDTH); glVertex2i(xRight,y-WIDTH); glVertex2i(xRight,y); glEnd(); if(side1->justPartner) side1->display(); if(side2->justPartner) side2->display(); if(children) displayChildren(); if(divorce && divorceDate/10000 <= currDate) { float length = WIDTH*3; float xMid = ((xRight-xLeft)/2) + xLeft; float yMid = y-(WIDTH/2); float xStart = (xMid+(length/2)) - (WIDTH/2); float yStart = yMid-(length/2); float yEnd = yMid+(length/2); float increment = 0.25; glColor3f(red[0],red[1],red[2]); for(float i=yStart;i<=yEnd;i+=increment) { glBegin(GL_QUADS); glVertex2i(xStart,yStart); glVertex2i(xStart+WIDTH,yStart); glVertex2i(xStart+WIDTH,yStart+increment); glVertex2i(xStart,yStart+increment); glEnd(); xStart-=increment; yStart+=increment; } } }
/**************************** addObject **********************************/ void hashing::addObject(person &personObj) { int tempCollision = 0; int index = Hash(personObj.getName()); cout << personObj.getName() << ": [" << index << "]\n" ; if(HashTable[index] == NULL) { HashTable[index] = new item; HashTable[index]->hashedPerson = &personObj; HashTable[index]->next =0; cout << personObj.getName() << " is added!\n"; } else { item* Ptr = new item; Ptr->hashedPerson = HashTable[index]->hashedPerson; Ptr->next = HashTable[index]->next; HashTable[index]->hashedPerson = &personObj; HashTable[index]->next = Ptr; cout << personObj.getName() << " is added!" << endl; numberofcollisions = numberofcollisions +1; cout << numberofcollisions << endl; } numberofentries++; //cout << "People in this index[" << Hash(personObj.getName()) << "] :" << hashing::NumberOfItemsInIndex(Hash(personObj.getName())) << endl; if(getLoadingfactor() > 0.75) { reHash(); } }
void person::deleteFriend(person &friendName) { // NOTE : check if already exists or if it is the same person if (&friendName == this) { cout << "You cannot delete yourself." << endl; return; } for (int i = 0; i < friends.size(); i++ ) { if (friends[i]->name == friendName.name) { friends.erase(friends.begin() + i); friendName.deleteFriend(*this); return ; } } cout << name << " and " << friendName.name << " are no longer friends." << endl; }
void ribi::imcw::company::add(person& customer) { if ( std::find( std::begin(m_customers), std::end(m_customers), customer ) != std::end(m_customers) ) { std::stringstream msg; msg << __func__ << ": cannot add existing customer (ID: " << customer.get_id() << ") again" ; throw std::logic_error(msg.str()); } m_customers.push_back(customer); }
bool operator <(const person &a, const person &b) { return a.bmi() > b.bmi(); }
void inputperson() { p1.input(); }
void spy_on(const person& p) { p.all_info(); }
void displayperson() { p1.display(); }
void bar(person &value) { //value = person("ola bar"); value.setName("ola bar"); }
void glueless(person p) { p.all_info(); }