为了账号安全,请及时绑定邮箱和手机立即绑定

关于c++的简单类的问题

关于c++的简单类的问题

C++
为啥有昵称 2017-03-29 19:05:05
/*定义一个描述学生通讯录的类,数据成员包括:姓名、学校、电话号码和邮编;成员函数包括:输出各个数据成员的值,分别设置和获取各个数据成员的值*/#include<iostream>#include<string>using namespace std;class Student{private: char *Name; char *School; char Tel[15]; char PC[6];public: void Assign(char *name, char *shcool, char tel[], char pc[]); void SetName(char *name); void SetSchool(char *school); void SetPhone(char *tei); void SetPC(char *pc); char GetName(); char GetSchool(); char GetPhone(); char GetPC();// 设置数据和获得数据 void ShowStudent();//输出数据};void Student::Assign(char *name, char *school, char tel[], char pc[]){ SetName(name); SetSchool(school); SetPhone(tel); SetPC(pc);}void Student::SetName(char *name){ Name = new char[strlen(name) + 1]; strcpy(Name, name);}void Student::SetSchool(char *school){ School = new char[strlen(school) + 1]; strcpy(School, school);}void Student::SetPhone(char *tel){ strcpy(Tel, tel);}void Student::SetPC(char *pc){ strcpy(PC, pc);}char Student::GetName(){ return *Name;}char Student::GetSchool(){ return *School;}char Student::GetPhone(){ return *Tel;}char Student::GetPC(){ return *PC;}void Student::ShowStudent(){ cout << Name << '\t' << School << '\t' << Tel << '\t' << PC << endl;}//学生通讯类int main(){ int n; char *name="qiaoxu"; char *school="jiangsudaxue"; char tel[15]; char pc[6]; cout << "请输入学生人数n:" << endl; cin >> n; Student *s; s = new Student[n]; cout << "name" << '\t' << "school" << '\t' << "telphone" << '\t' << "post code:" << endl; for (int i=0;i<n;i++) {  cin >> name>> school>> tel >> pc;  s[i].Assign(name, school, tel, pc); } for (int j = 0; j < n; j++) {  s[j].ShowStudent(); } delete[]s; system("pause"); return 0;}问题是   会提示写入权限冲突_Str 是 0x132DC74
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 1398 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信