1.定义一个学生类,其中有3个数据成员:学号、姓名、年龄,2个成员函数;构造函数和显示学生信息
1.定义一个学生类,其中有3个数据成员:学号、姓名、年龄,2个成员函数;构造函数和显示学生信息的display函数。2.编写main函数使用这个类,实现对一个学生数据的赋...
1.定义一个学生类,其中有3个数据成员:学号、姓名、年龄,2个成员函数;构造函数和显示学生信息的display函数。2.编写main函数使用这个类,实现对一个学生数据的赋值和输出。该学生的信息如下:学号:001 姓名:yingxing 年龄:10
急!!!在线等 展开
急!!!在线等 展开
4个回答
展开全部
#include <iostream>
#include <string>
using namespace std;
class student
{
public:
student()
{
}
student(char *id,char *name,int age)
{
strcpy(stuId,id);
strcpy(stuName,name);
stuAge = age;
}
void display()
{
cout<<"学号:"<<stuId<<"姓名:"<<stuName<<"年龄:"<<stuAge<<endl;
}
private:
char stuId[10];
char stuName[20];
int stuAge;
};
int main()
{
student st("001","yingxing",10);
st.display();
return 0;
}
#include <string>
using namespace std;
class student
{
public:
student()
{
}
student(char *id,char *name,int age)
{
strcpy(stuId,id);
strcpy(stuName,name);
stuAge = age;
}
void display()
{
cout<<"学号:"<<stuId<<"姓名:"<<stuName<<"年龄:"<<stuAge<<endl;
}
private:
char stuId[10];
char stuName[20];
int stuAge;
};
int main()
{
student st("001","yingxing",10);
st.display();
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
#include <string>
using namespace std;
class Student
{
char Id[20];
char Name[20];
int Age;
public:
Student(char Id[20],char Name[20], int Age);
void Display();
};
Student::Student(char* _id,char* _name, int _age)
{
strcpy(Id, _id);
strcpy(Name, _name);
Age = _age;
}
void Student::Display()
{
cout << "学号:" << Id << " 姓名:" << Name << " 年龄:" << Age;
}
int main()
{
Student stu("001","yingxing", 10);
stu.Display();
return 0;
}
#include <string>
using namespace std;
class Student
{
char Id[20];
char Name[20];
int Age;
public:
Student(char Id[20],char Name[20], int Age);
void Display();
};
Student::Student(char* _id,char* _name, int _age)
{
strcpy(Id, _id);
strcpy(Name, _name);
Age = _age;
}
void Student::Display()
{
cout << "学号:" << Id << " 姓名:" << Name << " 年龄:" << Age;
}
int main()
{
Student stu("001","yingxing", 10);
stu.Display();
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <iostream>
usingnamespacestd;
class Student{
private:
string id;
int age;
string name;
public:
Student(string vid, string vname, int vage)
{
id = vid;
name = vname;
age = vage;
}
void display()
{
cout << "my name is "<<name << ",my age is " << age << endl;
}
};
int main (int argc, constchar * argv[])
{
// insert code here...
Student *student = newStudent("001", "yingxing", 10);
student->display();
return0;
}
usingnamespacestd;
class Student{
private:
string id;
int age;
string name;
public:
Student(string vid, string vname, int vage)
{
id = vid;
name = vname;
age = vage;
}
void display()
{
cout << "my name is "<<name << ",my age is " << age << endl;
}
};
int main (int argc, constchar * argv[])
{
// insert code here...
Student *student = newStudent("001", "yingxing", 10);
student->display();
return0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |