北邮大一上机第七章.docx

上传人:b****8 文档编号:29732000 上传时间:2023-07-26 格式:DOCX 页数:12 大小:190.06KB
下载 相关 举报
北邮大一上机第七章.docx_第1页
第1页 / 共12页
北邮大一上机第七章.docx_第2页
第2页 / 共12页
北邮大一上机第七章.docx_第3页
第3页 / 共12页
北邮大一上机第七章.docx_第4页
第4页 / 共12页
北邮大一上机第七章.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

北邮大一上机第七章.docx

《北邮大一上机第七章.docx》由会员分享,可在线阅读,更多相关《北邮大一上机第七章.docx(12页珍藏版)》请在冰豆网上搜索。

北邮大一上机第七章.docx

北邮大一上机第七章

第七章

1#include

usingnamespacestd;

inti=0;

intj=0;

classz

{

public:

intn;

z();

voida();

};

voidz:

:

a()

{

if(n>0)

{

cout<<"该数字为正整数"<

i++;

}

else

{

cout<<"该数字是负整数"<

j++;

}

}

z:

:

z()

{

n=0;

}

voidmain()

{

zb;

cout<<"请输入一个非零整数:

";

cin>>b.n;

while(b.n!

=0)

{

b.a();

cout<<"请输入一个非零整数:

";

cin>>b.n;

};

cout<<"判断结束!

"<

cout<<"正整数有"<

cout<<"负整数有"<

}

2#include

usingnamespacestd;

classsell

{

private:

intcolorcast;

intfridge;

intwasher;

inttotal;

public:

sell()

{

colorcast=4200;

fridge=2800;

washer=1500;

}

~sell(){};

voidresult(intm,intn,intp)

{

intall;

all=m*colorcast+n*fridge+p*washer;

cout<<"今天销售额为"<

}

};

intmain()

{

cout<<"今天卖出彩电,冰箱,洗衣机的数量分别为:

"<

intn1,n2,n3;

cin>>n1>>n2>>n3;

selltoday;

today.result(n1,n2,n3);

system("pause");

}

3#include

#include

usingnamespacestd;

classcar

{

private:

stringcarship;

stringcolor;

inta;

intb;

intc;

public:

car(stringcarship,stringcolor,inta,intb,intc)

{

this->carship=carship;

this->color=color;

this->a=a;

this->b=b;

this->c=c;

}

voiddisp_parameters()

{

cout<<"车型为:

"<

cout<<"颜色为:

"<

cout<<"车门数为:

"<

cout<<"座位数为:

"<

cout<<"轴距为:

"<

}

voidchange_parameters(stringcarship,stringcolor,inta,intb,intc)

{

this->carship=carship;

this->color=color;

this->a=a;

this->b=b;

this->c=c;

cout<<"改变后的车型为:

"<

cout<<"改变后的颜色为:

"<

cout<<"改变后的车门数为:

"<

cout<<"改变后的座位数为:

"<

cout<<"改变后的轴距为:

"<

}

};

voidmain()

{

carcar1("小型车","黑色",4,8,1280);

car1.disp_parameters();

car1.change_parameters("微型车","红色",4,6,960);

}

4#include

#include

usingnamespacestd;

classStudent

{

private:

intnumber;

stringname;

stringsex;

public:

intage;

voidset(intnu,stringna,stringse,intag)

{

number=nu;

name=na;

sex=se;

age=ag;

}

voidshow();

};

voidStudent:

:

show()

{

cout<<"学号:

"<

"<

"<

"<

}

voidmain()

{

Studenta[5];

a[0].set(1,"liuli","male",17);

a[1].set(2,"zhangsan","female",14);

a[2].set(3,"lisi","male",15);

a[3].set(4,"xiaoming","female",18);

a[4].set(5,"liu","female",20);

Studenttemp;

for(inti=0;i<5;i++)

{

for(intj=0;j<5-i;j++)

{

if(a[j].age

{

temp=a[j];

a[j]=a[j+1];

a[j+1]=temp;

}

}

}

a[0].show();

a[1].show();

a[2].show();

a[3].show();

a[4].show();

}

5

#include

usingnamespacestd;

classATM

{

public:

intx,y,u,v,w;

voidcheck();

voidhhhh();

ATM();

private:

intnum;

intcode;

intmoney;

};

ATM:

:

ATM()

{

num=1111;

code=2222;

money=10000;

}

voidATM:

:

check()

{

if(x==num&&y==code)

{

cout<<"TRUE!

"<

w=1;

}

else

{

cout<<"WRONG!

"<

w=0;

}

}

voidATM:

:

hhhh()

{

cout<<"请输入账号:

";

cin>>x;

cout<<"请输入密码:

";

cin>>y;

ATM:

:

check();

if(w==1)

{cout<<"存款请按1,取款请按2:

";

cin>>v;

switch(v)

{

case1:

cout<<"请输入存款金额:

";

cin>>u;

money+=u;

cout<<"余额为:

"<

break;

case2:

cout<<"请输入取款金额:

";

cin>>u;

money-=u;

cout<<"余额为:

"<

break;

}

}

else

cout<<"密码错误!

"<

}

voidmain()

{

ATMsomebody;

somebody.hhhh();

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1