还剩2页未读,继续阅读
文本内容:
f翻教有科学马枝术学浣INSTITUTE OFEDUCATION SCIENCEAND TECHNOLOGY本科实验报告课程名称面向对象程序设计实验项目类与对象程序设计实验地点________慎思楼505专业班级教本一班学号14学生姓名____________聂子建指导教师____________刘立云年月日
20151016、实验目的和要求掌握类的定义和使用、成员函数的定义和使用;1掌握类的私有成员、公有成员和保护成员的区别;2掌握对象的定义、类成员的访问;3掌握类中构造函数与析构函数的应用4掌握重载函数的定义和使用5
二、实验内容和原理请检查下面程序,找出错误并改正然后上机调试,使之能正常运行运行时从键盘输入时、分、秒的值,检查输出是否正确
三、主要仪器设备HP6460b;Visual Studio2008软件环境
四、操作方法与实验步骤源程序#includeiostream.hclass Time{void set_timevoid;void show_timevoid;int hour;int minute;int sec;;Time t;int main{set_time;show_time;}void set_timevoid{cint.hour;cint.minute;cint.sec;void show_timevoid{coutt.hour〈〈〃:〃〈〈t・minute/z:〃〈t・secendl;}修改后程序#includeiostream.hclass Time{public:int hour;int minute;int sec;;Time t;void set_timevoid{cin»t.hour;cin»t.minute;cin»t.sec;void show_timevoid{cout«t.hour«n:n«t.minute«n:n«t.sec«endl;}int main{set_time;show_time;return0;程序错误作业f:\c++\22\l.cppll:error C2065:set_time:undeclared identifierf:\c++作业\22\l.cpp12:error C2065:show_timeundeclared identifier作业f:\c++\22\l.cpp13:warning C4508:main:function shouldreturn avalue;voidreturn typeassumed作业f:\c++\22\l.cpp15:error C2373:set_time:redefinition;different typemodifiers作业f:\c++\22\l.cpp15:error C2248:hour:cannot accessprivate memberdeclared inclassTime*作业f:\c++\22\l.cpp5:see declarationofhourf:\c++^^lk\22\l.cpp16:error C2248:minute:cannot accessprivate memberdeclaredin classTime作业f:\c++\22\l.cpp6:see declarationofminutef:\c++{^^lk\22\
1.cpp17:error C2248:sec:cannot accessprivate memberdeclared inclassTime作业f:\c++\22\l.cpp7:see declarationofsec作业f:\c++\22\l.cpp20:error C2373:show_time:redefinition;different typemodifiers作业f:\c++\22\l.cpp20:error C2248:hour:cannot accessprivate memberdeclared inclassTime,作业f:\c++\22\l.cpp5:see declarationofhour作业f:\c++\22\Lcpp20:error C2248:minute:cannot accessprivate memberdeclared inclassTime!作业f:\c++\22\l.cpp6:see declarationofminute作业f:\c++\22\l.cpp20:error C2248:sec:cannot accessprivate memberdeclared inclassTime作业f:\c++\22\l.cpp7:see declarationofsec
五、实验数据记录和处理12253412:25:34Press anykey tocontinue
六、实验结果与分析函数和函数放在类的类体中,这表示是类的成1set_time show_time TimeTime员函数,但是在定义这两个函数时是按一般函数定义的在函数中调用函数和函数,而这两个函数是在2main set_time show_time main函数之后定义的,而在函数中并未对这两个函数进行声明main
七、讨论、心得通过这次实验可以深刻体会到类的作用,熟悉了类的定义和使用、成员函数的定义和使用掌握类的私有成员、公有成员和保护成员的区别而在类中函数的调用离不开对象,掌握对象的定义、类成员的访问十分必要,简介明了的语句使程序易懂类中构造函数与析构函数的应用,则是十分基础与必要的从重载函数的使用中也体会到重载函数的简介性体会到很多与语言不同的东西,显得更为“人性化”,可读性、可操作C C++性强。
个人认证
优秀文档
获得点赞 0