已閱讀5頁,還剩20頁未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
在準(zhǔn)備2012年東南大學(xué)計(jì)算機(jī)復(fù)試筆試期間,我將2010和2011年的筆試編程題目進(jìn)行了精心的編碼。并很高心提供給以后的考生參考。以下源代碼均經(jīng)過Visual studio 6.0調(diào)試通過,僅供參考。代碼由: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請輸入一行二進(jìn)制代碼:;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做為哨兵,實(shí)現(xiàn)升序排列#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;/該數(shù)組選擇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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年新世紀(jì)版九年級歷史下冊階段測試試卷含答案
- 2025年湘師大新版八年級地理下冊月考試卷含答案
- 2025年新世紀(jì)版選修6歷史下冊月考試卷含答案
- 2025年人民版必修3歷史下冊月考試卷含答案
- 2025年人教A新版九年級地理下冊階段測試試卷含答案
- 2025年滬科版八年級歷史下冊階段測試試卷含答案
- 2025年滬科版九年級地理下冊階段測試試卷
- 2025年外研版必修三歷史上冊階段測試試卷
- 2025年教科新版必修3生物下冊月考試卷含答案
- 2025年新科版選擇性必修3生物下冊階段測試試卷含答案
- 課題申報(bào)書:GenAI賦能新質(zhì)人才培養(yǎng)的生成式學(xué)習(xí)設(shè)計(jì)研究
- 駱駝祥子-(一)-劇本
- 全國醫(yī)院數(shù)量統(tǒng)計(jì)
- 《中國香文化》課件
- 2024年醫(yī)美行業(yè)社媒平臺人群趨勢洞察報(bào)告-醫(yī)美行業(yè)觀察星秀傳媒
- 第六次全國幽門螺桿菌感染處理共識報(bào)告-
- 天津市2023-2024學(xué)年七年級上學(xué)期期末考試數(shù)學(xué)試題(含答案)
- 經(jīng)濟(jì)學(xué)的思維方式(第13版)
- 盤錦市重點(diǎn)中學(xué)2024年中考英語全真模擬試卷含答案
- 湖北教育出版社四年級下冊信息技術(shù)教案
- 背景調(diào)查報(bào)告
評論
0/150
提交評論