




已阅读5页,还剩20页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
在准备2012年东南大学计算机复试笔试期间,我将2010和2011年的笔试编程题目进行了精心的编码。并很高心提供给以后的考生参考。以下源代码均经过Visual studio 6.0调试通过,仅供参考。代码由:hbfxzhy提供)题目:和该参考代码共同打包2010年,第一题:#include using std:cout;using std:cin;using std:cerr;using std:endl;using std:ios;#include using std:ofstream;#include #include int convertToDec(char *,int);void main()const int SIZE=30;char datasSIZE;int decs;cout请输入一行二进制代码:;int i=0,n; while(datasi=cin.get()!=n)i+; decs=convertToDec(datas,i); ofstream outFile(output.txt,ios:out);if(!outFile)cerrFile could not be openedendl;exit(1);srand(time(0);n = rand()%10 +1;coutdecs nendl; while(n-)outFiledecsendl;int convertToDec(char data,int size)int decNum=0;int temp;for(int i=0;isize;i+)temp=(int)datai-48;decNum=decNum * 2;decNum+=temp;return decNum;第二题:#include using std:cout;using std:endl;using std:cerr;using std:ios;#include using std:ifstream;#include #include void print(char *str1, int size) for(int i=0;isize;i+)coutstr1i;cout|;void main()char temp100;char *name;char *age;char *mobel;ifstream inFile=ifstream(input.txt,ios:in); if(!inFile)cerrtemp;/couttemp) char * tokenPtr=strtok(temp,;); name=tokenPtr; coutname|; tokenPtr=strtok(NULL,;); age=tokenPtr; coutage|; tokenPtr=strtok(NULL,;); print(tokenPtr+8,8); print(tokenPtr+1,6); tokenPtr=strtok(NULL,;); mobel=tokenPtr; couttokenPtrendl; 第三题:/a0做为哨兵,实现升序排列#include using std:cout;using std:endl;template void dieDai_Sort(T1 *s,int size);template void diGui_Sort(T1 *s,int size);void main()int s11=0,1,3,2,5,4,8,6,7,9,0;double s18=0,0.4,0.2,0.6,0.3,0.9,0.5,0.7;/diGui_Sort(s,10);dieDai_Sort(s1,7);for(int i=1;i8;i+)couts1i ;coutendl;template void dieDai_Sort(T1 *s,int size)for(int i=2;i=size;i+)s0=si;for(int j=i-1;s0sj;j-)sj+1=sj;sj+1=s0;template void diGui_Sort(T1 *s,int size)if(size1)diGui_Sort(s,size-1);s0=ssize;for(int i=size-1;s0si;i-)si+1=si;si+1=s0;第四题:#ifndef POLYNOMIAL_H#define POLYNOMIAL_H#include using std:ostream;class Polynomial friend ostream& operator(ostream&,const Polynomial&);public:Polynomial(const double *,int len); Polynomial(const Polynomial &p); Polynomial(); void setPolynomial(const double *);int getLength() const;void setLength(int );Polynomial& operator+(Polynomial &p);private:double *poly;int length;#endif#include using std:cout;using std:endl;using std:ostream;#include using std:setw;#include #include #include #include polynomial.hPolynomial:Polynomial(const double *polyPtr,int len):length(len)setPolynomial(polyPtr);Polynomial:Polynomial(const Polynomial ©):length(copy.length)setPolynomial(copy.poly);Polynomial:Polynomial()deletepoly;int Polynomial:getLength() constreturn length;void Polynomial:setLength(int len)length=len;void Polynomial:setPolynomial(const double *p)poly= new doublelength;for(int i=0;ip.length ? length:p.length);double *tempPtr= new doublesizes;for(int i=0;ilength & ip.length;i+)tempPtri=polyi+p.polyi;if(lengthp.length)for(;ip.length;i+)tempPtri=p.polyi;elsefor(;ilength;i+)tempPtri=polyi; return * new Polynomial(tempPtr,sizes);ostream &operator0;i-)if(p2.polyi!=0) outputp2.polyi*Xi + ;outputp2.poly0endl;return output;#include using std:cout;using std:endl;#include polynomial.hvoid main()double polys17=1,2.3,4.0,5,6.7,8.9,1.9;double polys23=3.2,1.4,0; Polynomial p2(polys2,3);Polynomial p1(polys1,7);coutp1endlp2endl;p2=p2+p1;coutp2;第五题:#ifndef BRAKE_H#define BRAKE_Hclass Brakepublic:Brake(bool isPut);Brake(const Brake& );void setPut(bool);bool getPut();private:bool isPut;#endif#include #include brake.hBrake:Brake(bool put):isPut(put)Brake:Brake(const Brake &brake)isPut=brake.isPut;void Brake:setPut(bool put)isPut=put ;bool Brake:getPut()return isPut;#ifndef STREETWHEEL_H#define STREETWHEEL_Hclass StreetWheelpublic:StreetWheel(double angle=0,int direction=0);StreetWheel(const StreetWheel& streetwheel);void setAngle(double angle);void setDirection(int direction);double getAngle();int getDirection();void print();private:double angle;int direction;#endif#include using std:cout;using std:endl;#include streetwheel.hStreetWheel:StreetWheel(double angle0,int direction0)angle=angle0;direction=direction0;StreetWheel:StreetWheel(const StreetWheel &streetWheel)angle=streetWheel.angle ;direction=streetWheel.direction;void StreetWheel:setAngle(double angle0)angle=angle0;void StreetWheel:setDirection(int direction0)direction=direction0;double StreetWheel:getAngle()return angle;int StreetWheel:getDirection()return direction;void StreetWheel:print()coutNow the cars direction is:(direction 0 ? left : right )angledegreen;#include using std:cout;using std:endl;class Vehiclepublic:Vehicle(char * names)length=(strlen(names);name=new charlength+1;strcpy(name,names);coutCreate a new Vehicle,name is:name!n;char * getName()return name;private:char *name;int length;#include using std:cout;using std:endl;#include brake.h#include streetwheel.h#include vehicle.h#include class Car:public Vehiclepublic:Car(char *names,const Brake &brake0,const StreetWheel &streetWheel0):Vehicle(names),brake(brake0),streetWheel(streetWheel0)void setBrake(bool put)brake.setPut(put);void setStreetWheel(double ang,int direct)streetWheel.setAngle(ang);streetWheel.setDirection(direct); void print()coutThe cars name is:getName()endl;coutThe brake is now:(brake.getPut() ? put :pop )endl;streetWheel.print();private:Brake brake;StreetWheel streetWheel;void main()Brake brake(false);StreetWheel streetWheel(30,-1);Car car(BaoMa,brake,streetWheel);car.print();car.setBrake(true);car.setStreetWheel(20,1);car.print();第六题:#ifndef SHAPE_H#define SHAPE_H#include using std:string;class Shapepublic:virtual double getArea()const;virtual double getVolume()const;virtual string getName()const=0;virtual void print()const=0;double Shape:getArea ()constreturn 0.0;double Shape:getVolume ()constreturn 0.0;#endif#ifndef POINT_H#define POINT_H#include using std:cout;#include using std:string;#include shape.hclass Point:public Shapeprivate:int x;int y;public:Point(int =0,int =0);void setX(int);int getX()const;void setY(int);int getY()const;virtual string getName()const;virtual void print()const;Point:Point(int xValue ,int yValue):x(xValue),y(yValue)void Point:setX(int xValue)x=xValue;int Point:getX ()constreturn x;void Point:setY(int yValue)y=yValue;int Point:getY ()constreturn y;string Point:getName ()constreturn Point;void Point:print ()constcoutgetX(), getY();#endif#ifndef CIRCLE_H#define CIRCLE_H#include using std:cout;#include point.h#include using std:string;class Circle:public Pointpublic:Circle(int xValue,int yValue,double radiusValue):Point(xValue,yValue)radius=radiusValue;double getRadius()constreturn radius;double getDiameter()constreturn 2*getRadius();double getArea()constreturn 3.14159*getRadius()*getRadius();string getName()constreturn Circle;void print()constcoutcenter is;Point:print();cout;radius is getRadius();private:double radius;#endif#include using std:cout;using std:endl;using std:fixed;#include using std:setprecision;#include using std:vector;#include shape.h#include point.h#include circle.hvoid virtualViaReference(const Shape &baseclassRef)coutbaseclassRef.getName (): ;baseclassRef.print ();coutnarea isbaseclassRef.getArea();coutnvolume isbaseclassRef.getVolume()endlendl;void main()coutfixedsetprecision(2);Point point(7,11);Circle circle(22 ,8 ,3.5);coutpoint.getName(): ;point.print();coutn;coutcircle.getName(): ;circle.print();coutn;vector shapeVector(2);shapeVector0 = &point;shapeVector1 = &circle;for(int i=0; ishapeVector.size() ;i+)virtualViaReference(*shapeVectori);2011,第一题:#include using std:cout;using std:endl;using std:cin;using std:fixed;#include using std:setprecision;#include void main()double x,temp=1,sum=1;coutfixedsetprecision(12)x;coutx=1e-10; i+)temp=temp*x/i;couttempendl;sum+=temp;coutthe numbers of the items is:i-1tsums is:sumttemp is:tempendl;cout1e-10;第二题:#include using std:cout;using std:cin;using std:endl;#include #include using std:setprecision;void main()int pause;int size=sizeof(double)*8;double Pi=0,temp=4;int sign=-1;cout=pow(2.0,-1*size);i+=2)temp=4.0/i;sign=sign*(-1);temp=temp*sign;couttemppause;coutPi;第三题:#include using std:cout;using std:endl;using std:cin;template void diGui_Min(const T *s,int &minNum,int len)if(len0) diGui_Min(s ,minNum, len-1); if(sminNum=slen) minNum=len;else if(len=0) minNum=(sminNum=s0 ? 0:minNum );void main()int a10=3,2,1,9,8,7,0,6,5,4;int min=0;diGui_Min(a,min,9);coutmin;第四题:#include using std:cout;using std:endl;using std:cin;#include void SortOne(char *,int length);void SortTwo(char *,int length);void main()char *s1=nishishuya!;int length1=strlen(s1);char *s2=new charlength1+1;strcpy(s2,s1); s2length1=0;coutlength1endl;SortTwo(s2,length1);couts2;/该数组选择0号元素位置为哨兵void SortOne(char*s,int length)for(int i=2;is0;j-)sj+1=sj;sj+1=s0;void SortTwo(char *s,int length)int k;char temp;for(int i=0;ilength;i+)k=i;for(int j=i+1;jsj)k=j; if(k!=i)temp=si;si=sk;sk=temp;第五题:#include using std:cout;using std:endl;using std:cin;#include using std:setw;#include template class Arraypublic:Array(int,int);Array();/Array(const Array ©);void setArray(T *);T& operator()(int rowValue,int colValue);int getRow()constreturn row;int getCol()constreturn col;private:int row;int col;T *ptr;template Array:Array(int row,int col):row(row),col(col)int length=row*col;ptr=new Tlength;template Array:Array()delete ptr;/*template Array:Array(const Array ©)row=copy.row;col=copy.col;ptr=&(new Trow*col);for(int i=0;irow;i+)for(int j=0;jcol;j+)ptrij=copy.ptrij;*/template void Array:setArray(T *p) T *q=ptr;T *p_end=p+row*col;for(;pp_end;p+,q+)*q=*p;template T& Array:operator () (int row1,int col1)return (*(ptr+col*row1+col1);void main()int as4=1,2,3,4,5,6,7,8,9;Array array(3,4);array.setArray(*as);for(int i=0;iarray.getRow();i+)for(int j=0;jarray.getCol();j+) coutsetw(10)array(i,j);coutendl;第六题:#ifndef SHAPE_H#define SHAPE_Hclass Shapepublic:virtual double getArea()const;double Shape:getArea()constreturn 0.0;#endif#ifndef REC_H#define REC_H#include #include shape.hclass Rec:public Shapepublic:Rec(int x3,int y3,int x2,int y2):x0(x3),x1(x2),y0(y3),y1(y2)double getArea()constreturn fabs(x0-x1)*fabs(y0-y1);private:int x0;int y0;int x1;int y1;#endif#ifndef TRI_H#define TRI_H#include shape.h#include class Tri:public Shapepublic:Tri(int x3,int y3,int x4,int y4,int x5,int y5):x0(x3),y0(y3),x1(x4),y1(y4),x2(x5),y2(y5)double getArea()constdouble a= sqrt(x0-x1)*(x0-x1)+(y0-y1)*(y0-y1);double b= sqrt(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);double c= sqrt(x2-x0)*(x2-x0)+(y2-y0)*(y2-y0); /couta is:atb is:btc is:cendl;double p=(a+b+c)/2;/coutp is:pendl;/cout(p-a)*(b-p)*(c-p)*pendl;return sqrt(p-a)*(b-p)*(c-p)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 性与健康教程试卷及答案
- 2025年高考物理力学试卷及答案
- 2025年不锈钢、镍纤维及纤维毡项目规划申请报告
- 安全用气培训计划课件
- 法院网络安全培训内容课件
- 脱硫阀门检修试卷及答案
- 法的正义价值课件
- 法的基本知识课件
- 法理学课件张文显
- 公交星级考试试题及答案
- 2024版2025秋贵州黔教版综合实践活动五年级上册全册教案教学设计
- 转作风重实干课件
- 《工程勘察设计收费标准》(2002年修订本)
- 个人贷款管理办法(2024年第3号)
- 小学语文课程与教第二章:小学语文课程教材
- 苏教版一年级上册科学素材期末复习知识点总结
- 废铅酸电池中回收高纯度金属铅和α-PbO新工艺及其电化学性能研究
- 露天停车场施工方案
- 山东省青岛第三十九中学2023-2024学年九年级上学期月考数学试卷(10月份) (月考)
- GB/T 43063-2023集成电路CMOS图像传感器测试方法
- 作文格子纸-word版本
评论
0/150
提交评论