C++上机实验报告实验一.docx

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C上机实验报告实验一概要

实验一 Exercise 1 1.实验目的 1.熟悉Microsoft Visual C++6.0集成开发环境 2.学习创建控制台应用程序项目 3.编辑源程序 4.编译和调试程序 2.实验要求 1.熟悉程序开发环境 2.编辑源程序 3.编译并调试程序 3.实验内容 1.熟悉Microsoft Visual Studio 6.0 的开发环境 2.编辑并调试下面的程序 注:工程中的文件包括三个:TimeType.h、TimeType.cpp、Diary.cpp 4.源程序 class TimeType{ public: void Set(int hours,int minutes,int seconds); void Increment(); void Write();// const; bool Euqal(TimeType otherTime) ;//const; bool LessThan(TimeType otherTime);//const; private: int hrs; int mins; int secs; }; #includeTimeType.h #includeiostream using namespace std; void TimeType::Set(int hours,int minutes,int seconds) { hrs=hours; mins=minutes; secs=seconds; }//Set() void TimeType::Increment() { secs++; if(secs59){ secs=0; mins++; if(mins59){ mins=0; hrs++; if(hrs23) hrs=0; } } }//Increment() void TimeType::Write() //const { couthrs:; if(mins10) cout0; coutmins:; if(secs10) cout0; coutsecs; }//Write() bool TimeType::Euqal(TimeType otherTime)//const { return(hrs==otherTime.hrsmins==otherTime.minssecs==otherTime.secs); } bool TimeType::LessThan(TimeType otherTime)//const { return(hrsotherTime.hrs||hrs==otherTime.hrsminsotherTime.mins||hrs==otherTime.hrsmins==otherTime.minssecsotherTime.secs); } #includeiostream #includeTimeType.h using namespace std; int main() { TimeType time; TimeType othertime; int hours; int minutes; int seconds; coutEnter a time (use hours0 to quit):; cinhoursminutesseconds; while(hours=0)//while(hours=0) { time.Set(hours,minutes,seconds); time.Increment();//设置时间量 coutIncremented time is; time.Write();//输出时间 coutendl; coutEnter a time(use hours0 to quit):; cinhoursminutesseconds;//输入另一个时间量 othertime.Set(hours,minutes,seconds); if(time.Euqal(othertime))//判断两个时间的大小关系 couttime is equal to othertimeendl; else if(time.LessThan(othertime)) couttime is lessthan to othertimeendl; else couttime is morethan to othertimeendl; }//while return 0; } 5.运行结果 1.创建工程和文件 2.调试时间程序 6.心得体会 通过练习一,进一步了解了Microsoft

文档评论(0)

6663144 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档