/*定義一個(gè)描述學(xué)生通訊錄的類,數(shù)據(jù)成員包括:姓名、學(xué)校、電話號(hào)碼和郵編;成員函數(shù)包括:輸出各個(gè)數(shù)據(jù)成員的值,分別設(shè)置和獲取各個(gè)數(shù)據(jù)成員的值*/#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();// 設(shè)置數(shù)據(jù)和獲得數(shù)據(jù)?void ShowStudent();//輸出數(shù)據(jù)};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;}//學(xué)生通訊類int main(){?int n;?char *name="qiaoxu";?char *school="jiangsudaxue";?char tel[15];?char pc[6];?cout << "請(qǐng)輸入學(xué)生人數(shù)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;}問(wèn)題是?? 會(huì)提示寫入權(quán)限沖突_Str 是 0x132DC74
- 1 回答
- 0 關(guān)注
- 1498 瀏覽
添加回答
舉報(bào)
0/150
提交
取消