OOP HomeWork

This commit is contained in:
e2hang
2025-08-11 00:01:30 +08:00
commit e8a5ca2363
119 changed files with 3187 additions and 0 deletions

29
oop_hw4/hw123/main.cpp Normal file
View 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
View 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
View 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
View 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
View 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
View 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
View 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();
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 KiB