第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

想要實(shí)現(xiàn)兩個(gè)類(lèi),分別表示雇員和經(jīng)理兩類(lèi)人員,并滿(mǎn)足以下程序給出的運(yùn)行結(jié)果,求指點(diǎn)

想要實(shí)現(xiàn)兩個(gè)類(lèi),分別表示雇員和經(jīng)理兩類(lèi)人員,并滿(mǎn)足以下程序給出的運(yùn)行結(jié)果,求指點(diǎn)

C++
慕村9548890 2023-04-02 18:14:45
公司中有兩類(lèi)人員:一般雇員(Employee)和經(jīng)理(Manager)。每位雇員都有各自的基本信息,包括姓名、年齡、工齡、部門(mén)名稱(chēng)。每位經(jīng)理除了具有這些基本信息外,還具有另外兩個(gè)信息:職務(wù)級(jí)別、他所管轄的雇員信息。int main(){Employee e1(“Jack”, 24, 2, “Development”);Employee e2(“Susan”, 28, 4, “Development”);Manager m(“Tom”, 30, 2, “Development”, 2);m.addMember(&e1).addMember(&e2);e1.printOn(); // display all data member information of Jacke2.printOn(); // display all data member information of Susamm.printOn(); // display all data member information of Tom cout << “Total” << Employee::count();cout<< “employee’s object created.” << endl;return 0;}程序運(yùn)行結(jié)果:This is Jack:age: 24Year: 2Dept: DevelopmentThis is Susan:age: 28Year: 4Dept: DevelopmentThis is Tom:age: 30Year: 2Dept: DevelopmentLevel: 2Members: Jack Susan Total 3 employee’s object created.1.main函數(shù)體中一個(gè)字也不要更改
查看完整描述

2 回答

?
烙印99

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超13個(gè)贊

#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
class Employee{
public:
Employee(char *,int,int,char *);
void printOn();
static int count(); //調(diào)用靜態(tài)成員的函數(shù)也必須是靜態(tài)函數(shù)
char *name;
int age;
int worktime;
char *department;
static int n;
/*~Employee(){
delete name;
delete department;
}*/ //使用該析構(gòu)函數(shù)會(huì)抱內(nèi)存錯(cuò)
};
int Employee::n=0;
Employee::Employee(char *name,int age,int worktime,char *department){
this->name=name; 
this->age=age;
this->worktime=worktime; 
this->department=department;
n++;
}
void Employee::printOn(){
cout<<"This is "<<name<<endl
<<"age "<<age<<endl
<<"year "<<worktime<<endl
<<"Dept "<<department<<endl;
}  
int Employee::count(){
return n;
};
class Manager:public Employee{
public:
Manager(char *,int,int,char *,int);
Manager& addMember(Employee *);
void printOn();
private:
static int m;
int level;
char *member[10];
};
int Manager::m=0;
Manager::Manager(char *name,int age,int worktime,char *department,int level):Employee(name,age,worktime,department){
this->level=level;
}  
Manager& Manager::addMember(Employee *e){
member[m++]=e->name;  
return *this;
}
void Manager::printOn(){
Employee::printOn();
cout<<"Level: "<<level<<endl
<<"Members: ";
for(int i=0;i<n-1;i++)
cout<<member[i]<<" ";
cout<<endl;
}  
int main(){
Employee e1("Jack", 24, 2, "Development");
Employee e2("Susan", 28, 4, "Development");
Manager m("Tom", 30, 2, "Development", 2);
m.addMember(&e1).addMember(&e2);
e1.printOn(); // display all data member information of Jack
e2.printOn(); // display all data member information of Susam
m.printOn(); // display all data member information of Tom 
cout << "Total " << Employee::count();
cout<< " employee's object created." << endl;
system("pause");
return 0;
}

查看完整回答
反對(duì) 回復(fù) 2023-04-05
?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗(yàn) 獲得超12個(gè)贊

#include<iostream>
using namespace std;
/*
公司中有兩類(lèi)人員:一般雇員(Employee)和經(jīng)理(Manager)。
每位雇員都有各自的基本信息,包括姓名、年齡、工齡、部門(mén)名稱(chēng)。
每位經(jīng)理除了具有這些基本信息外,還具有另外兩個(gè)信息:
職務(wù)級(jí)別、他所管轄的雇員信息。請(qǐng)?jiān)O(shè)計(jì)并實(shí)現(xiàn)兩個(gè)類(lèi),分別表示雇
員和經(jīng)理兩類(lèi)人員,并滿(mǎn)足以下程序給出的運(yùn)行結(jié)果(注意:經(jīng)理也是雇員)。 
*/
class Employee
{
char* _xm;
int _nl;
int _gl;
char* _bm;
static int _n;
public:
void getXm(char*&); 
Employee(char*, int, int, char*);
virtual ~Employee();
virtual void printOn();
static int count();
};
void Employee::getXm(char*& xm)
{
strcpy(xm,_xm);
}
int Employee::_n=0;
Employee::Employee(char* xm,int nl, int gl, char* bm)
{
++_n;
_xm=new char[strlen(xm)+1];
strcpy(_xm, xm);
_nl=nl;
_gl=gl;
_bm=new char[strlen(bm)+1];
strcpy(_bm, bm);
}
Employee::~Employee()
{
if(_xm!=NULL)
delete [] _xm;
if(_bm!=NULL)
delete [] _bm;
}
void Employee::printOn()
{
cout<<"This is "<<_xm<<": "<<endl;
cout<<"age: "<<_nl<<endl;
cout<<"Year: "<<_gl<<endl;
cout<<"Dept: "<<_bm<<endl;
}
int Employee::count()
{
return _n;
}

class Manager : public Employee
{
int _dj;
char* _gyxx;
public:
Manager(char*, int, int, char*, int);
virtual ~Manager();
void printOn();
Manager& addMember(Employee*);
};
Manager::Manager(char* xm, int nl, int gl, char* bm,int dj)
:Employee(xm, nl, gl, bm)
{
_gyxx=NULL;
_dj=dj;
}
Manager::~Manager()
{
if(_gyxx!=NULL)
delete [] _gyxx;

void Manager::printOn()
{
Employee::printOn();
cout<<"Level: "<<_dj<<endl;
cout<<"Members: "<<_gyxx<<endl;
}
Manager& Manager::addMember(Employee* e)
{
char* a=new char[50];
e->getXm(a);
if(_gyxx!=NULL)
{

char* t=new char[strlen(_gyxx)+1];
strcpy(t, _gyxx);
delete [] _gyxx;
_gyxx=new char[strlen(t)+strlen(a)+6];
strcpy(_gyxx, t);
strcat(_gyxx, " ");
strcat(_gyxx, a);
delete [] t;
}
else
{
_gyxx= new char[strlen(a)+1];
strcpy(_gyxx, a);
}
delete [] a;
return *this;
}

int main()
{
Employee e1("Jack", 24, 2, "Development");
Employee e2("Susan", 28, 4, "Development");
Manager m("Tom", 30, 2, "Development", 2);
m.addMember(&e1).addMember(&e2);
e1.printOn(); // display all data member information of Jack
e2.printOn(); // display all data member information of Susam
m.printOn(); // display all data member information of Tom
cout << "Total " << Employee::count();
cout<< " employee’s object created." << endl;
return 0;
}


查看完整回答
反對(duì) 回復(fù) 2023-04-05
  • 2 回答
  • 0 關(guān)注
  • 240 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)