first commit
This commit is contained in:
commit
1b2bf174e8
164 files changed
+35594
No files matched your search
+15
@@ -0,0 +1,15 @@
|
||||
//atm.h␍
|
||||
#ifndef __ATM_H__␍
|
||||
#define __ATM_H__␍
|
||||
#include <stdlib.h>␍
|
||||
#include "cashcard.h"␍
|
||||
class ATM {␍
|
||||
public:␍
|
||||
double withDraw(Cashcard &myCard, double money) {␍
|
||||
if(myCard.money < money)␍
|
||||
return NULL;␍
|
||||
myCard.money = (myCard.money - money);␍
|
||||
return money;␍
|
||||
}␍
|
||||
};␍
|
||||
#endif␍
|
||||
@@ -0,0 +1,14 @@
|
||||
//bank.cpp␍
|
||||
#ifndef __BANK_CPP__␍
|
||||
#define __BANK_CPP__␍
|
||||
#include "person.h"␍
|
||||
#include "bank.h"␍
|
||||
Cashcard* Bank::makeCashcard(Passport &P) {␍
|
||||
if(&P) {␍
|
||||
Name &N = P.getPassportName();␍
|
||||
Cashcard *tmp = new Cashcard(N);␍
|
||||
return tmp;␍
|
||||
}␍
|
||||
return NULL;␍
|
||||
};␍
|
||||
#endif
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
//bank.h␍
|
||||
#ifndef __BANK_H__␍
|
||||
#define __BANK_H__␍
|
||||
#include "passport.h"␍
|
||||
#include "person.h"␍
|
||||
class Bank {␍
|
||||
public:␍
|
||||
Bank(){}␍
|
||||
~Bank(){}␍
|
||||
Cashcard *makeCashcard(Passport &P);␍
|
||||
int insertMoney(Cashcard &myCard, double money) {␍
|
||||
return(myCard.money += money);␍
|
||||
}␍
|
||||
};␍
|
||||
#endif␍
|
||||
␍
|
||||
@@ -0,0 +1,19 @@
|
||||
//cashcard.h␍
|
||||
#ifndef __CASHCARD_H__␍
|
||||
#define __CASHCARD_H__␍
|
||||
#include "name.h"␍
|
||||
class ATM;␍
|
||||
class Bank;␍
|
||||
class Cashcard {␍
|
||||
friend ATM;␍
|
||||
friend Bank;␍
|
||||
private:␍
|
||||
Name myName;␍
|
||||
double money;␍
|
||||
public:␍
|
||||
Cashcard(Name &N, double M=0):myName(N){money=M;}␍
|
||||
~Cashcard(){}␍
|
||||
void print() { myName.print(); }␍
|
||||
};␍
|
||||
#endif␍
|
||||
␍
|
||||
@@ -0,0 +1,17 @@
|
||||
//main.cpp␍
|
||||
#include "person.h"␍
|
||||
␍
|
||||
void main() {␍
|
||||
Person myPerson(Name("Kalle !"), 20);␍
|
||||
Police myStation;␍
|
||||
Bank myBank;␍
|
||||
ATM myATM;␍
|
||||
if(myPerson.getPassport(myStation)) //Person gets a passport␍
|
||||
myPerson.print();␍
|
||||
if(myPerson.getCashcard(myBank)) //Person gets a cashcard␍
|
||||
myPerson.print();␍
|
||||
if (myPerson.insertMoney(myBank, 200)) //Person insert 200:-␍
|
||||
myPerson.print();␍
|
||||
if(myPerson.getMoney(myATM, 200)) //Person withdraws 200:-␍
|
||||
myPerson.print();␍
|
||||
}␍
|
||||
@@ -0,0 +1,49 @@
|
||||
//name.cpp␍
|
||||
#ifndef __NAME_CPP__␍
|
||||
#define __NAME_CPP__␍
|
||||
#include <iostream.h>␍
|
||||
#include <string.h>␍
|
||||
#include <stdlib.h>␍
|
||||
#include "name.h"␍
|
||||
//##################################################␍
|
||||
// Name␍
|
||||
// Puts name into a buffer␍
|
||||
//==================================================␍
|
||||
Name::Name(char *txt) {␍
|
||||
buff = new char[strlen(txt) + 1];␍
|
||||
strcpy(buff, txt);␍
|
||||
}␍
|
||||
//##################################################␍
|
||||
// Destructor␍
|
||||
// Delets buffer␍
|
||||
//==================================================␍
|
||||
Name::~Name() {␍
|
||||
delete [] buff;␍
|
||||
}␍
|
||||
//##################################################␍
|
||||
// Operator overload␍
|
||||
// Deletes buffer and makes a new one␍
|
||||
// and copies the data␍
|
||||
//==================================================␍
|
||||
void Name::operator = (const Name &src) {␍
|
||||
delete [] buff;␍
|
||||
buff = new char[strlen(src.buff) + 1];␍
|
||||
strcpy(buff, src.buff);␍
|
||||
}␍
|
||||
//##################################################␍
|
||||
// Constructor␍
|
||||
// Creates a new name␍
|
||||
//==================================================␍
|
||||
Name::Name(const Name &src) {␍
|
||||
buff = new char[strlen(src.buff) + 1];␍
|
||||
strcpy(buff, src.buff);␍
|
||||
}␍
|
||||
//##################################################␍
|
||||
// Print␍
|
||||
// Prints out a name␍
|
||||
//==================================================␍
|
||||
void Name::print() {␍
|
||||
cout << buff;␍
|
||||
}␍
|
||||
#endif␍
|
||||
␍
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
//name.h␍
|
||||
#ifndef __NAME_H__␍
|
||||
#define __NAME_H__␍
|
||||
class Name {␍
|
||||
private:␍
|
||||
char* buff;␍
|
||||
public:␍
|
||||
Name(char* txt);␍
|
||||
~Name();␍
|
||||
void operator = (const Name &src);␍
|
||||
Name(const Name &src);␍
|
||||
void print();␍
|
||||
};␍
|
||||
#endif␍
|
||||
@@ -0,0 +1,14 @@
|
||||
//passport.h␍
|
||||
#ifndef __PASSPORT_H__␍
|
||||
#define __PASSPORT_H__␍
|
||||
#include "name.h"␍
|
||||
class Passport {␍
|
||||
private:␍
|
||||
Name myName; //The name in the passport␍
|
||||
public:␍
|
||||
Passport(Name &N):myName(N){}␍
|
||||
~Passport(){}␍
|
||||
void print() { myName.print(); }␍
|
||||
Name getPassportName() {return myName;}␍
|
||||
};␍
|
||||
#endif␍
|
||||
@@ -0,0 +1,54 @@
|
||||
//person.h␍
|
||||
#ifndef __PERSON_H__␍
|
||||
#define __PERSON_H__␍
|
||||
#include "police.h"␍
|
||||
#include "atm.h"␍
|
||||
␍
|
||||
#include "cashcard.h"␍
|
||||
#include "bank.h"␍
|
||||
#include <stdlib.h>␍
|
||||
␍
|
||||
class Person {␍
|
||||
private:␍
|
||||
Name myName;␍
|
||||
int myAge;␍
|
||||
double cash;␍
|
||||
Passport *myPass;␍
|
||||
Cashcard *myCard;␍
|
||||
public:␍
|
||||
Person(Name &N, int &age):myName(N) { //Constructor␍
|
||||
myPass=NULL;␍
|
||||
myCard=NULL;␍
|
||||
cash=0;␍
|
||||
myAge=age;␍
|
||||
}␍
|
||||
~Person(){}␍
|
||||
const Name &getName() { return myName; }␍
|
||||
int getPassport(Police &myStation) {␍
|
||||
if(myPass)␍
|
||||
return NULL;␍
|
||||
myPass = myStation.makePassport(*this);␍
|
||||
};␍
|
||||
int getCashcard(Bank &myBank) {␍
|
||||
if(myCard)␍
|
||||
return NULL;␍
|
||||
myCard = myBank.makeCashcard(*myPass);␍
|
||||
};␍
|
||||
double getMoney(ATM &myATM, double &money) {␍
|
||||
if(!myCard)␍
|
||||
return NULL;␍
|
||||
cash = myATM.withDraw(*myCard, money);␍
|
||||
return cash;␍
|
||||
};␍
|
||||
int insertMoney(Bank &myBank, double &money) {␍
|
||||
if(!myCard)␍
|
||||
return NULL;␍
|
||||
return(myBank.insertMoney(*myCard, money));␍
|
||||
}␍
|
||||
void print() {␍
|
||||
myName.print();␍
|
||||
if(myPass)␍
|
||||
myPass->print();␍
|
||||
};␍
|
||||
};␍
|
||||
#endif␍
|
||||
@@ -0,0 +1,11 @@
|
||||
//police.cpp␍
|
||||
#ifndef __POLICE_CPP__␍
|
||||
#define __POLICE_CPP__␍
|
||||
#include "person.h"␍
|
||||
#include "police.h"␍
|
||||
Passport* Police::makePassport(Person &P) {␍
|
||||
Name &N = P.getName();␍
|
||||
Passport *tmp = new Passport(N);␍
|
||||
return tmp;␍
|
||||
};␍
|
||||
#endif␍
|
||||
@@ -0,0 +1,14 @@
|
||||
//police.h␍
|
||||
#ifndef __POLICE_H__␍
|
||||
#define __POLICE_H__␍
|
||||
#include "passport.h"␍
|
||||
#include "person.h"␍
|
||||
class Person;␍
|
||||
class Police {␍
|
||||
public:␍
|
||||
Police(){}␍
|
||||
~Police(){}␍
|
||||
Passport *makePassport(Person &P);␍
|
||||
};␍
|
||||
#endif␍
|
||||
␍
|
||||
@@ -0,0 +1,13 @@
|
||||
Avancerad programmering i C++␍
|
||||
==========================================␍
|
||||
␍
|
||||
Denna lab skapades med Borland C++ 5.0 ␍
|
||||
Lägg alla .cpp i projektet.␍
|
||||
Kompilera för EasyWin.␍
|
||||
␍
|
||||
I katalogen Visual finns programmet ␍
|
||||
även skapat i MS Visual C++ 6.0␍
|
||||
␍
|
||||
==========================================␍
|
||||
Christian Ohlsson, Karlstadds Universitet␍
|
||||
di7chro@cse.kau.se␍
|
||||
Reference in new issue
Block a user