ImageVerifierCode 换一换
格式:DOC , 页数:18 ,大小:239.50KB ,
资源ID:2302295      下载积分:8 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/2302295.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文(《面向对象程序设计》实验报告[二].doc)为本站上传会员【精***】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

《面向对象程序设计》实验报告[二].doc

1、 计算机科学与工程学院 《面向对象程序设计》实验报告[二] 专业班级 2017数字媒体技术01 实验地点 J411 学生学号 1705121411 指导教师 陈艳 学生姓名 黄浩博 实验时间 实验项目 类的定义及应用(6学时) 实验类别 基础性() 设计性(√) 综合性() 其它( ) 实验目的及要求 1.掌握类定义的语法;

2、 2.掌握构造函数和析构函数的定义; 3.掌握几个关键字的用法:this、const、new/delete、friend 4.综合应用类的封装性解决常见问题; 5.完成实验内容,调试通过后将完整代码及运行截图粘贴到实验结果对应的题号下面; 6.对本次实验进行总结(遇到的问题,可行的解决方案,收获,体会等等) 7.完成实验报告后,以学号+姓名+实验2(.doc或.docx)为名上传到ftp://218.199.185.223/student/上传作业/陈艳/面向对象程序设计下对应班级及实验项目文件夹中 成 绩 评 定 表 类 别 评 分 标 准 分值 得分 合

3、 计 上机表现 积极出勤、遵守纪律 主动完成设计任务 30分 程序与报告 程序代码规范、功能正确 报告详实完整、体现收获 70分 说明: 评阅教师: 日 期: 年 月 日 实 验 内 容 题目1: 下面设计一个三角形类,请按下列声明形式完成各成员函数的定义。添加主程序中初始化该类,并调用成员函数测试结果。 #include

4、 using namespace std; class Triangle{ public: void Setabc(doublex, doubley, doublez); //设置三条边的值,注意要能成三角形 double Perimeter( ); //计算三角形的周长 double Area( ); //计算并返回三角形的面积 private: double a,b,c; //三条边的长度为私有数据成员 }; 题目2: 定义一个正方形类Square,编写构造函数、析构函数,Set()/Get()函数以 设置/读取边长,perimeter()

5、函数和area函数分别求周长和面积。并在主程序中进行测试。 题目3: 定义时间类Time,并计算两个时间之间的间隔。 题目4: 定义Student类(包含3个数据成员name,id_number,score),计算班上30个学生的平均成绩,并按成绩高到低顺序输出高于平均成绩的学生信息。 题目5:从 定义复数类,实现实部、虚部的读写,复数计算,结果输出等功能。并在主程序中进行测试。 题目6: 定义Point类和Line类(Line类的成员是Point的对象——复合),在主程序中进行测试,体会构造函数、析构函数、赋值运算符函数、拷贝构造函数的调用。 实 验 结 果

6、 题目1: #include #include using namespace std; class Triangle{ public: void Setabc(double x, double y, double z); double Perimeter(); double Area(); private: double a,b,c; }; int main(){ double a,b,c; cout<<"Please enter the triangle's a,b,c:"; cin>>a>>b

7、>>c; Triangle triangle; triangle.Setabc(a,b,c); double len=triangle.Perimeter(); double s=triangle.Area(); cout<<"The triangle's Perimeter is :"<

8、{ a=x;b=y;c=z; } double Triangle::Perimeter(){ double len; len=a+b+c; return len; } double Triangle::Area(){ double p=(a+b+c)/2; double s=sqrt(p*(p-a)*(p-b)*(p-c)); return s; } 题目2: #include class Square{ private: double m_a; public: S

9、quare(); ~Square(); void Set(double a); void Get(); double Perimeter(); double Area(); }; int main(){ Square square; std::cout<<"Please enter the square's length:"; double a,b,c; std::cin>>a; square.Set(a); square.Get(); b=square.Perimete

10、r(); c=square.Area(); std::cout<<"The square's Perimeter is :"<

11、} void Square::Set(double a){ m_a=a; } void Square::Get(){ std::cout<<"The square's length is:"< class Time{ private: int m_ho

12、ur,m_minute,m_second; public: Time(){std::cout<<"This is a new time."<

13、e time in chronological order."; for(int a=0;a<2;a++){ std::cout<<"Please enter the time:(second minute,hour)"<>s>>m>>h; time[a].Set(s,m,h); } time[1].Interval(time[0]); return 0; } void Time::Interval(Time S){ int s,m,h;

14、 bool flag1(0),flag2(0); if(this->m_second>S.m_second) s=this->m_second-S.m_second; else { s=60+this->m_second-S.m_second; flag1=1; } if(flag1) this->m_minute--; if(this->m_minute>S.m_minute) m=this->m_minute-S.m_minute; else

15、 { m=60+this->m_minute-S.m_minute; flag2=1; } if(flag2) this->m_hour--; h=this->m_hour-S.m_hour; std::cout<<"The time interval is:(hour,minute,second) "<

16、UDED #define STUDENT_H_INCLUDED #include using std::string; class Student{ private: string m_name; long int m_id; float m_score; public: Student(string name="None",long int id=0,float score=0):m_name(name),m_id(id),m_score(score){}; void Set(string name,long in

17、t id,float score){m_name=name;m_id=id;m_score=score;}; float Interval(){return m_score;}; void pri(){std::cout<<"The name is "<m_score>a.m_score) return true ;else return false;};

18、}; #endif // STUDENT_H_INCLUDED main.cpp #include #include"Student.h" const int n=30; int scan(Student [],int ); void sear(Student []); void prin(Student [],float ); int main(){ Student student[n]; int x=0; float sum(0); x=scan(student,x); for(int a=0;

