91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 7KB
    文件類型: .cpp
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2024-01-05
  • 語言: C/C++
  • 標(biāo)簽: 鏈表??C++??編程??

資源簡(jiǎn)介

/* 題目: 大學(xué)中的人員分三類 :學(xué)生,教師和職員,他們的基本信息如下: 學(xué)生:姓名,年齡,學(xué)號(hào),年級(jí),成績(jī) 教師:姓名,年齡,身份證號(hào),職稱,工資 職員:姓名,年齡,身份證號(hào),工資 現(xiàn)在需要管理各類人員的信息,請(qǐng)用面向?qū)ο蟮姆椒ㄔO(shè)計(jì)一個(gè)異質(zhì)鏈表,用來存放他們的信息。 異質(zhì)鏈表實(shí)現(xiàn):有三個(gè)類 student,teacher,staff,再定義一個(gè) 鏈表類,此類用來存放這幾個(gè)不同類的對(duì)象,并將鏈表類 list 聲明為所有這些 類的友元,使它們可以訪問它們的私有成員。*/

資源截圖

代碼片段和文件信息

/*
題目:
大學(xué)中的人員分三類?:學(xué)生,教師和職員,他們的基本信息如下:?
學(xué)生:姓名,年齡,學(xué)號(hào),年級(jí),成績(jī)?
教師:姓名,年齡,身份證號(hào),職稱,工資?
職員:姓名,年齡,身份證號(hào),工資?
現(xiàn)在需要管理各類人員的信息,請(qǐng)用面向?qū)ο蟮姆椒ㄔO(shè)計(jì)一個(gè)異質(zhì)鏈表,用來存放他們的信息。?

???異質(zhì)鏈表實(shí)現(xiàn):有三個(gè)類?student,teacher,staff,再定義一個(gè)?
鏈表類,此類用來存放這幾個(gè)不同類的對(duì)象,并將鏈表類?list?聲明為所有這些?
類的友元,使它們可以訪問它們的私有成員。*/?


#include?
#include??
#include??
using?namespace?std;

class?person{?//定義一個(gè)共同的基類,它具有公共的數(shù)據(jù)成員?
friend?class?list;?//鏈表類作為本類的友元?
protected:?
char?name[20];?//定義姓名?
int?age;?//定義年齡?
char?add[40];?//定義地址?
char?tele[20];?//定義電話號(hào)碼?
static?person?*ptr;?//定義一個(gè)指向person類對(duì)象的靜態(tài)指針?
person?*next;?//指向下一個(gè)對(duì)象的指針?
public:?
person(char?*nameint?agechar?*addchar?*tele);//構(gòu)造函數(shù)?
virtual?void?print();?//說明虛函數(shù)?
virtual?void?insert(){};//定義虛函數(shù)并且什么也不做,只定義一個(gè)接口?
};?

class?student:public?person{?//派生類?student?
friend?class?list;?//鏈表類作為本類的友元?
int?level;?//定義年級(jí)?
float?grade_point_average;?//定義平均分?
public:?
student(char?*nameint?agechar?*addchar?*tele?int?level?float?grade_point_average);?//聲明構(gòu)造函數(shù)?
void?print();?//重新定義print()函數(shù)?
void?insert();?//重新定義insert()函數(shù)?
};?
//?
class?teacher:public?person{?//派生類?teacher?
friend?class?list;?//鏈表類作為本類的友元?
float?salary;?//定義工資?
public:?
teacher(char?*nameint?agechar?*addchar?*telefloat?salary);?//聲明構(gòu)造函數(shù)?
void?print();?//重新定義print()函數(shù)?
void?insert();?//重新定義insert()函數(shù)?
};?
//?
class?staff:public?person{?//派生類?staff?
friend?class?list;?//鏈表類作為本類的友元?
float?hourly_wages;?//定義計(jì)時(shí)工資?
public:?
staff(char?*nameint?agechar?*addchar?*tele?
float?hourly_wages);?//聲明構(gòu)造函數(shù)?
void?print();?//重新定義print()函數(shù)?
void?insert();?//重新定義insert()函數(shù)?
};?
//?
class?list{?//定義異質(zhì)鏈表類?
person?*root;?//鏈表頭指針?
public:?
list(){?root=0;?}?//鏈表構(gòu)造函數(shù),初始為?0?
void?insert_person(person?*node);?//向鏈表插入一個(gè)對(duì)象結(jié)點(diǎn)?
void?remove(char?*name);?//從鏈表移去一個(gè)對(duì)象結(jié)點(diǎn)?
void?print_list();?//輸出整個(gè)鏈表?
};?
//?
person::person(char?*nameint?agechar?*addchar?*tele)?
{?//person?的構(gòu)造函數(shù)?
strcpy(person::namename);?
strcpy(person::addadd);?
strcpy(person::teletele);?
person::age=age;?
next=0;?
}?
void?person::print()?//基類的虛成員函數(shù)print()版本,輸出基類數(shù)據(jù)成員?
{?
cout<<“\nname:?“<cout<<“age:?“<cout<<“address:?“<cout<<“telephone?number:?“<}?
//?
student::student(char?*nameint?agechar?*addchar?*tele?int?level?float?grade_point_average):person(nameageaddtele)?
{?//student?派生類的構(gòu)造函數(shù),需綴上基類的構(gòu)造函數(shù)?
student::level=level;?
student::grade_point_average=grade_point_average;?
}?
void?student::print()?//派生類?student的成員函數(shù)print()新版本?
{?
person::print();?
cout<<“grade?point?average:?“<}?
void?student::insert()?
{?//將?student?類的一個(gè)對(duì)象賦給?ptr?基類指針,這是允許的?
ptr=new?student(nameageaddtelelevelgrade_point_average);?
}?
//?
teacher::teacher(char?*nameint?agechar?*addchar?*tele?float?salary):person(nameageaddtele)?//teacher?派生類的構(gòu)造函數(shù),需綴上?
//基類的構(gòu)造函數(shù)?
{?
teacher::salary=salary;?
}?
void?teacher::print()?//派生類?teacher的成員函數(shù)print()新版本

評(píng)論

共有 條評(píng)論