首页 程序设计与问题求解

程序设计与问题求解

举报
开通vip

程序设计与问题求解..PAGE..word.zl.电子科技大学试卷2021-2021学年第2学期A卷课号课程名称程序设计与问题求解2适用班级〔专业〕考试时间120分钟座位号学号题号一二三四五六七八成绩总分值502030得分评卷人一、阅读程序,写出程序运行结果〔每题10分,5题共50分〕1.构造体#include#includeusingnamespacestd;structWorker{charname[15];//intage;//年龄f...

程序设计与问题求解
..PAGE..word.zl.电子科技大学 试卷 云南省高中会考试卷哪里下载南京英语小升初试卷下载电路下试卷下载上海试卷下载口算试卷下载 2021-2021学年第2学期A卷课号课程名称程序 设计 领导形象设计圆作业设计ao工艺污水处理厂设计附属工程施工组织设计清扫机器人结构设计 与问题求解2适用班级〔专业〕考试时间120分钟座位号学号题号一二三四五六七八成绩总分值502030得分评卷人一、阅读程序,写出程序运行结果〔每题10分,5题共50分〕1.构造体#include#includeusingnamespacestd;structWorker{charname[15];//intage;//年龄floatpay;//工资};voidmain(){WorkerWorker1,Worker2;char*t="liouting";intd=38;floatf=493;strcpy(Worker1.name,t);Worker1.age=d;Worker1.pay=f;cout<usingnamespacestd;classTAdd{private:intx,y;public:TAdd(inta,intb):x(a),y(b){cout<<"调用构造函数1."<usingnamespacestd;classA{public:virtualvoidf(){cout<<"A::f()executing\n";}};classB:publicA{public:voidf(){cout<<"B::f()executing\n";}};voidmain(){Aa;Bb;b.f();A*p=&a;p->f();p=&b;p->f();a=b;a.f();}输出结果是:B::f()executingA::f()executingB::f()executingA::f()executing4.模板#includeusingnamespacestd;templateclassmyclass{private:Type1i;Type2j;public:myclass(Type1a,Type2b){i=a;j=b;}voidshow(){cout<ob1(1,3);myclassob2(10,0.23);myclassob3('A',"Thisisatest");ob1.show();ob2.show();ob3.show();}输出结果是:13100.23AThisisatest5.继承#includeusingnamespacestd;classA{intx,y;public:A(intx1=0,inty1=0):x(x1),y(y1){cout<<"A:"<#includeusingnamespacestd;//词条类型structWordList{charword[50];intfreq;};//词典排序函数voidSort(WordListlist[],intcount){for(inti=0;ii;j=j-1)if(strcmp(list[j-1].word,list[j].word)>0){WordListtmp;tmp=list[j-1];list[j-1]=list[j];list[j]=tmp;}}//主函数:进展词频统计intmain(){WordListlist[5000];inti,num=0;chartemp[50];cout<<"请输入一系列英语单词,以xyz表示输入完毕"<>temp;while(〔1〕){for(i=0;i=num)//假设词典中无该词条,添加该词{strcpy(list[i].word,temp);〔3〕〔4〕}〔5〕//继续输入单词}Sort(list,num);//对词典进展排序//输出词典cout<<"词频统计结果如下:"<>temp;2.带头结点链表类的定义如下:#include#includeusingnamespacestd;template//模板声明classNODE//结点类定义{public:datatypedata;//数据域NODE*next;//指针域};templateclassList//单链表类定义{private:NODE*head;//链表头指针public:List();//构造函数创立头结点intlength();//求表长函数boolisempty(){returnhead->next==NULL?true:false;}//判空链表函数boolinsert_data(datatypedata,inti);//插入元素函数……………~List();//析构函数};templateboolList::insert_data(datatypedata,inti)//定义插入函数{NODE*current,*previous,*newnode;intj=1;if((i>length()+1)||(i<0))//判插入位置的合法性{cout<<"插入位置不正确,不能插入!\n";returnfalse;}newnode=newNODE;//申请新结点空间if(newnode==NULL)//判表满否{cout<<"存无空闲空间,不能插入!\n";returnfalse;}newnode->data=data;newnode->next=NULL;previous=head;〔6〕while((7))//寻找第i个元素{previous=current;(8)//指向下一个结点j++;};//链入新结点(9)(10)returntrue;}答案:(6)current=head->next;(7)current!=NULL&&jnext;(9)newnode->next=current;(10)previous->next=newnode;三、程序设计〔每题15分,2题共30分〕1.设计一个时间(Time)类,设计多个重载的构造函数,可以设置时间,时间加运算〔时间加多少秒〕,要求重载+来实现时间加运算,按24小时制格式:时:分:秒输出时间。并在主程序中测试所有的操作。(15分)#pragmaonce/*时间类*/classTime{intsecond,minute,hour;intGetSecond();//计算总秒数voidSetTime(intss);//根据秒数算出second,minute,hourpublic:Time();Time(inthh,intmm,intss);voidSetTime(inthh,intmm,intss);constTime&operator+(intss);booloperator<(Time&);voidPrint_hms();//HH:mm:ss};#include"Time.h"#includeusingnamespacestd;Time::Time(){second=0;minute=0;hour=0;}Time::Time(inthh,intmm,intss){SetTime(hh,mm,ss);}//计算总秒数intTime::GetSecond(){returnsecond+60*minute+3600*hour;}voidTime::SetTime(intss){second=ss%60;ss=ss/60;minute=ss%60;ss=ss/60;hour=ss%24;}voidTime::SetTime(inthh,intmm,intss){second=(ss>=0&&ss<60)?ss:0;minute=(mm>=0&&mm<60)?mm:0;hour=(hh>=0&&hh<24)?hh:0;}constTime&Time::operator+(intss){SetTime(GetSecond()+ss);return*this;}boolTime::operator<(Time&time){if(GetSecond()-time.GetSecond()<0)returntrue;elsereturnfalse;}voidTime::Print_hms(){cout<usingnamespacestd;intmain(){Timet1,t2;inthour,minute,second;cout<<"请输入时间〔时分秒〕:"<>hour>>minute>>second;t1.SetTime(hour,minute,second);t1.Print_hms();t2.SetTime(12,0,0);if(t1usingnamespacestd;classperson{intno;charname[10];public:virtualvoidinput(){cout<<"thenois";cin>>no;cout<<"thenameis";cin>>name;}virtualvoidoutput(){cout<<"thenois"<>salary;}voidoutput(){person::output();cout<<"theemployeesalaryis"<>post;}voidoutput(){person::output();cout<<"theemployerpostis"<input();p->output();p=&er;p->input();p->output();}输出结果:thenois01thenameiswanghongtheemployeesalaryis1000thenois1thenameiswanghongtheemployeesalaryis1000thenois02thenameislizhetheemplorerpostisbossthenois2thenameislizhetheemployerpostisboss评分说明:头文件2分;person类的两虚函数各2分;employee类和employer类的公有继承各2分;employee类和employer类对虚函数的重载各2分;employee类和employer类对象赋给person类指针各2分;输出结果2分。教育之通病是教用脑的人不用手,不教用手的人用脑,所以一无所能。教育革命的对策是手脑联盟,结果是手与脑的力量都可以大到不可思议。
本文档为【程序设计与问题求解】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
个人认证用户
ysdg83
从事建筑公司质量、技术
格式:doc
大小:76KB
软件:Word
页数:12
分类:教育学
上传时间:2021-11-23
浏览量:1