19、a>ch;s

20、td::cin.get(); for(int a=0;a>name>>id>>score; std::cin.get(); student[a].S

21、et(name,id,score); x++; std::cout<<"Enter q to quit."<>ch;std::cin.get(); } return x; } void sear(Student student[n]){ for(int a=0;a

22、 Student c; c=student[a];student[a]=student[b];student[b]=c; } } } } void prin( Student student[n],float x){ for(int a=0;ax){ student[a].pri(); }

23、else continue; } } 题目5: Comp.h #ifndef COMP_H_INCLUDED #define COMP_H_INCLUDED class Comp { private: int real,imag; public: Comp(int r=0,int i=0):real(r),imag(i){}; ~Comp(){}; void cset(int ,int ); void cput(); Comp operator+(const Comp &com) cons

24、t; Comp operator-(const Comp &com) const; Comp& operator=(const Comp &com); }; #endif // COMPLEX_H_INCLUDED main.cpp #include #include"Comp.h" void sca(Comp [],int ); void pri(Comp [],int ); int main(){ Comp a[3]; Comp b[3]; sca(a,3); std::cout<<"The

25、 a[3] :"; pri(a,3); b[0]=a[0]+a[1]; b[1]=a[0]-a[2]; b[2]=a[0]; std::cout<<"The b[3] :"; pri(b,3); return 0; } void Comp::cset(int r,int i){ real=r; imag=i; } void Comp::cput(){ std::cout<<"The complex's real is "<

26、<"The complex's image is "<real+com.real; sum.imag=this->imag+com.imag; return sum; } Comp Comp::operator-(const Comp &com) const{ Comp sum; sum.real=this->real-com.real;

27、sum.imag=this->imag-com.imag; return sum; } Comp& Comp::operator=(const Comp &com){ this->real=com.real; this->imag=com.imag; return *this; } void sca(Comp a[],int n){ for(int x=0;x

28、 std::cin>>real; std::cout<>imag; a[x].cset(real,imag); } } void pri(Comp a[],int n){ for(int x=0;x

29、 int m_x, m_y; public: Point(int x = 0, int y = 0) :m_x(x), m_y(y) {}; ~Point() {}; void pset(int x, int y) { m_x = x; m_y = y; }; void pput(); Point operator+(const Point& point) const; Point operator-(const Point& point) const; Point& operator=(const Point& point); }; class Lin

30、e { private: Point m_start, m_end; public: Line(int x1=0, int y1=0, int x2=0, int y2=0) :m_start(x1, y1), m_end(x2, y2) {}; ~Line() {}; void lput(); void lset(Point s, Point e) { m_start = s, m_end = e; }; Line operator+(const Line& line) const; Line operator-(const Line& line) const

31、 Line& operator=(const Line& line); }; #endif Line.cpp #include #include"Line.h" using std::cout; using std::endl; Point Point::operator+(const Point& point) const { Point p; p.m_x = this->m_x + point.m_x; p.m_y = this->m_y + point.m_y; return p; } Point Point::op

32、erator-(const Point& point) const { Point p; p.m_x = this->m_x - point.m_x; p.m_y = this->m_y - point.m_y; return p; } Point& Point::operator=(const Point& point) { this->m_x = point.m_x; this->m_y = point.m_y; return *this; } void Point::pput() { cout << m_x << "," << m_y << end

33、l; } Line Line::operator+(const Line& line) const { Line l; l.m_start = this->m_start + line.m_start; l.m_end = this->m_end + line.m_end; return l; } Line Line::operator-(const Line& line) const { Line l; l.m_start = this->m_start - line.m_start; l.m_end = this->m_end - line.m_end;

34、 return l; } Line& Line::operator=(const Line& line) { this->m_start = line.m_start; this->m_end = line.m_end; return *this; } void Line::lput() { cout << "The start point's x,y is:"; m_start.pput(); cout << "The end point's x,y is:"; m_end.pput(); cout<

35、 #include #include"Line.h" using std::cin; using std::cout; using std::endl; void pscan(Point[], int n); void lscan(Line[], Point [], int n,int m); void lprin(Line[], int); int main() { Point p[6]; pscan(p, 6); Line line[6]; lscan(line, p, 6, 6); line[3] = line[1] + line[

36、0]; line[4] = line[0] - line[2]; line[5]=line[0]; lprin(line, 6); return 0; } void pscan(Point p[], int n) { int x, y; for (int m = 0; m < n; m++) { cout << "Please enter x,y:"; cin >> x >> y; p[m].pset(x, y); } } void lscan(Line l[], Point p[], int n,int m) { for (int x

37、 = 0,y=0; x < n&&x < m; x++,y++,y++) { l[x].lset(p[y], p[y+1]); } } void lprin(Line l[], int n) { for (int x = 0; x < n; x++) { cout << "The line "<

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服