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

57
oop_hw5/hw2/animal.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include "animal.h"
#include <iostream>
#include <cstring>
Animal::Animal() {
name = "#UNDEFINED";
weight = -1;
}
Animal::Animal(std::string n, int w) {
name = n;
weight = w;
}
std::string Animal::show_name()
{
return name;
}
int Animal::show_weight()
{
return weight;
}
void Animal::who() {
std::cout << "This is an Animal" << std::endl;
std::cout << "Name : " << name << std::endl
<< "Weight : " << weight << std::endl;
}
Lion::Lion() {
this->change_name("#UNDEFINED_LION_NAME");
this->change_weight(-1);
}
Lion::Lion(std::string n,int w) {
this->change_name(n);
this->change_weight(w);
}
void Lion::who() {
std::cout << "This is a Lion" << std::endl;
std::cout << "Name : " << this->show_name() << std::endl
<< "Weight : " << this->show_weight() << std::endl;
}
Aardvark::Aardvark() {
this->change_name("#UNDEFINED_LION_NAME");
this->change_weight(-1);
}
Aardvark::Aardvark(std::string n, int w) {
this->change_name(n);
this->change_weight(w);
}
void Aardvark::who() {
std::cout << "This is a Aardvark" << std::endl;
std::cout << "Name : " << this->show_name() << std::endl
<< "Weight : " << this->show_weight() << std::endl;
}
void Animal::change_name(std::string cn) {
name = cn;
}
void Animal::change_weight(int cw) {
weight = cw;
}