欢迎来到课桌文档! | 帮助中心 课桌文档-建筑工程资料库
课桌文档
全部分类
  • 党建之窗>
  • 感悟体会>
  • 百家争鸣>
  • 教育整顿>
  • 文笔提升>
  • 热门分类>
  • 计划总结>
  • 致辞演讲>
  • 在线阅读>
  • ImageVerifierCode 换一换
    首页 课桌文档 > 资源分类 > DOC文档下载  

    c课后实验.doc

    • 资源ID:14864       资源大小:102KB        全文页数:18页
    • 资源格式: DOC        下载积分:10金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    c课后实验.doc

    实验一:第三章 类与对象定义一个学生类,进展成绩管理,显示学生的所有信息。#include<iostream>#include<string>using namespace std;class Studentprivate:char name10,*snumber;double math,eng,puter;public:Student(char*n,char *s,double m,double e,double c)strcpy(name,n);snumber=s;math=m;eng=e;puter=c;void avescore()double ave;ave=(math+eng+puter)/3.0;cout<<":"<<name<<endl;cout<<"学号:"<<snumber<<endl;cout<<"数学:"<<math<<endl;cout<<"英语:"<<eng<<endl;cout<<"计算机:"<<puter<<endl;cout<<"平均成绩:"<<ave<<endl<<endl;void main()Student x("三","200701",80,85,87),y("四","200702",75,80,79),z("王五","200703",85,90,77);x.avescore();y.avescore();z.avescore();实验二:第三章 类与对象 课后习题10:某单位的职工工资包括根本工资Wage,岗位津贴Subsidy,房租Rent,水费WaterFee和电费ElecFee。设计实现工资管理的类Salary。其中:实发工资Wage+Subsidy-Rent-WaterFee-ElecFee#include<iostream>#include<string>using namespace std;class Salaryprivate:double Wage,Subsidy,Rent,WaterFee,ElecFee;public:Salary(double a,double b,double c,double d,double e)Wage=a;Subsidy=b;Rent=c;WaterFee=d;ElecFee=e;Salary()Wage=0;Subsidy=0;Rent=0;WaterFee=0;ElecFee=0;void setWage(double f)Wage=f;getWage()return Wage;void setSubsidy(double f)Subsidy=f;getSubsidy()return Subsidy;void setRent(double f)Rent=f;getRent()return Rent;void setWaterFee(double f)WaterFee=f;getWaterFee()return WaterFee;void setElecFee(double f)ElecFee=f;getElecFee()return ElecFee;void RealSalary()double realsalary;realsalary=Wage+Subsidy-Rent-WaterFee-ElecFee;cout<<"Wage is:"<<Wage<<endl<<endl;cout<<"Subsidy is:"<<Subsidy<<endl<<endl;cout<<"Rent is:"<<Rent<<endl<<endl;cout<<"WaterFee is:"<<WaterFee<<endl<<endl;cout<<"ElecFee is:"<<ElecFee<<endl<<endl;cout<<"realsalary is:"<<realsalary<<endl<<endl;void main()Salary a;a.setWage(2000);a.setSubsidy(300);a.setRent(500);a.setWaterFee(200);a.setElecFee(100);a.RealSalary();实验三 第三章 类与对象 课后习题 11:设计一个工人类,它具有,年龄,工作部门,工资等数据。其中工资即10题中设计的Salary类型的数据。按照第10题的形式完成工人类的程序设计,并统计工人的人数用静态成员统计人数。#include<iostream>using namespace std;class Salaryprivate: double wage,subsidy,rent,waterfee,elecfee;public:Salary(double a,double b,double c, double d, double e)wage=a;subsidy=b;rent=c;waterfee=d;elecfee=e;double Realsalary()double realsalary;realsalary=wage+subsidy-rent-waterfee-elecfee;class Workerprivate:char name10,dept10;int age;double salary;double wage,subsidy,rent,waterfee,elecfee,realsalary;Salary s;static int number;public:Worker(char *Name,char *Dept,int A,double a,double b,double c, double d, double e):s(a,b,c,d,e)strcpy(name,Name);strcpy(dept,Dept);age=A;wage=a;subsidy=b;rent=c;waterfee=d;elecfee=e;realsalary=wage+subsidy-rent-waterfee-elecfee;void display()number+; cout<<name<<" "<<dept<<" "<<age<<" "<<wage<<" "<<subsidy<<" "<<rent<<" "<<waterfee<<" "<<elecfee<<" "<<realsalary<<" "<<number; cout<<endl;int Worker:number=0;void main()cout<<"职工 部 门 年龄 根本工资 岗位津贴 房租 水费 电费 实际工资 人数 t "Worker p("王 卫","生劳部",35,2000,300,500,100,100), q(" 畅","宣传部",28,2400,200,500,100,150), r(" 明","策划部",30,2600,400,700,200,200);p.display();q.display();r.display();实验四:第四章 继承 :在某高校,对员工进展工资管理普通教学人员:根本工资+课时费课时*每课时报酬。科研人员:根本工资+科研经费提成每月经费*提成率。教授:根本工资+课时费+科研经费提成+5000。专家教授:根本工资+课时费+科研经费提成+10000。#include<iostream>using namespace std;class Personprivate:char name20;int num;public:char *getname()return name;int getnum()return num;int setnum(int x)num=x;Person();Person(char *na,int nu)strcpy(name,na);num=nu;void show()cout<<":"<<getname()<<endl;cout<<"编号:"<<getnum()<<endl;class PtStaff:virtual public Personprivate:int bsalary;int hour;int payph;public:int setbsalary(int x)bsalary=x;int sethour(int x)hour=x;int setpayph(int x)payph=x;int getbsalary()return bsalary;int gethour()return hour;int getpayph()return payph;int getcpay()return hour*payph;int getrealsalary()return bsalary+hour*payph;PtStaff(char *na,int nu,int bs,int ho,int ph):Person(na,nu)bsalary=bs;hour=ho;payph=ph;void dis()cout<<"-普通教学人员->"<<getname()<<endl;show();cout<<"根本工资:"<<getbsalary()<<endl;cout<<"课时:"<<gethour()<<endl;cout<<"每课时报酬:"<<getpayph()<<endl;cout<<"课时费:"<<getcpay()<<endl;cout<<"实际工资:"<<getrealsalary()<<endl<<endl;class KyStaff:virtual public Personprivate:int jsalary;int outlaypm;float tcl;public:int setjsalary(int x)jsalary=x;int setoutlaypm(int x)outlaypm=x;float settcl(int x)tcl=x;int getjsalary()return jsalary;int getoutlaypm()return outlaypm;float gettcl()return tcl;float getjftc()return outlaypm*tcl;float getshijisalary()return jsalary+outlaypm*tcl;KyStaff(char *na,int nu,int js,int opm,float tc):Person(na,nu)jsalary=js;outlaypm=opm;tcl=tc;void disp()cout<<"-科研人员->"<<getname()<<endl;show();cout<<"根本工资:"<<getjsalary()<<endl;cout<<"每月经费:"<<getoutlaypm()<<endl;cout<<"提成率:"<<gettcl()<<endl;cout<<"科研经费提成:"<<getjftc()<<endl;cout<<"实际工资:"<<getshijisalary()<<endl<<endl;class Professor:public PtStaff,public KyStaffprivate:int jintie;public:Professor(char *na,int nu,char *nam,int num,int bs,int ho,int ph,char *Nam,int Num,int js,int opm,float tc,int jt): Person(na,nu),PtStaff(nam,num,bs,ho,ph),KyStaff(Nam,Num,js,opm,tc)jintie=jt;void displ()cout<<"-教授->"<<getname()<<endl;show();cout<<"作为普通教学人员的工资:"<<endl;cout<<"根本工资:"<<getbsalary()<<endl;cout<<"课时:"<<gethour()<<endl;cout<<"每课时报酬:"<<getpayph()<<endl;cout<<"课时费:"<<getcpay()<<endl;cout<<"作为科研人员的工资:"<<endl;cout<<"根本工资:"<<getjsalary()<<endl;cout<<"每月经费:"<<getoutlaypm()<<endl;cout<<"提成率:"<<gettcl()<<endl;cout<<"科研经费提成:"<<getjftc()<<endl;cout<<"津贴:"<<jintie<<endl;cout<<"实际工资:"<<getrealsalary()+getshijisalary()+jintie<<endl<<endl;class Exprofessor:public PtStaff,public KyStaffprivate:int allowance;public:Exprofessor(char *na,int nu,char *nam,int num,int bs,int ho,int ph,char *Nam,int Num,int js,int opm,float tc,int al): Person(na,nu),PtStaff(nam,num,bs,ho,ph),KyStaff(Nam,Num,js,opm,tc)allowance=al;void displa()cout<<"-专家教授->"<<getname()<<endl;show();cout<<"作为普通教学人员的工资:"<<endl;cout<<"根本工资:"<<getbsalary()<<endl;cout<<"课时:"<<gethour()<<endl;cout<<"每课时报酬:"<<getpayph()<<endl;cout<<"课时费:"<<getcpay()<<endl;cout<<"作为科研人员的工资:"<<endl;cout<<"根本工资:"<<getjsalary()<<endl;cout<<"每月经费:"<<getoutlaypm()<<endl;cout<<"提成率:"<<gettcl()<<endl;cout<<"科研经费提成:"<<getjftc()<<endl;cout<<"津贴:"<<allowance<<endl;cout<<"实际工资:"<<getrealsalary()+getshijisalary()+allowance<<endl<<endl;void main()PtStaff a("跃",200709,2000,40,80);KyStaff b("琳",200780,2200,5000,0.25);Professor c("吴建华",200734,"吴建华",200734,2600,90,30,"吴建华",200734,2400,8000,0.2,5000);Exprofessor d("胡海涛",200750,"胡海涛",200750,3000,20,100,"胡海涛",200750,2700,6000,0.2,10000);a.dis();b.disp();c.displ();d.displa();实验五 第四章 继承 课后习题 11:一个教学系统至少有学生和教师两种类型的人员,假设教师的数据有教师编号,性别,职称和系别。学生的数据有学号,年龄,性别,班级,语文数学英语三门课程的成绩。编程完成学生和教师档案数据的输入和显示。要求如下:设计三个类Person,Teacher,Student。Person是后两个的基类,具有此二类共有的数据成员,年龄,性别,并具有输入和显示这些数据的成员函数。教师类继承了人类的,并增加了教师编号,职称和系别等数据成员进展输入和显示的成员函数,按照同样的方法完善学生类。#include<iostream.h>#include<string.h>class Personprotected:char *name;char *sex;int age;public:Person(char *n,char *s,int a)age=a;name=new charstrlen(n)+1;strcpy(name,n);sex=new charstrlen(s)+1;strcpy(sex,s);Person();Person();void display()cout<<":"<<name<<""<<"性别:"<<sex<<""<<"年龄:"<<age<<""<<endl;char *getname()return name;class Teacher:public Personprotected:int tnumber;char *title;char *branch;public:Teacher(char *n,char *s,int a,int tn,char *t,char *b):Person(n,s,a)tnumber=tn;title=new charstrlen(n)+1;strcpy(title,t);branch=new charstrlen(n)+1;strcpy(branch,b);Teacher();void show()cout<<"编号:"<<tnumber<<""<<"职称:"<<title<<""<<"系别:"<<branch<<endl;class Student:public Person protected:char *sclass;int snumber;int chi;int mat;int eng;public:Student(char *n,char *s,int a,char *sc,int sn,int ch,int ma,int en):Person(n,s,a)sclass=new charstrlen(n)+1;strcpy(sclass,sc);snumber=sn;chi=ch;mat=ma;eng=en;Student();void show()cout<<"班级:"<<sclass<<""<<"学号:"<<snumber<<""<<"语文:"<<chi<<""<<"数学:"<<mat<<""<<"英语:"<<eng<<endl;void main()Teacher a1("何云","女",40,2007101,"副教授","外语系");Student b1("马玲","女",18,"电子商务二班",200701,75,80,70);cout<<a1.getname()<<endl;a1.display();a1.show();cout<<endl<<endl;cout<<b1.getname()<<endl;b1.display();b1.show();实验六 第五章 多态 课后习题 5:用抽象类设计计算一个二维平面图形面积的程序,在基类Tdshape中设计纯虚函数area()和printName()。前者用于计算几何图形的面积,后者用于打印输出几何图形的类名。如是Triangle类就打印出Triangle,每个具体形状的类如此从抽象类Tdshape中派生,各自需要定义其独有的数据成员和成员函数,并且定义area()和printName()具体的实现代码。#include<iostream>using namespace std;class TDshapepublic:virtual void area()=0;virtual void printName()=0;class Triangle:public TDshapeprivate:double width,height;public:void setwidth(double x)width=x;void setheight(double x)height=x;double getwidth()return width;double getheight()return height;void area()cout<<width*height*0.5<<endl<<endl;void printName()cout<<"这是Triangle,它的面积是:"<<endl;class Rectangle:public TDshapeprivate:double width,height;public:void setwidth(double x)width=x;void setheight(double x)height=x;double getwidth()return width;double getheight()return height;void area()cout<<width*height<<endl<<endl;void printName()cout<<"这是Rectangle,它的面积是:"<<endl;void main()TDshape *p;Triangle t;t.setheight(20);t.setwidth(20);p=&t;p->printName();p->area();Rectangle r;TDshape &q=r;r.setwidth(20);r.setheight(20);q.printName();q.area();实验七 第六章 运算符重载 课后习题 6:设计一个计数器,它只有一个用于计数的数据成员count。它的有效计数围是0-65535。实现计数器的前自增,后自增,前自减,后自减,两个计数器相加减等运算。#include<iostream>using namespace std;class Calculatorerprivate:int count;public:Calculatorer(int i=0)count=i;void setcount(int x)count=x;int getcount()return count;Calculatorer operator+();Calculatorer operator+(int);friend Calculatorer operator-(Calculatorer &a);friend Calculatorer operator-(Calculatorer &a,int);Calculatorer operator+(Calculatorer a);Calculatorer operator-(Calculatorer a);friend Calculatorer operator*(Calculatorer b,Calculatorer c);friend Calculatorer operator/(Calculatorer b,Calculatorer c);void display();Calculatorer Calculatorer:operator+()+count;cout<<"Calculatorer的前自增运算-> "return *this;Calculatorer Calculatorer:operator+(int)count+;cout<<"Calculatorer的后自增运算-> "return *this;Calculatorer operator-(Calculatorer &a)-a.count;cout<<"Calculatorer的前自减运算-> "return a;Calculatorer operator-(Calculatorer &a,int)a.count-;cout<<"Calculatorer的后自减运算-> "return a;Calculatorer Calculatorer:operator+(Calculatorer a)cout<<"两个计数器相加-> "return Calculatorer(a.count+count);Calculatorer Calculatorer:operator-(Calculatorer a)cout<<"两个计数器相减-> "return Calculatorer(count-a.count);Calculatorer operator*(Calculatorer b,Calculatorer c)cout<<"两个计数器相乘-> "Calculatorer t;t.count=b.count*c.count;return t;Calculatorer operator/(Calculatorer b,Calculatorer c)cout<<"两个计数器相除-> "return Calculatorer(b.count/c.count);void Calculatorer:display()if(count>=0&&count<=65535)cout<<"Calculatorer number="<<count<<endl;elsecout<<"计算结果超出本计数器围!"<<endl;void main(void) Calculatorer d;int m;cout<<"-一个计数器的自增运算-"<<endl;cout<<"请输入Calculatorer的初始值m(m的围是065535):"<<endl;cin>>m;if(m<0|m>65535)cout<<"您输入的数超过本计数器的围,请重新输入!"<<endl;d.setcount(m);+d;d.display();d+;d.display();-d;splay();d-;d.display();cout<<endl;Calculatorer e1,e2,e3,e4,e5,e6;int p,q;cout<<"-两个计数器的运算-"<<endl;cout<<"请输入两个计数器中一个的初始值p(p的围是065535):"<<endl;cin>>p;cout<<"请输入两个计数器中另一个的初始值q(q的围是065535):"<<endl;cin>>q;e1.setcount(p);isplay();e2.setcount(q);e2.display();e3=e1+e2;e3.display();e4=e1-e2;e4.display();e5=e1*e2;e5.display();e6=e1/e2;e6.display();实验八 第六章 运算符重载 课后习题 7:建立一个二维坐标系的类TwoCoor,用x,y表示坐标值,实现两坐标点的加,减运算,计算两坐标点之间的距离,并重载输入输出运算符,使之能够直接输入输出坐标点的坐标值。#include<iostream.h>#include<math.h> class TwoCoorprivate:double x,y;public:TwoCoor(double a=0,double b=0)x=a;y=b; friend TwoCoor operator+(TwoCoor m,TwoCoor n);friend TwoCoor operator-(TwoCoor m,TwoCoor n);friend double dist(TwoCoor m,TwoCoor n);friend TwoCoor &operator<<(ostream &os,TwoCoor &s);friend TwoCoor &operator>>(istream &is,TwoCoor &s);TwoCoor operator+(TwoCoor m,TwoCoor n) TwoCoor t;t.x=m.x+n.x;t.y=m.y+n.y;return t;TwoCoor operator-(TwoCoor m,TwoCoor n)return TwoCoor(m.x-n.x,m.y-n.y);double dist(TwoCoor m,TwoCoor n)double x=(m.x-n.x);double y=(m.y-n.y);return sqrt(x*x+y*y);TwoCoor &operator<<(ostream &os,TwoCoor &s)os<<"("<<s.x<<","<<s.y<<")"return s;TwoCoor &operator>>(istream &is,TwoCoor &s)is>>s.x>>s.y;return s;void main()TwoCoor m,n,a1,a2;double a3;cout<<"两个坐标点的输入"<<endl;cout<<"请输入一个坐标点m的x,y的值(x和y用空格隔开):"<<endl;cin>>m;cout<<"请输入另一个坐标点n的x,y的值(x和y用空格隔开):"<<endl;cin>>n;cout<<"m="<<m;cout<<endl;cout<<"n="<<n;cout<<endl<<endl;cout<<"两个坐标点的运算"<<endl;cout<<"两个坐标点的加运算->"a1=m+n;cout<<"a1="<<a1;cout<<endl;cout<<"两个坐标点的减运算->"a2=m-n;cout<<"a2="<<a2;cout<<endl;cout<<"两个坐标点间的距离->"cout<<"a3="<<dist(m,n)<<endl;实验十 第九章 文件与流 课后习题 4:编写程序,将文件A1中的容复制到A2中,并在屏幕上显示文件容。#include<iostream>#include<fstream>using namespace std;#define SRCfile "F:text1.txt"#define DESfile "F:text2.txt"#define fixsize 2048void copyfile()fstream ifile(SRCfile,ios:in|ios:binary);fstream ofile(DESfile,ios:out|ios:binary);char szbuffixsize=0;int nlen=sizeof(ifile);int nread=0;while(nread<nlen)memset(szbuf,0,fixsize);if(nlen-nread)>fixsize)ifile.read(szbuf,fixsize);ofile.write(szbuf,fixsize);nread+=f

    注意事项

    本文(c课后实验.doc)为本站会员(夺命阿水)主动上传,课桌文档仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知课桌文档(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-1

    经营许可证:宁B2-20210002

    宁公网安备 64010402000986号

    课桌文档
    收起
    展开