1 solutions

  • 0
    @ 2025-11-5 17:25:08

    C++ :

    #include <iostream>
    #include <string.h>
    using namespace std;
    class Person{
    	public:
    	Person();
    	void Register();//成员 赋值函数
    	void  showme(); 
    	~Person();
    	private:
    		char name[20];
    		int age;
    		char x;
    		
    };
    Person::Person(){
    	char w[20]="XXX";
    	int a=0;
    	char c='m';
    	strcpy(name,w);
    	age=a;
    	x=c;
    }
     void Person::Register(){
     	cin>>name;
     	cin>>age;
     	cin>>x;
     }
     void Person::showme(){
     	cout<<name<<" "<<age<<" "<<x<<endl; 
     }
     Person::~Person(){
     	cout<<"Now destroying the instance of Person"<<endl;
     }
      
    int main(){
    	int i;
    	Person s[2];
    	Person *p1,*p2;
    	p1=&s[0];
    	p2=&s[1];
    		s[0].Register();
    	for(i=0;i<2;i++){
    		cout<<"person"<<i+1<<":";
    	   s[1].showme();
    	}
    	s[1]=s[0];
    	cout<<"person"<<1<<":";
    	p1->showme();
    	cout<<"person"<<2<<":";
    	p2->showme(); 
    return 0;	
    }  
    
    • 1

    Information

    ID
    18409
    Time
    1000ms
    Memory
    32MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By