版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
#include<iostream.h>
classA
public:
virtualvoidact1(){cout?nact1\n";act2();}
voidact2(){cout?"act2\nn;act3();)
/*****************'found*****************/
virtualvoidact3(){cout?HAact3\nn;act4();}
/*****************'found*****************/
virtualvoidact4(){cout?MAact4\nn;act5();}
voidact5(){cout?nAend\n";}
);
classB:publicA
voidact3(){cout?nBact3\n";act4();)
voidact4(){cout?nBact4\n";act5();}
voidact5(){cout?,,Bend\nM;}
);
voidmain(void)
charc;
A*a;
cout?"Whichact(aorb)?”;
/*****************found*****************/
cin?c;
if(c=,a')
a=newA;
else
a=newB;
a->actl();
deletea;
}
#include<iostream.h>
#include<fstream.h>
#include<string.h>
voidfun(charss[]);
voidmain()
chars[80];
coutvv”請輸入字符串:”;
cin?s;
fun(s);
coutvv”逆序后的字符串:"vvs?endl;
ofstreamfin(**outl.dat");
charstr[80]=nhappyM;
fun(str);
fin?str?endl;
fin.closeQ;
)
voidfiin(charss[])
(
intn=strlen(ss);
for(inti=0;i<(n/2);i-H-)
{
charc=ss[i];
ss[i]=ss[n-l-i];
ss[n-l-i]=c;
)
}
#include<iostream.h>
classCat
{
public:
intGetAge();
voidSetAge(intage);
voidMeow();
protected:
//**]**
intitsAge;
);
intCat::GetAge()
{
//**2**
returnitsAge;
}
voidCat::SetAge(intage)
{
itsAge=age;
}
voidCat::Meow()
cout?"meowAnH;
)
voidmain()
(
Catkitty;
kitty.Meow();
kitty.SetAge(5);
cout?nkittyisacatwhois
cout?kitty.GetAge();
cout?"yearsold.\n";
kitty.Meow();
}
a-X-M—X—>—X-X-*-A-A-X-A-X-A-J
#include<iostream.h>
classvehicle
intwheels;
floatweight;
public:
/*****************^Qund*****************/
virtualvoidmessage(void){cout?nVehiclemessage\nn;}
);
classcar:publicvehicle
intpassengerload;
public:
/*****************fbund*****************/
voidmessage(void){cout?"Carmessaged";}
);
classtruck:publicvehicle
{
intpassengerload;
floatpayload;
public:
intpassengers(void){returnpassenger_load;}
);
voidmain()
{
vehicle*unicycle;
unicycle=newvehicle;
/*****************fbund*****************/
unicycle->message();
deleteunicycle;
unicycle=newcar;
unicycle->message();
deleteunicycle;
unicycle=newtruck;
unicycle->message();
deleteunicycle;
}
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
classAA{
int*a;
intn;
intMS;
public:
voidInitAA(intaa[],intnn,intms)
(
if(nn>ms)
|
cout?nError!n?endl;
exit(l);
}
MS=ms;
n=nn;
a=newint[MS];
fbr(inti=0;i<n;i++)a[i]=aa[i];
)
intCompare(AAb);
);
intAA::Compare(AAb)
(
if(n!=b.n)return0;
fbr(inti=0;i<n;i++)
if(a[i]!=b.a[i])return0;
return1;
}
voidmain()
(
AAa,b,c;
intx[]={l,2,3,4,5};
inty[]={1,2,3,6,7);
intz[]={l,2,5,7,9};
a.InitAA(x,3,5);
b.InitAA(y,3,5);
c.InitAA(z,3,5);
if(a.Compare(b))
cout?na=bH?endl;
else
cout?Ma<>bn?endl;
if(a.Compare(c))
cout?,,a=c,,?endl;
else
cout?naocM?endl;
ofstreamfin(noutl.dat");
if(a.Compare(b))
fin?Ha=b"?endl;
else
fin?naobn?endl;
if(a.Compare(c))
fin?,,a=c,,?endl;
else
fin?HaocM?endl;
fin.close();
/**************************!
#include<iostream.h>
#include<string.h>
classPoint
(
intx,y;
public:
〃**I**
Point(intxl=0,intyl=0):x(xl),y(yl)
{
cout?"Point:"?x?''?y?^';
}
?Point。{}
);
classText
{
chartext[100];
public:
Text(char*str)
{
strcpy(text,str);
cout?str?"\nM;
-Text(){}
);
classCircleWithText:publicPoint,publicText
{
public:
CircleWithText(intcx,intcy,char*msg):Point(cx,cy),Text(msg)
{}
?CircleWithText(){}
);
voidmain()
(
CircleW汕Textcm(3,4,"hellon);
}
#include<iostrcam.h>
#include<math.h>
classpoint
{
public:
voidset(doubleix,doubleiy)
{
x=ix;
y=iy;
)
doublexofTset()
(
returnx;
)
doubleyoffset()
(
returny;
}
doubleangle()
{
return(180/3.14159)*atan2(y,x);
}
/****************nd*************
inlinedoubleradius()
returnsqrt(x*x+y*y);
protected:
doublex;
doubley;
);
voidmain()
pointp;
doublex,y;
cout?"Enterxandy:\nu;
cin?x?y;
p.set(x,y);
^****************Cund*******************/
p.set((p.xoffset()+5),(p.yoffset()+6));
y****************Cund*******************/
cout?nxoffset=H?p.xoffset()?endl;
cout?,'yoflfset=,,?p.yoffset()?endl;
cout?,'angle=M?p.angle()?endl;
cout?nradius="?p.radius()?endl;
#include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
voidfun(chars[],intc)
(
inti=0;
char*p;
P=s;
while(*p)
{if(*p!=c)
{s[i]=*p;
i++;
}
p++;
}
s[i]='\0';
)
voidmain()
staticcharstr[]="turbocandborlandc++”;
charch;
coutvv”原始字符串:\n”《strv<endl;
coutw”輸入一個字符:
cin?ch;
fun(str,ch);
cout?nstr=n?str?endl;
ofstreamfin(noutl.dat");
staticcharstrl[]="turbocandBorlandc++”;
charchl=*c';
fun(strl,chl);
fin?strl?endl;
fin.close();
/**************************j
#include<iostream.h>
#include<string.h>
classEmployee{
protected:
charname[20];
charaddress[100];
charcity[20];
charprovince[20];
charzipcode[10];
public:
Employee(char*nm,char*addr,char*city,char*prov,char*zip);
voidChangeName(char*newName);
char*Display();
);
Employee::Employee(char*nm,char*adr,char*cit,char*prov,char*zip)
(
〃**I**
strcpy(name,nm);
strcpy(address,adr);
strcpy(city,cit);
strcpy(province,prov);
strcpy(zipcode,zip);
}
voidEmployee::ChangeName(char*newName)
strcpy(name,newName);
}
char*Employee::Display()
(
//**3**
char*buffer=newchar[200];
strcpy(buffcr,name);
strcat(buffer,address);
returnbuffer;
}
voidmain()
{
Employeeemp("李華”「建國路大街105號“,”石家莊“,“河北〃J103400");
emp.ChangeName("王東");
cout?emp.Display()?endl;
#include<iostream.h>
classanimal
public:
/****************found**亭****************/
friendvoidsetvalue(animal&,int,int);
friendvoidsetvalue(animal&,int,int);
voidprint();
//protected:將成員變量itsage;itsweight改為public類型。
/****************found*******************/
intitsweight;
intitsage;
);
voidanimal::print()
(
cout?,,weight:,,?itsweight?endl;
cout?"age:,,?itsage?endl;
)
voidsetvalue(animal&ta,inttw)
{
ta.itsweight=tw;
ta.itsage=O;
}
voidsetvalue(animal&ta,inttw,inttn)
ta.itsweight=tw;
ta.itsage=tn;
}
voidmain()
{/****************'f^jund*******************/
animalpeppy;
setvalue(peppy,5);
cout?nl:"?endl;
peppy.print();
setvalue(pcppy,7,9);
cout?"2:"?endl;
pcppy.print();
)
#includc<iostream.h>
#include<fstream.h>
intScqSearch(intlist[],intstart,intn,intkey)
{
for(inti=start;i<n;i++)
{
if(list[i]=key)
{
returni;
}
}
return-1;
}
voidmain()
(
intA[10];
intkey,count=0,pos;
cout?"Enteralistof10integers:
fbr(pos=0;pos<10;pos++)
{
cin?A[pos];
}
cout?"Enterakey:
cin?key;
pos=0;
while((pos=SeqSearch(A,pos,10,key))!=-l)
{
count-H-;
POS-H-;
cout?key?noccursn?count?(count!=l?Mtimes":"inthelist.M?endl;
/**************************/
ofstreamfin(Houtl.datn);
intb[10]={0,l,2,3,4,5,6,7,8,9};
intkey1=3;
intpos1=0,count1=0;
while((pos1=SeqSearch(b,pos1,10,key1))!=-I)
count1-H-;
posl-H-;
fin?keyl?"occurs"?countl?(countl!=l?ntimes":”time")?ninthelist.”v〈endl;
fin.close();
/**************************/
}
#include<iostream.h>
classvector
inta;
intb;
public:
〃**]**
vector(intx=0,inty=0):a(x),b(y){}
voidinput(intx,inty)
〃**2**
a=x;
b=y;
)
voidoutput()
cout?,(,?a<<7?b?,,),,?endl;
frienddoubleMultiply(vector&x,vector&y);
);
doubleMultiply(vector&x,vector&y)
doublec;
c=x.a*y.a+x.b*y.b;
returnc;
voidmain()
vectorx(10,20),y;
doubled;
y.input(2,3);
d=Multiply(x,y);
x.output();
y.output();
cout?d?endl;
}
#include<iostream.h>
classA!
public:
A(inti,intj){a=i;b=j;}
y****************Cund*******************/
voidMove(intx,inty){a+=x;b+=y;}
voidShow(){cout?H(H?a?n,"?b?")n?endl;}
private:
inta,b;
);
classB:privateA
{
public:
/****************^Qund*******************/
B(inti,intj,intk,intl):A(ij){x=k;y=l;}
voidShow(){cout?x?M,M?y?end1;}
voidfun(){Move(3,5);}
/****************found*******************/
voidfl(){A::ShowO;}
private:
intx,y;
);
voidmain()
(
Ae(l,2);
e.Show();
Bd(3,4,5,6);
d.fun();
d.Show();
d.fl();
#include<iostream.h>
#include<fstream.h>
intpattem_index(charsubstr[],charstr[])
inti,j,k;
for(i=O;str[i];i++)
fbr(j=i,k=O;(str[j]=substr[k])||(substr[k]==,?,);j-H-,k-H-)
if(!substr[k+l])
return(i);
retum(O);
voidmain()
char*substring,*string;
intsame;
substring=,,???gram**;
string="thisprogramreturnindexofsubstring";
same=pattem_index(substring,string);
ififsame)
coutw”子串起始位置:“wsamevvendl;
else
coutw”匹配不成功"wendl;
/**************************/
ofstreamfin(noutl.dat");
intsame1=pattem_index(substring,string);
if(samel)
finvv”子串起始位置:“vvsame<vendl;
else
finvv”匹配不成功"wendl;
fin.close();
}
//include<iostream.h>
classcomp
{
inta;
intb;
public:
〃**?**
comp(intx=0,inty=0):a(x),b(y){}
friendcompplus(comp&x,comp&y);
voidinput(intx,inty)
a=x;
b=y;
)
voidoutput()
(
cout?a?'+'?b?"i"?endl;
}
};
compplus(comp&x,comp&y)
{
compc;
c.a=x.a+y.a;
c.b=x.b+y.b;
returnc;
}
voidmain()
{
compx(10,20),y,z;
y.input(2,3);
z=plus(x,y);
x.output();
y.output();
cout?"result:M;
z.output();
)
#include<iostream.h>
classCSample
inti;
public:
CSample(){cout?MConstructorlM?endl;i=0;}
CSample(intval){cout?,,Constructor2,,?endl;i=val;}
-CSampleO{cout?nDestructorM?endl;}
voiddisp();
};
/**********found*******亭*不/
voidCSample::disp()
cout?ni=,,?i?endl;
voidmain()
CSample*a,b(10);
/**********nd**********/
a=newCSample;
a->disp();
/**********仿und**********/
b.disp();
}
#include<conio.h>
#include<math.h>
#include<iostream.h>
#include<fstream.h>
floatfun()
floatx1=0.0,xO;
do
{x0=xl;
xl=cos(x0);
}while(fabs(xO-x1)>=1e-6);
returnxl;
)
voidmain()
cout?nRoot=H?fun()?endl;
ofstreamfin(Houtl.dat");
fin?fun()?endl;
fin.close();
#include<iostream.h>
classStudent
{
〃**I**
intcode;
intenglish;
intcomputer;
inttotal;
public:
voidgetinfbrmation();
voidcomputesum();
intgetcode();
intgettotalscore();
?Student。;
);
voidStudent::getinformation()
{
//**2**
COUtVV”輸入編號:
cin?code;
cout?"英語成績:";
cin?english;
coutvv”計算機成績:”;
cin?computer;
)
voidStudent::computesum()
|
total=english+computer;
cout?"編號"vvcode<v”總分:n?total?endl;
)
intStudent::getcode()
{
returncode;
}
intStudent::gettotalscore()
{
returntotal;
}
voidfirstname(Student*A[],intnum)
{
inttempcode,tempsum;
tempcode=(*A[0]).getcode();
tempsum=(*A[0]).gettotalscore();
fbr(inti=l;i<num;i++)
(
if(((*A[i]).gettotalscore())>tempsum)
{
tempcode=(*A[i]).getcode();
tempsum=(*A[i]).gettotalscore();
}
}
coutw”總分最高者」〈〈tempcodevv”:M?tempsum?endl;
}
voidmain()
Student*A[3];
inti,n=3;
fbr(i=O;i〈n;i++)
(
A[i]=newStudent;
A[i]->getinfbnnation();
}
for(i=O;i<n;i++)
{
A[i]->computesum();
}
firstname(A,3);
#include<iostream.h>
classB
intx;
public:
B(){x=0;cout?nConstructorln?endl;}
B(inti){x=i;cout?HConstructor2H?endl;}
-B(){cout?MDestructor"?endI;}
/**********found**********/
voidprint(){cout?Hx="?x?endl;}
);
voidmain()
B*ptr;
ptr=newB[2];
/**********%und**********/
ptr[O]=B();
ptr[l]=B(5);
/**********d**********/
for(inti=0;i<2;i++)
ptr[i].print();
delete[]ptr;
}
#include<iostream.h>
#include<fstream.h>
#include<stdlib.h>
intchamum(charfin[10]);
voidmain()
intnum;
num=chamum("abc.txtn);
cout?nnum=**?num?endl;
/**************************!
ofstreamfin(noutl.dat");
intnuml;
numl=charnum(nabcefg.txt");
fin?num1?endl;
fin.close();
/**************************/
intchamum(charfh[10])
{
(streamfile;
file.open(fri,ios::in);
if(!file)
(
cout?"abc.txtcan'topcnn?endl;
abort();
}
charch;
inti=0;
while(!file.eof())
(
file.get(ch);
i++;
)
file.close();
returni-1;
}
#include<iostream.h>
classCircle{
public:
Circle():radius(5){}
〃**?**
Circle(intrad):radius(rad){}
voidSetRadius(intr){radius=r;}
intGetRadius(){returnradius;}
〃**2**
voidPrint(){cout?nThecirclehasradiusof"?radius?M!\nn;}
friendvoidCompareR(Circle*cl,Circle*c2);
private:
intradius;
);
voidCompareR(Circle*cl,Circle*c2)
{
〃**3**
if((cl->GetRadius())>(c2->GetRadius()))
cout?,,cl>c2"?endl;
else
if((cl->GetRadius())==(c2->GetRadius()))
cout?ncl=c2,,?endl;
else
if((c1->GetRadius())<(c2->GetRadius()))
cout?nc1<c2n?endl;
)
voidmain()
{
Circlecl;
cl.SetRadius(5);
cl.Print();
Circlec2(10);
c2.Print();
CompareR(&cI,&c2);
)
#include<iostream.h>
classbase
(
public:
/**********d**********/
virtualvoidfl(){cout?"flfunctionofbaseM?endl;}
virtualvoidf2(){cout?Mf2functionofbaseM?endl;}
virtualvoidf3(){cout?"f3functionofbasen?endl;}
voidf4(){cout?"f4functionofbaseM?endl;}
};
/**********d**********j
classderive:publicbase
{
voidfl(){cout?MflfunctionofderiveM?endl;}
voidf2(intx){cout?"f2functionofderive"?endl;}
voidf4(){cout?nf4functionofderiveM?endl;}
);
voidmain()
base*p;
deriveobj2;
/**********^3und**********/
p=&obj2;
p->fl();
p->f2();
)
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<fstream.h>
#defineN10
typedefstructss
{charnum[10];
ints;
}STU;
voidfun(STUa[],STU*s)
{
inti,min;
min=a[0].s;
fbr(i=0;i<N;i++)
if(a[i].s<inin)
{min=a[i].s;
*s=a[i];
}
}
voidmain()
{
STU
,,,,,MnMHM,,MMM
a[N]={{A0r581},{A02,89},{"A03,66},{A04587},{A05,77},{"A06,90},{A07",79},{A
08”,61},{“A09”,80},{“A10n,71}},m;
fun(a,&m);
cout?n*****Theoriginaldate*****n?endl;
cout?nThelowest:n?m.num?m.s?end1;
/**************************/
ofstreamfin(noutl.dat");
fun(a,&m);
fin?m.num?m.s?endl;
fin.close();
/**************************/
}
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<fstream.h>
#defineN10
typedefstructss
{charnum[10];
ints;
}STU;
voidfun(STUa[],STU*s)
(
inti,min;
min=a[0].s;
fbr(i=O;i<N;i++)
if{a[i].s<min)
{min=a[i].s;
*s=a[i];
}
}
voidmain()
{
STU
a[N]={{nA0r,,81},{"A02n,89},{"A03H,66},{HA04n,87},{HA05n,77},{"A06,1,90},{nA07",79},{,,A
08”,61},{MA09H,80},{MA1
fun(a,&m);
cout?n*****Theoriginaldate*****n?endl;
cout?nThelowest:n?m.num?m.s?end1;
ofstreamfin(noutl.dat");
fun(a,&m);
fin?m.num?m.s?endl;
fin.close();
#include<iostream.h>
#include<stdio.h>
classTable
〃**]**
intx;
inty;
intz;
public:
voidprint(intx,inty,intz);
);
voidTable::print(intx,inty,intz)
{
printf("%d*%d=%dH,x,y,z);
if(z<10)printf("M);
}
classTable9:publicTable
|
public:
voidprint();
);
voidTable9::print()
(
inti,j;
intx,y,z;
for(i=l;i<10;i+4-)
(
fbr(j=l;j<i+l;j++)
{
x=i;
y=j;
z=i*j;
Table::print(y,x,z);
)
printffW”);
)
}
main()
(
Table9t_9;
t_9.print();
return0;
#include<iostream.h>
classA
protected:
intn,m;
public:
voidset(inta,intb){m=a;n=b;}
voidshow(){cout?m?H,n?n?endl;}
/**********found**********/
);
classB:publicA
ints;
public:
voidset(){s=m*n;}
voidshows(){cout?s?endl;}
};
voidmain()
Bb;
/**********found**********/
b.A::set(4,5);
b.show();
b.set();
/**********found**********/
b.shows();
)
#include<iostream.h>
#include<fstream.h>
#include<string.h>
intCalcDigital(char*str);
voidmain()
char*str;
str=newchar[255];
COUtVV”輸入字符串:”;
cin?str;
intnum=CalcDigital(str);
cout?str?n:"?num?endl;
/**************************/
ofstreamfin(noutl.dat");
char*strl="olympic2008H;
intnum1=CalcDigital(str1);
fin?num1?endl;
fin.close();
}
intCalcDigital(char*str)
if(str==NULL)return0;
intnum_of^digital=0;
intlen=strlen(str);
for(inti=0;i<len;i++)
if(str[i]<='9,&&str[i]>='0,)
num_of^digital-H-;
returnnum_of_digital;
}
#include<iostream.h>
〃**]**
constfloatPI=3.14159f;
constfloatWIDTH=3.00f;
classCircle
{
private:
floatradius;
public:
〃**2**
Circle(floatr):radius(r){};
floatCircumference(){return2*PI*radius;}
floatArea(){returnPI*radius*radius;}
);
classMoney
{
private:
floatFencePrice;
floatConcretePrice;
public:
Money(floatf,floatc);
floatTotalMoney(floatfencelen,floatconarea);
);
Money::Money(floatf,floatc)
(
〃**3**
FencePrice=f;
ConcretePrice=c;
}
floatMoney::TotalMoney(floatfencelen,floatconarea)
(
〃**4**
retumFenccPrice*fencelen+ConcretcPrice*conarea;
)
voidmain()
{
floatradius,fence,concrete;
cout.setfi(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout?"Entertheradiusofthepool:";
cin?radius;
cout?"EntertheFenccPrice:";
cin?fence;
cout?"EntertheConcretePrice:
cin?concrete;
CirclePool(radius);
CirclePoolRim(radius+WIDTH);
Moneymon(fence,concrete);
floattotalmoney=mon.TotalMoney(PoolRim.Circumference(),(PoolRim.Area()
Pool.Area()));
cout?"ThetotalmoneyisRMB”?totalmoney?endl;
}
#include<iostream.h>
classBase
public:
Base(){cout?"classBase**?endl;}
voidf(){cout?"finBaseM?endl;}
);
classDI:virtualpublicBase
public:
Dl(){cout?"classDlM?endl;}
voidf(){cout?"finDln?endl;}
);
/**********d**********/
classD2:virtualpublicBase
public:
D2(){cout?"classD2H?endl;}
);
/**********Cund**********/
classD3:publicDI,publicD2
{
public:
D3(){cout?"classD3M?endl;}
);
voidmain()
D3d;
/**********Sund**********/
d.Base::f();
#include<iostream.h>
#include<fstream.h>
inlinelongsum(intn)
(
if(n=l)
return1;
else
returnn*n+sum(n-l);
}
voidmain()
intn;
coutw”輸入n:M;
cin?n;
cout?"結(jié)果為:"?sum(n)?endl;
ofstreamfin(noutl.dat");
fin?sum(5)?endl;
fin.close();
#include<iostream.h>
#include<string.h>
classCEmployee
public:
voidputname(charn[50]){strcpy(name,n);)
voidgetname(charn[50]){strcpy(n,name);}
voidputpay(doubled){pay=d;}
doublegetpay(){returnpay;}
private:
〃**]**
charname[50];
doublepay;
};
classCompany
(
private:
CEmployee*emp;
intnum;
public:
Company(intn);
voidadd(intcode,charname[50],doublepay);
voidprint();
);
Company::Company(intn)
{
num=n;
emp=newCEmployee[num];
}
voidCompany::add(intcode,charname[50],doublepay)
{
(emp+code)->putname(name);
(emp+code)->putpay(pay);
}
voidCompany::print()
(
〃**4**
charc[50];
doublemoney;
fbr(inti=0;i<num;i++)
(emp+i)->getname(c);
money=(emp+i)->getpay();
cout?c?Hispaid"?money?HRMBforonemonth"?endl;
)
voidmain()
|
Companycom(2);
com.add(0,nJackn,200);
com.add(1,"Lee”,300);
com.print();
#include<iostream.h>
classCommonBase
public:
intx;
);
/*****************found****************不/
classDcriveCommonA:publicCommonBase
public:
inty;
);
classDeriveCommonB:publicCommonBase
public:
intz;
};
/*****************nd*****************/
classOverlapping:publicDeriveCommonA,publicDeriveCommonB
public:
voidDisplay()
cout?"Valuesare:"?DeriveCommonA::x?n,"?y?"andM?z?endl;
);
intmain()
Overlappingov;
/*****************d*****************/
ov.DeriveCommonA::x=l;
ov.y=2;
ov.z=3;
ov.Display();
return0;
)
#include<iostream.h>
#include<stdio.h>
#include<fstream.h>
#defineN80
intfiin(char*str)
inti,n=0,fg=l;
char*p=str;
while(*p)
{n++;p-H-;}
fbr(i=0;i〈n/2;i++)
if(str[i]==str[n-l-i]);
else
{fg=0;break;}
returnfg;
}
voidmain()
chars[N];
cout?"Enterastring:"?endl;
gets(s);
cout?n\n\n";
puts(s);
ifi(fun(s))
cout?"YES\nM;
else
cout?nNO\nH;
ofstreamfin(noutl.dat");
charsl[80]={'",'b','c',d,'e'};
if(fiin(sl))
fin?"yes,,?endl;
else
fin?"noM?endl;
fin.close();
#include<iostream.h>
classqueue
intq[100];
intbl,el;
public:
queue();
voidqput(intj);
intqget();
);
queue::queue()
{
II**I**
b!=el=0;
cout?"queucinitialized\nn;
}
voidqueue::qput(intj)
(
H**2**
if(bl==100)
{
cout?"queueisfull\nM;
return;
)
bl++;
q[bi]=j;
}
intqueue::qget()
{
H**3**
if(el=bl)
(
cout?*'queueisempty\nn;
return0;
)
el++;
returnq[el];
)
voidmain()
{
queueaa,bb;
aa.qput(l1);
bb.qput(22);
aa.qput(33);
bb.qput(44);
cout?aa.qget()?H,,?aa.qget()?"\nM;
cout?bb.qget()?HM?bb.qget()?"\nn;
#include<iostream.h>
template<classT>
classpair
(
Tvalue1,value2;
public:
pair(Tfirst,Tsecond)
{valuel=first;valuc2=second;}
/*****************fiDund*****************/
Tgetmax();
};
/*****************fbund*****************/
template<classT>
Tpair<T>::getmax()
|
Tretval;
retval=valuel>value2?value1:value2;
returnretval;
}
voidmain()
{
pair<int>myobject(100,75);
cout?myobject.getmax()?endl;
}
#include<conio.h>
#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include<string.h>
voidfun(char*s,chart[])
(
inti,j=0,n;
n=strlen(s);
fbr(i=0;i〈n;i++)
if{i%2!=0&&s[i]%2!=0)
{tQ]=s[i]u++;)
t[j]W
)
voidmain()
chars[100],t[100];
cout?"PleaseenterstringS:H?endl;
gets(s);
fun(s,t);
puts(t);
ofstreamfin(noutl.dat");
charsl[l00]={,a,,'b,;c';d,,,e;,f,,d7s,};
chartl[100];
fiin(sl,tl);
fin?tl?endl;
fin.close();
/**************************/
#include<iostream.h>
#include<stdlib.h>
classARRAY
{
private:
int*p,num;
public:
ARRAY(){p=newint[10],num=10;}
ARRAY(inti)
(
II**I**
if(i<=0)
{
coutvv”錯誤!數(shù)組長度應(yīng)為正。\n";
exit(O);
}
p=newint[i];
num=i;
}
ARRAY(constARRAY&a);
int&operator[](inti);
-ARRAY(){deletep;}
ARRAY&operatoi^:(constARRAY&a);
friendARRAYoperator+(ARRAY&a,ARRAY&b);
friendostream&operator?(ostream&os,ARRAY&a);
);
ARRAY::ARRAY(constARRAY&a)
H**2**
num=a.num;
p=newint[num];
fbr(inti=O;i〈num;i++)
p[i]=a.p[i];
}
int&ARRAY::operator[](inti)
{
H**3**
if(i>=num||i<0)
{
coutw"越界訪問!”;
exit(0);
}
returnp[i];
}
ARRAY&ARRAY::opcrator=(constARRAY&a)
{
num=a.num;
p=newint[num];
fbr(inti=0;i〈num;i++)
p[i]=a.p[i];
H**4**
return*this;
)
ARRAYoperator+(ARRAY&a,ARRAY&b)
{
if(a.num!=b.num)
{
coutw”數(shù)組長度不相同!”Wendi;
exit(O);
}
ARRAYt(a.num);
fbr(inti=0;i<a.num;i++)
t.p[i]=a.p[i]+b.p[i];
returnt;
}
ostream&operator?(ostream&os,ARRAY&a)
{
inti=0;
fdr(;i<a.num;i4-+)
{
cout?a.p[i]?'*;
!((i+1)%10))cout?endl;
returnos;
}
voidmain()
{
ARRAYa(3);
a[0]=a[l]=a[2]=3;
cout?,a,?a?endl;
ARRAYb(a);
cout?,b,?b?end1;
ARRAYc(2);
c=a+b+b;
cout?,c,?c?endl;
c=((b=(a+b))+c);
cout?'a'?a?'b'?b?'c'?c?endl;
a[7]=3;
cout?a;
#includc<iostrcam.h>
classA{
public:
staticintn;
A(){n++;};
-A(){n-;};
);
/*****************d*****************/
intA::n=0;
intmain(){
Aa;
Ab[3];
A*c=newA;
c=&a;
cout?c->n?endl;
cout?A::n?endl;
return0;
#include<iostream.h>
#include<fstream.h>
intsortnum(intnum)
intnumber[3],ij,temp;
for(i=0;i<3;i++)
{
number[i]=num%10;
溫馨提示
- 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 戶外帳篷合作合同范例
- 出售商品公司合同范例
- epc項目銷售合同范例
- 當(dāng)鋪簡易合同范例
- 心理咨詢科心理健康篩查項目
- 平方個人租房合同范例
- 二手農(nóng)村房合同范例
- 加裝電梯改造合同范例
- 審計政府采購合同范例
- 售樓合同范例
- 廣東省廣州市2024-2025學(xué)年九年級上學(xué)期期中英語試題(無答案)
- 2024-2025學(xué)年人教版物理八年級上冊 期中考試物理試卷
- 期中模擬練習(xí)(1-4單元)(試題)2024-2025學(xué)年二年級上冊數(shù)學(xué)蘇教版
- DZ∕T 0265-2014 遙感影像地圖制作規(guī)范(1:50000、1:250000)(正式版)
- 中華民族發(fā)展史智慧樹知到期末考試答案2024年
- MOOC 3D工程圖學(xué)-華中科技大學(xué) 中國大學(xué)慕課答案
- JJG 443-2023燃油加油機(試行)
- 人教版英語四年級上冊《Unit-3-My-friends》單元教學(xué)課件
- 亞馬遜品牌授權(quán)書(英文模板)
- 門座式起重機檢驗規(guī)程
- 微型消防站備案表.doc
評論
0/150
提交評論