OOP HomeWork
This commit is contained in:
33
oop_hw4/hw4/main.cpp
Normal file
33
oop_hw4/hw4/main.cpp
Normal 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
33
oop_hw4/hw4/man.cpp
Normal 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
24
oop_hw4/hw4/man.h
Normal 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
34
oop_hw4/hw4/woman.cpp
Normal 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
24
oop_hw4/hw4/woman.h
Normal 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();
|
||||
};
|
BIN
oop_hw4/hw4/测试截图4.png
Normal file
BIN
oop_hw4/hw4/测试截图4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 380 KiB |
Reference in New Issue
Block a user