用类编写任意程序
- 提问者网友:鼻尖触碰
- 2021-05-04 16:07
1.问题内容描述清晰。
2.在解决问题的过程中,必须使用类的方法解决问题。
3.如果使用多个类实现,要画出类结构关系图。
4.关键变量需要注释,重要函数需要画出流程图。
所有文档使用Word撰写,关系图,流程图使用Word中的绘图工具或Visio绘制,最终数据需要包含整个工程,必须包括编译后的可执行文件。
(不要网上能搜到的,这是选修考试大作业,我的qq625505882)
- 五星知识达人网友:第幾種人
- 2021-05-04 17:06
#include<iostream.h>
#include<string.h>
class person{
public:
person()
{
name=NULL;
id=NULL;
}
void setperson(char *n,char *i);
void showperson()
{
cout<<*name<<'\t'<<*id<<endl;
}
~person()
{
delete []name;
delete []id;
}
private:
char *name,*id;
};
class stud{
public:
stud()
{
addr=NULL;
tel=NULL;
}
void setstud(char *a,char *t);
void showstud()
{
cout<<*addr<<'\t'<<*tel<<endl;
}
~stud()
{
delete []addr;
delete []tel;
}
private:
char *addr,*tel;
};
class teacher:public person{
public:
teacher():person()
{
degree=NULL;
dep=NULL;
}
void setteacher(char *deg,char *dp);
void showteacher()
{
cout<<*degree<<'\t'<<*dep<<endl;
}
~teacher()
{
delete []degree;
delete []dep;
}
private:
char *degree,*dep;
};
class student:public person{
public:
student():person()
{
old=0;
sno=NULL;
}
~student()
{
delete []sno;
}
void setstudent(int age,char *no);
void showstudent()
{
cout<<old<<'\t'<<*sno<<endl;
}
private:
int old;
char *sno;
};
class score:public student,public stud{
public:
score():student(),stud()
{
math=0;
eng=0;
}
void setscore(float ma,float en);
void showscore()
{
cout<<math<<'\t'<<eng<<endl;
}
private:
float math,eng;
};
void person::setperson(char *n,char *i)
{
name=new char [strlen (n)+1];
id=new char [strlen(i)+1];
strcpy (name,n);
strcpy(id,i);
}
void teacher::setteacher(char *deg,char *dp)
{
degree=new char[strlen(deg)+1];
dep=new char [strlen(dp)+1];
strcpy(degree,deg);
strcpy(dep,dp);
}
void stud::setstud(char *a,char *t)
{
addr=new char[strlen(a)+1];
tel=new char [strlen(t)+1];
strcpy(addr,a);
strcpy(tel,t);
}
void student::setstudent(int age,char *no)
{
old=age;
sno=new char [strlen(no)+1];
strcpy(sno,no);
}
void score::setscore(float ma,float en)
{
math=ma;
eng=en;
}
void main()
{
char name1,id1,sno1,addr1,tel1,degree1,dep1;
int old1;
float math1,eng1;
cin>>name1>>id1>>sno1>>addr1>>tel1>>degree1>>dep1>>old1>>math1>>eng1;
score c1;
teacher t1;
c1.setperson(&name1,&id1);
c1.setstudent(old1,&sno1);
c1.setstud(&addr1,&tel1);
c1.setscore(math1,eng1);
t1.setteacher(°ree1,&dep1);
c1.showperson();
c1.showstud();
c1.showstudent();
c1.showscore();
t1.showperson();
t1.showteacher();
}