Created
February 26, 2012 17:17
-
-
Save fayimora/1917826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Undefined symbols for architecture x86_64: | |
"CreditCard::CreditCard(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, double)", referenced from: | |
testCard() in ccbBJwte.o | |
"CreditCard::chargeIt(double)", referenced from: | |
testCard() in ccbBJwte.o | |
"operator<<(std::basic_ostream<char, std::char_traits<char> >&, CreditCard const&)", referenced from: | |
testCard() in ccbBJwte.o | |
"CreditCard::makePayment(double)", referenced from: | |
testCard() in ccbBJwte.o | |
ld: symbol(s) not found for architecture x86_64 | |
collect2: ld returned 1 exit status |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "CreditCard.h" | |
using namespace std; | |
CreditCard::CreditCard(const string& no, const string& nm, int lim, double bal) | |
{ | |
number=no; name=nm; | |
balance=bal; limit=lim; | |
} | |
bool CreditCard::chargeIt(double price) | |
{ | |
if(price+balance > double(limit)) | |
return false; | |
balance+=price; | |
return true; | |
} | |
void CreditCard::makePayment(double payment){ | |
balance-=payment; | |
} | |
ostream& operator<<(ostream& out, const CreditCard& c){ | |
out << "Number=" << c.getNumber() << "\n" | |
<< "Name=" << c.getName() << "\n" | |
<< "Balance="<< c.getBalance()<< "\n" | |
<< "Limit=" << c.getLimit() << "\n"; | |
return out; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef CREDIT_CARD_H | |
#define CREDIT_CARD_H | |
#include <string> | |
#include <iostream> | |
class CreditCard | |
{ | |
public: | |
CreditCard(const std::string& no, const std::string& nm, int lim, double bal=0); | |
std::string getNumber() const {return number;} | |
std::string getName() const {return name;} | |
double getBalance() const {return balance;} | |
int getLimit() const {return limit;} | |
bool chargeIt(double price); | |
void makePayment(double payment); | |
private: | |
std::string number; | |
std::string name; | |
int limit; | |
double balance; | |
}; | |
std::ostream& operator<<(std::ostream& out, const CreditCard& c); | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include "CreditCard.h" //includes CreditCard, cout nd string | |
using namespace std; | |
void testCard() | |
{ | |
vector<CreditCard*> wallet(10); //vector of 10 creditcard pointers | |
wallet[0] = new CreditCard("5391 0375 9387 5309", "John Bowman", 2500); | |
wallet[1] = new CreditCard("3485 0399 3395 1954", "John Bowman", 3500); | |
wallet[2] = new CreditCard("6011 4902 3294 2994", "John Bowman", 5000); | |
for(int i=1; i<=16; i++) | |
{ | |
wallet[0]->chargeIt(double(i)); | |
wallet[1]->chargeIt(2*i); | |
wallet[2]->chargeIt(double(3*i)); | |
} | |
cout << "Card Payments:\n"; | |
for(int i=0; i<3; i++) | |
{ | |
cout << *wallet[i]; | |
while(wallet[i]->getBalance() > 100.0){ | |
wallet[i]->makePayment(100.0); | |
cout << "New Balance = " << wallet[i]->getBalance() << "\n"; | |
} | |
cout << "\n"; | |
delete wallet[i]; | |
} | |
} | |
int main(void){ | |
testCard(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment