无聊

来源:互联网 发布:快手未知网络连接错误 编辑:程序博客网 时间:2024/06/05 09:47
#include <iostream>#include <string>using namespace std;class pet{public:    int sum(int a,int b);    void show();    pet(int x, string y);    ~pet();    void setage();    void setname();private:    string name;    int age;    int adoptage;};pet::pet(int x,string y):age(x),name(y){    cout<<"开始"<<endl;}pet::~pet(){    cout<<"再见"<<endl;}int pet::sum(int a, int b){    return (a+b);}void pet::setage(){    int age;    cin>>age;    this->age = age;}void pet::setname(){    string name;    cin>>name;    this->name = name;}void pet::show(){    cout<<"请问宠物的年龄是:"<<endl;    cout<<"姓名:"<<name<<endl;    cout<<"年龄:"<<age<<endl;}int main(){    pet dai(18,"蛋蛋");    dai.show();    cout<<"请问您的宠物的姓名是:"<<endl;    dai.setname();    cout<<"请问您的宠物的年龄是:"<<endl;    dai.setage();    dai.show();    return 0;}


 

0 0
原创粉丝点击