OOP HomeWork
This commit is contained in:
29
oop_hw4/hw123/main.cpp
Normal file
29
oop_hw4/hw123/main.cpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include "thief.h"
|
||||
#include "walker.h"
|
||||
#include "police.h"
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
|
||||
int main() {
|
||||
thief t1("Dan", 100, false), t2("Trevor", 50.4, false), t3("Mike", 30.2, false);
|
||||
walker w1("Man", 1000, false), w2("Wan", 5000, false);
|
||||
t1.steal(w1);
|
||||
t2.steal(w2);
|
||||
t1.display();
|
||||
t2.display();
|
||||
w1.display();
|
||||
w2.display();
|
||||
police p1("Officer", 0, 0), p2("Reciffo", 1, 1), p3("fw", 0, 0);
|
||||
p1.caught(t1);
|
||||
p2.caught(t2);
|
||||
cout << "After Caught" << endl;
|
||||
p1.display();
|
||||
p2.display();
|
||||
t1.display();
|
||||
t2.display();
|
||||
return 0;
|
||||
}
|
28
oop_hw4/hw123/police.cpp
Normal file
28
oop_hw4/hw123/police.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include "walker.h"
|
||||
#include "police.h"
|
||||
#include "thief.h"
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
|
||||
police::police(){
|
||||
name = "";
|
||||
money = -1;
|
||||
respect = -1;
|
||||
}
|
||||
police::police(string n, double m, int r) {
|
||||
name = n ;
|
||||
money = m ;
|
||||
respect = r ;
|
||||
}
|
||||
police& police::caught(thief& x) {
|
||||
money += 100;
|
||||
respect++;
|
||||
x.becaught();
|
||||
return *this;
|
||||
}
|
||||
void police::display() {
|
||||
cout << name << " " << money << " " << "Respect :" << respect << endl;
|
||||
}
|
22
oop_hw4/hw123/police.h
Normal file
22
oop_hw4/hw123/police.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "thief.h"
|
||||
#include "walker.h"
|
||||
|
||||
class thief;
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
class police {
|
||||
private:
|
||||
string name;
|
||||
double money;
|
||||
int respect;
|
||||
public:
|
||||
police();
|
||||
police(string n, double m, int r);
|
||||
police& caught(thief& x);
|
||||
void display();
|
||||
};
|
33
oop_hw4/hw123/thief.cpp
Normal file
33
oop_hw4/hw123/thief.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include "thief.h"
|
||||
#include "walker.h"
|
||||
#include "police.h"
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
|
||||
thief::thief() {
|
||||
name = "";
|
||||
money = -1;
|
||||
caught = false;
|
||||
}
|
||||
thief::thief(string n, double m, bool c = false) {
|
||||
name = n;
|
||||
money = m;
|
||||
caught = c;
|
||||
}
|
||||
thief& thief::steal(walker& x) {
|
||||
money += x.money_print();
|
||||
x.zero();
|
||||
caught = true;
|
||||
return *this;
|
||||
}
|
||||
thief& thief::becaught() {
|
||||
money = 0;
|
||||
caught = false;
|
||||
return *this;
|
||||
}
|
||||
void thief::display() {
|
||||
cout << name << " " << money << " " << "If caught :" << caught << endl;
|
||||
}
|
24
oop_hw4/hw123/thief.h
Normal file
24
oop_hw4/hw123/thief.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "walker.h"
|
||||
#include "police.h"
|
||||
|
||||
class walker;
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
class thief {
|
||||
private:
|
||||
string name;
|
||||
double money;
|
||||
bool caught;
|
||||
public:
|
||||
thief();
|
||||
thief(string n, double m, bool c);
|
||||
thief& steal(walker& x);
|
||||
void display();
|
||||
thief& becaught();
|
||||
|
||||
};
|
32
oop_hw4/hw123/walker.cpp
Normal file
32
oop_hw4/hw123/walker.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <iostream>
|
||||
#include "thief.h"
|
||||
#include "walker.h"
|
||||
#include "police.h"
|
||||
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
|
||||
walker::walker() {
|
||||
name = "";
|
||||
money = -1;
|
||||
stolen = false;
|
||||
}
|
||||
walker::walker(string n, double m, bool c = false) {
|
||||
name = n;
|
||||
money = m;
|
||||
stolen = c;
|
||||
}
|
||||
double walker::money_print() {
|
||||
return money;
|
||||
}
|
||||
walker& walker::zero() {
|
||||
money = 0;
|
||||
stolen = true;
|
||||
return *this;
|
||||
}
|
||||
void walker::display() {
|
||||
cout << name << " " << money << " " << "If stolen :" << stolen << endl;
|
||||
}
|
21
oop_hw4/hw123/walker.h
Normal file
21
oop_hw4/hw123/walker.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "thief.h"
|
||||
#include "police.h"
|
||||
|
||||
using std::string;
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
|
||||
class walker {
|
||||
private:
|
||||
string name;
|
||||
double money;
|
||||
bool stolen;
|
||||
public:
|
||||
walker();
|
||||
walker(string n, double m, bool c);
|
||||
double money_print();
|
||||
walker& zero();
|
||||
void display();
|
||||
};
|
BIN
oop_hw4/hw123/测试截图123.png
Normal file
BIN
oop_hw4/hw123/测试截图123.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 408 KiB |
Reference in New Issue
Block a user