1 条题解

  • 0
    @ 2025-4-12 22:06:17

    C++ :

    #include <iostream> 
    #include <string>
    using namespace std;
    class Dog{
    	public:
    		Dog();
    		void shuru();
    	string GetName(){return name;}
    	int GetAge(){return age;}
    	char GetSex(){return sex;}
    	float GetWeight(){return weight;}
    	static void speak();
    	private:
    	string name;
    	int age;
    	char sex;
    	float weight;
    	static string dog;	
    };
    string Dog::dog="Arf!Arf!";
    Dog::Dog(){
    	string n="dfs";
    	int a=21;
    	char s='a';
    	float w=2.4;
    	name=n;
    	age=a;
    	sex=s;
    	weight=w;
    }
    void Dog::shuru(){
    	cin>>name>>age>>sex>>weight;
    }
    void Dog::speak(){
    	cout<<dog<<endl;
    }
    int main(){
    	Dog d; 
    	d.shuru();
    	cout<<d.GetName()<<endl;
    	cout<<d.GetAge()<<endl;
    	cout<<d.GetSex()<<endl;
    	cout<<d.GetWeight()<<endl;
    	Dog::speak();
    return 0;
    }
    
    • 1

    信息

    ID
    2864
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者