[期中][Class and Object] Cat Class

Problem Description
Please design a class Cat, which contains the following public member functions:
请设计类 Cat, 它包含下面的公有成员函数:

int get_age() const
string get_name() const
void set_age(int age)
void set_name(const string & name)

EXAMPLE INPUT

KLUBZSW
4

EXAMPLE OUTPUT

This is my cat:
KLUBZSW
4

主程序(C/C++)

#include <iostream>
#include <string>
using namespace std;

#include "source.cpp"

void print_cat(const Cat & cat) {
    cout << "This is my cat:" << endl;
    cout << cat.get_name() << endl;
    cout << cat.get_age() << endl;
}

int main() {
    int age;
    string name;
    cin >> name >> age;
    Cat cat;
    cat.set_name(name);
    cat.set_age(age);
    print_cat(cat);
}

答案

#include <iostream>
#include <string>
using namespace std;
class Cat
{
    int age;
    string name;
public:
    string get_name() const {
        return name;
    }
    int get_age() const {
        return age;
    }
    void set_name(const string & n) {
        name = n;
    }
    void set_age(int a) {
        age = a;
    }
};

随机测试文本产生程序 (C)

#include <stdio.h>
int main() {
    printf("KLUBZSW\n");
    printf("4\n");
}
支持 makedown语法