欢迎来到天天文库
浏览记录
ID:50530918
大小:70.00 KB
页数:14页
时间:2020-03-10
《面向对象程序设计试卷A答案及评分标准.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、《面向对象程序设计》试卷A答案及评分标准本试卷共10个题,分别按以下标准评分,最后根据整个答题的情况,从程序设计风格的角度给予0-5分的附加分。1、编写程序,将从键盘读入的所有大小写字母写入名为a.txt的文件中(遇EOF结束)。(本题总分10分,fopen函数使用妥当4分,读入过程正确4分,关闭文件2分。程序结构完整,有不妥之处,酌情扣分。)#includemain(){FILE*fptr;fptr=fopen("a.txt","w");if(fptr==NULL)return0;chara;a=getchar();while(a!=
2、EOF){if(a>=’a’&&a<=’z’
3、
4、a>=’A’&&a<=’Z’)fputc(a,fptr);a=getchar();}fclose(fptr);return0;}2、定义一个矩形类Rectangle,并在main函数中用它声明一个矩形对象,然后利用接口设置该矩形对象的长和宽、计算面积并输出。(本题总分10分,类结构2分,设置矩阵对象的长与高各1分,计算面积函数2分,输出函数2分,主函数2分。程序结构完整,有不妥之处,酌情扣分。)#include#includeclassRectangle{publi
5、c:intgetArea();voidsetWidth(intw);voidsetLength(intl);private:intLength;intWidth;};intRectangle::getArea(){returnLength*Width;}voidRectangle::setLength(intl){Length=l;}voidRectangle::setWidth(intw){Width=w;}main(){intlen,wid;Rectangler1;cout<<"InputtheRectangle'sInformation"<6、l;cout<<"Lentgh:"<>len;cout<<"Width:"<>wid;r1.setLength(len);r1.setWidth(wid);cout<<"Rectangle'sArea:"<7、ude#includestructNode{intitem;structNode*next;};classIStack{public:IStack();~IStack();voidpush(intitem);intpop();intgetItemNum();private:Node*head;intsize;};IStack::IStack(){head=NULL;size=0;}IStack::~IStack(){Node*temp=head;while(temp!=NULL){temp=head->next;8、deletehead;head=temp;}}voidIStack::push(intitem){Node*temp=newNode;temp->item=item;temp->next=head;head=temp;size++;}intIStack::pop(){if(size==0){cout<<"NoIteminthestack!";return0;}Node*temp=head;head=head->next;inti=temp->item;deletetemp;returni;}intIStack::getItemNum(){return9、size;}main(){IStackistack;istack.push(6);istack.push(7);istack.push(8);cout<10、整数。最后在main函数中对上述功能进行测试。(本题总分10分,类结构2分,分数
6、l;cout<<"Lentgh:"<>len;cout<<"Width:"<>wid;r1.setLength(len);r1.setWidth(wid);cout<<"Rectangle'sArea:"<7、ude#includestructNode{intitem;structNode*next;};classIStack{public:IStack();~IStack();voidpush(intitem);intpop();intgetItemNum();private:Node*head;intsize;};IStack::IStack(){head=NULL;size=0;}IStack::~IStack(){Node*temp=head;while(temp!=NULL){temp=head->next;8、deletehead;head=temp;}}voidIStack::push(intitem){Node*temp=newNode;temp->item=item;temp->next=head;head=temp;size++;}intIStack::pop(){if(size==0){cout<<"NoIteminthestack!";return0;}Node*temp=head;head=head->next;inti=temp->item;deletetemp;returni;}intIStack::getItemNum(){return9、size;}main(){IStackistack;istack.push(6);istack.push(7);istack.push(8);cout<10、整数。最后在main函数中对上述功能进行测试。(本题总分10分,类结构2分,分数
7、ude#includestructNode{intitem;structNode*next;};classIStack{public:IStack();~IStack();voidpush(intitem);intpop();intgetItemNum();private:Node*head;intsize;};IStack::IStack(){head=NULL;size=0;}IStack::~IStack(){Node*temp=head;while(temp!=NULL){temp=head->next;
8、deletehead;head=temp;}}voidIStack::push(intitem){Node*temp=newNode;temp->item=item;temp->next=head;head=temp;size++;}intIStack::pop(){if(size==0){cout<<"NoIteminthestack!";return0;}Node*temp=head;head=head->next;inti=temp->item;deletetemp;returni;}intIStack::getItemNum(){return
9、size;}main(){IStackistack;istack.push(6);istack.push(7);istack.push(8);cout<10、整数。最后在main函数中对上述功能进行测试。(本题总分10分,类结构2分,分数
10、整数。最后在main函数中对上述功能进行测试。(本题总分10分,类结构2分,分数
此文档下载收益归作者所有