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

33
oop_hw4/hw4/main.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <iostream>
#include <cstring>
#include "man.h"
#include "woman.h"
using std::string;
using std::cout;
using std::cin;
using std::endl;
int main() {
man m1("Zhang", false , NULL), m2("Wang", false , NULL), m3("Li", true , NULL), m4("Zhao", true , NULL);
woman w1("Wan", false, NULL), w2("Wu", false, NULL), w3("Xu", true, NULL), w4("Zhou", true, NULL);
m1.marry(&w1);
m2.marry(&w2);
m3.marry(&w3);
m4.marry(&w4);
cout << "Set" << endl;
m1.show() == NULL ? cout << "Devorced" << endl : cout << m1.show()->display() << endl;
m2.show() == NULL ? cout << "Devorced" << endl : cout << m2.show()->display() << endl;
m3.show() == NULL ? cout << "Devorced" << endl : cout << m3.show()->display() << endl;
m4.show() == NULL ? cout << "Devorced" << endl : cout << m4.show()->display() << endl;
cout << "Arrange" << endl;
m2.devorce(&w2);
m4.devorce(&w4);
m1.show() == NULL ? cout << "Devorced" << endl : cout << m1.show()->display() << endl;
m2.show() == NULL ? cout << "Devorced" << endl : cout << m2.show()->display() << endl;
m3.show() == NULL ? cout << "Devorced" << endl : cout << m3.show()->display() << endl;
m4.show() == NULL ? cout << "Devorced" << endl : cout << m4.show()->display() << endl;
return 0;
}

33
oop_hw4/hw4/man.cpp Normal file
View File

@@ -0,0 +1,33 @@
#include <iostream>
#include "woman.h"
#include "man.h"
using std::string;
using std::cout;
using std::cin;
using std::endl;
man::man() {
name = "";
married = false;
w = NULL;
}
man::man(string n, bool m, woman* x) {
name = n;
married = m;
w = x;
}
void man::marry(woman* x) {
w = x;
married = true;
}
void man::devorce(woman* x) {
w = NULL;
married = false;
}
string man::display() {
return name;
}
woman* man::show() {
return w;
}

24
oop_hw4/hw4/man.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include <iostream>
#include "woman.h"
using std::string;
using std::cout;
using std::cin;
using std::endl;
class woman;
class man {
private:
string name;
bool married;
woman* w;
public:
man();
man(string n, bool m, woman* x);
void marry(woman* x);
void devorce(woman* x);
string display();
woman* show();
};

34
oop_hw4/hw4/woman.cpp Normal file
View File

@@ -0,0 +1,34 @@
#include <iostream>
#include "man.h"
#include "woman.h"
using std::string;
using std::cout;
using std::cin;
using std::endl;
woman::woman() {
name = "";
married = false;
w = NULL;
}
woman::woman(string n, bool m, man* x) {
name = n;
married = m;
w = x;
}
void woman::marry(man* x) {
w = x;
married = true;
}
void woman::devorce(man* x) {
w = NULL;
married = false;
}
string woman::display() {
return name;
}
man* woman::show() {
return w;
}

24
oop_hw4/hw4/woman.h Normal file
View File

@@ -0,0 +1,24 @@
#pragma once
#include <iostream>
#include "man.h"
using std::string;
using std::cout;
using std::cin;
using std::endl;
class man;
class woman {
private:
string name;
bool married;
man* w;
public:
woman();
woman(string n, bool m, man* x);
void marry(man* x);
void devorce(man* x);
string display();
man* show();
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 380 KiB