OOP HomeWork
This commit is contained in:
22
oop_hw5/hw3/main.cpp
Normal file
22
oop_hw5/hw3/main.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
#include "person.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
int main() {
|
||||
Employee a[5];
|
||||
Executive b[5];
|
||||
a[0] = Employee(20, "Zhang", 1, 1001);
|
||||
a[1] = Employee(21, "Wang", 1, 1002);
|
||||
a[2] = Employee(19, "Zhao", 0, 1003);
|
||||
a[3] = Employee(22, "Li", 1, 1004);
|
||||
a[4] = Employee(28, "Zh", 0, 1145);
|
||||
a[0].display();
|
||||
a[1].display();
|
||||
a[2].display();
|
||||
a[3].display();
|
||||
a[4].display();
|
||||
return 0;
|
||||
}
|
72
oop_hw5/hw3/person.cpp
Normal file
72
oop_hw5/hw3/person.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "person.h"
|
||||
|
||||
Person::Person(int a, string n, bool g)
|
||||
{
|
||||
age = a;
|
||||
name = n;
|
||||
gender = g;
|
||||
}
|
||||
|
||||
void Person::change_age(int ca)
|
||||
{
|
||||
age = ca;
|
||||
}
|
||||
|
||||
void Person::change_name(string cn)
|
||||
{
|
||||
name = cn;
|
||||
}
|
||||
|
||||
void Person::change_gender(bool x)
|
||||
{
|
||||
gender = x;
|
||||
}
|
||||
|
||||
int Person::show_age()
|
||||
{
|
||||
return age;
|
||||
}
|
||||
|
||||
string Person::show_name()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
bool Person::show_gender()
|
||||
{
|
||||
return gender;
|
||||
}
|
||||
|
||||
void Person::display()
|
||||
{
|
||||
cout << "This is a Person" << endl
|
||||
<< "Name : " << name << endl
|
||||
<< "Age : " << age << endl
|
||||
<< "Gender : ";
|
||||
gender == false ? cout << "Woman" << endl : cout << "Man" << endl;
|
||||
}
|
||||
|
||||
void Employee::add_number(int n)
|
||||
{
|
||||
number = n;
|
||||
}
|
||||
|
||||
void Employee::display()
|
||||
{
|
||||
cout << "This is an Employee" << endl
|
||||
<< "Name : " << this->show_name() << endl
|
||||
<< "Age : " << this->show_age() << endl
|
||||
<< "Gender : ";
|
||||
this->show_gender() == false ? cout << "Woman" << endl : cout << "Man" << endl;
|
||||
cout << "Number ID : " << number << endl;
|
||||
}
|
||||
|
||||
void Executive::display()
|
||||
{
|
||||
cout << "This is an Executive" << endl
|
||||
<< "Name : " << this->show_name() << endl
|
||||
<< "Age : " << this->show_age() << endl
|
||||
<< "Gender : ";
|
||||
this->show_gender() == false ? cout << "Woman" << endl : cout << "Man" << endl;
|
||||
//cout << "Number ID : " << number << endl;
|
||||
}
|
41
oop_hw5/hw3/person.h
Normal file
41
oop_hw5/hw3/person.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
class Person {
|
||||
private:
|
||||
int age;
|
||||
string name;
|
||||
//enum string gender = { "Male","Female" }; <20>Բ<EFBFBD><D4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ôд<C3B4><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bool gender;//1 = Male , 0 = Female
|
||||
public:
|
||||
Person() :age(-1), name("#UNDEFINED"), gender(true) {};
|
||||
Person(int a, string n, bool g);
|
||||
void change_age(int ca);
|
||||
void change_name(string cn);
|
||||
void change_gender(bool x);
|
||||
int show_age();
|
||||
string show_name();
|
||||
bool show_gender();
|
||||
virtual void display();
|
||||
};
|
||||
|
||||
class Employee : public Person {
|
||||
private:
|
||||
int number;
|
||||
public:
|
||||
Employee() :Person(-1, "#UNDEFINED", true), number(-1) {};
|
||||
Employee(int a, string n, bool g, int num) : Person(a, n, g), number(num) {};
|
||||
void add_number(int n);
|
||||
void display();
|
||||
};
|
||||
class Executive : public Employee {
|
||||
public:
|
||||
void display();
|
||||
};
|
||||
|
BIN
oop_hw5/hw3/测试截图3.png
Normal file
BIN
oop_hw5/hw3/测试截图3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 391 KiB |
Reference in New Issue
Block a user