请问这道C++编程题怎么做?如何创建一个Client类?如图。求大神解答
3个回答
展开全部
//#include "stdafx.h"//If the vc++6.0, with this line.
#include <string>
#include <iostream>
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;
}
展开全部
#include<iostream>
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:"<<m_name<<endl;
cout<<"Age:"<<m_age<<endl;
}
};
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;
}
}
大概就是这样。
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:"<<m_name<<endl;
cout<<"Age:"<<m_age<<endl;
}
};
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;
}
}
大概就是这样。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2017-03-15
展开全部
什么网站Orz
追问
网络教室
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询