请问这道C++编程题怎么做?如何创建一个Client类?如图。求大神解答

2024-12-05 02:10:50
推荐回答(3个)
回答1:

//#include "stdafx.h"//If the vc++6.0, with this line.
#include 
#include 
using namespace std;
class Client{
        char *m_name;
        int m_age;
    public:
        Client(char *name,int age){
            m_name=new char[strlen(name)+1];
            strcpy(m_name,name);
            m_age=age;
        }
        ~Client(){
            delete []m_name;
        }
        void display(void){
            cout << "1. Name:" << m_name << endl;
            cout << "2. Age:" << m_age << endl;
        }
};
int main(int argc,char *argv[]){
    char name[20];
    int age;
    cout << "Please enter the user information...\n";
    cin >> name >> age;
    Client t(name,age);
    t.display();
    return 0;
}

回答2:

#include
using namespace std;
class Client{
private:
char* m_name;
int m_age;
public:
Client(char* name,int age) {
m_name=name;
m_age=age;

}
~Client(){
delete m_name;
}

void display()
{
cout<<"Name:"<cout<<"Age:"<
}

};

int main()
{
char inputName[100];
int inputage;
bool flag=true;
while(flag)
{
cout<<"请输入name:";
cin>>inputName;
cout<<"请输入age:";
cin>>inputage;
Client client(inputName,inputage);
client.display();
cout<<"是否继续?1是,0否:";
cin>>flag;
}

}

大概就是这样。

回答3:

什么网站Orz