C/C艹

CPP 第一个简单的类

2019-02-14  本文已影响17人  会长__
#include <fstream>
#include <iostream>
using namespace std;

class Tuzisir {
    private:
        double height;
        int age;
        string name;
    public:
        // 成员函数声明
        bool setHeight(double inputHeight);
        double getHeight(void);
        bool setAge(int inputAge);
        int getAge(void);
        bool setName(string name);
        string getName(void);
};

bool Tuzisir::setHeight(double inputHeight) {
    height = inputHeight;
    return true;
}

bool Tuzisir::setAge(int inputAge) {
    age = inputAge;
    return true;
}

bool Tuzisir::setName(string inputName) {
    name = inputName;
    return true;
}

double Tuzisir::getHeight() {
    return height;
}

int Tuzisir::getAge() {
    return age;
}

string Tuzisir::getName() {
    return name;
}

int main()
{
    Tuzisir tuzi1;
    string oss;
    tuzi1.setAge(23);
    tuzi1.setHeight(1.75);
    tuzi1.setName("tuzisir");
    oss = to_string(tuzi1.getHeight()) + tuzi1.getName() + to_string(tuzi1.getAge());
    cout << oss << endl;
}
image.png
上一篇下一篇

猜你喜欢

热点阅读