北邮小学期程序设计报告Word文档下载推荐.docx
- 文档编号:20607456
- 上传时间:2023-01-24
- 格式:DOCX
- 页数:31
- 大小:18.87KB
北邮小学期程序设计报告Word文档下载推荐.docx
《北邮小学期程序设计报告Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《北邮小学期程序设计报告Word文档下载推荐.docx(31页珍藏版)》请在冰豆网上搜索。
=n)
if(a>
1000)
Inputerror,tryagain."
endl;
n)
Yourpriceislarger,pleasetryagain."
if(a<
Yourpriceissmaller,pleasetryagain."
}
Good,youareright."
};
intmain()
guessPriceexample;
example.Guess();
system("
pause"
);
return0;
}
二1
math.h>
classPoint
{
doublex;
doubley;
Point(doublea=0,doubleb=0)
{x=a;
y=b;
cout<
1"
~Point(){cout<
3"
doublegetX(){returnx;
doublegetY(){returny;
doublegetPxy(PointP1,PointP2)
{
return(double)sqrt((P1.x-P2.x)*(P1.x-P2.x)+(P1.y-P2.y)*(P1.y-P2.y));
classRectangle
PointR;
PointL;
intx1,y1,x2,y2;
Rectangle(Pointr,Pointl)
{R=r;
L=l;
2"
voidgetPoint()
x1>
y1>
x2>
y2;
doublegetArea()
PointR1(R.getX(),L.getY());
doublewidth=x2-x1;
doublelenth=y1-y2;
return(double)fabs(width*lenth);
};
main()
//intx,ly,rx,ry;
Pleaseenterthelocation."
//cin>
lx>
ly>
rx>
ry;
PointL;
PointR;
Rectanglerectangle(L,R);
rectangle.getPoint();
面积为"
rectangle.getArea()<
system("
二3
#include<
classCar;
classBoat
doubleWeight;
//Boat(){};
frienddoubleTotalWeight(Boat&
b,Car&
c);
voidgetWeight()
Weight;
classCar
//Car(){};
doubleTotalWeight(Boat&
c)
returnb.Weight+c.Weight;
main()
Boatb;
Carc;
输入重量:
b.getWeight();
c.getWeight();
TotalWeight(b,c)<
三1
//矩阵一
#defineM4
#defineN5
classMatrix
intA[M][N];
voidgetMatrix()
Pleaseenterthematrix."
for(inti=0;
i<
M;
i++)
for(intj=0;
j<
N;
j++)//读入矩阵
A[i][j];
voidoutPut()//输出矩阵
j++)
A[i][j]<
"
voidmatrixPlus(MatrixB,MatrixC)//求和
this->
A[i][j]=B.A[i][j]+C.A[i][j];
voidmatrixCut(MatrixB,MatrixC)//做差
A[i][j]=B.A[i][j]-C.A[i][j];
Matrix(){}
~Matrix(){}
MatrixA1,A2,A3;
//声明类
A1.getMatrix();
//读入
A2.getMatrix();
TheresultofA1andA2is:
A3.matrixPlus(A1,A2);
A3.outPut();
TheresultofA1subtractA2is:
A3.matrixCut(A1,A2);
三2
//矩阵二
voidoutPut()
voidmatrixPlus(MatrixB,MatrixC)
voidmatrixCut(MatrixB,MatrixC)
Matrix()
{}
~Matrix()
{}
Matrix*A1,*A2,*A3;
A1=newMatrix;
//动态申请空间
A2=newMatrix;
A3=newMatrix;
A1->
getMatrix();
A2->
A3->
matrixPlus(*A1,*A2);
outPut();
matrixCut(*A1,*A2);
三3
//矩阵三
intlines,rows;
//私有属性行列和指针
int**A;
lines;
rows;
voidmatrixPlus(Matrix&
B,Matrix&
C)
voidmatrixCut(Matrix&
Matrix()//构造函数
Pleaseenterlinesandrows."
lines>
A=newint*[lines];
A[i]=newint[rows];
Matrix(Matrix&
Q)//拷贝构造函数复制数组
A=newint*[Q.lines];
=Q.lines-1;
A[i]=newint[Q.rows];
lines=Q.lines;
rows=Q.rows;
~Matrix()//析构函数
delete[]A[i];
delete[]A;
intl,r;
MatrixA1;
MatrixA2=A1;
//声明矩阵类
MatrixA3=A1;
Matrix*pA1=newMatrix;
//动态创建矩阵类
Matrix*pA2=newMatrix;
Matrix*pA3=newMatrix;
pA1->
pA2->
pA3->
matrixPlus(*pA1,*pA2);
matrixCut(*pA1,*pA2);
四1
//形状一
#definePI3.1415
classshape
doublearea(){}//构造函数与析构函数
shape()
{cout<
gz1"
~shape()
xg1"
classrectangle:
publicshape//矩形派生类
doublelength,wide;
rectangle(){}
rectangle(doublex,doubley)//构造函数
length=x;
wide=y;
gz2"
voidgetValue()//读入函数
输入长和宽:
length>
wide;
doublearea()
{returnlength*wide;
~rectangle()//析构函数
{cout<
xg2"
classcircle:
publicshape//圆形派生类
doubleradius;
circle(){}
circle(doubler)
radius=r;
gz3"
voidgetValue()
输入半径:
radius;
{returnPI*radius*radius;
~circle()
xg3"
classsquare:
publicrectangle//zhengfangxing派生类
doubleside;
square(){}
square(doublel)
side=l;
gz4"
输入边长:
side;
{returnside*side;
}//计算面积
~square()
xg4"
}
intm,n,r,d;
/*rectangleA;
circleB;
squareC;
*/
请输入长和宽:
m>
n;
rectangleA(m,n);
//A.getValue();
面积为:
A.area()<
请输入半径:
r;
circleB(r);
//B.getValue();
B.area()<
;
请输入边长:
d;
squareC(d);
//C.getValue()
C.area()<
四2
//形状二
virtualdoublearea(){};
//虚函数
}//构造函数与析构函数
publicshape
rectangle(doublex,doubley)
~rectangle()
publicrectangle
五1
//重载
classPoint
intx,y;
Point(){}
Point(inta,intb)
//构造函数对类初始化
}//析构函数
voidgetValue(inta,intb)
{x=a;
voidprint()
("
x<
"
y<
)"
Pointoperator++(int)
PointP(*this);
//创建副本
P.x=x+1;
P.y=y+1;
return*this;
//返回副本
Pointoperator--(int)
P.x=x-1;
P.y=y-1;
Pointoperator++()
PointP;
P
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 小学 程序设计 报告