完整word版c++primerplus中文版第六版源代码Word格式.docx

上传人:b****4 文档编号:7853672 上传时间:2023-05-09 格式:DOCX 页数:33 大小:21.58KB
下载 相关 举报
完整word版c++primerplus中文版第六版源代码Word格式.docx_第1页
第1页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第2页
第2页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第3页
第3页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第4页
第4页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第5页
第5页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第6页
第6页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第7页
第7页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第8页
第8页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第9页
第9页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第10页
第10页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第11页
第11页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第12页
第12页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第13页
第13页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第14页
第14页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第15页
第15页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第16页
第16页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第17页
第17页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第18页
第18页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第19页
第19页 / 共33页
完整word版c++primerplus中文版第六版源代码Word格式.docx_第20页
第20页 / 共33页
亲,该文档总共33页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

完整word版c++primerplus中文版第六版源代码Word格式.docx

《完整word版c++primerplus中文版第六版源代码Word格式.docx》由会员分享,可在线阅读,更多相关《完整word版c++primerplus中文版第六版源代码Word格式.docx(33页珍藏版)》请在冰点文库上搜索。

完整word版c++primerplus中文版第六版源代码Word格式.docx

intstonetolb(intsts)

return14*sts;

3:

carrots=25;

"

Howmanycarrotsdoyouhave?

”<

endl;

〉carrots;

”Herearetwomore。

”;

carrots=carrots+2;

”Nowyouhave"

carrots〈<

carrots。

//下两行专门测试cin.get()

cin.get();

cin.get();

4:

iostream〉

usingnamespacestd;

ComeupandC++mesometime.”;

cout〈〈endl;

〈”Youwon'

tregretit!

5#include〈iostream>

voidsimon(int);

usingnamespacestd;

simon(3);

〈"

Pickaninteger:

intcount;

cin〉>

count;

simon(count);

”Done!

”〈<

voidsimon(intn)

”Simonsaystouchyourtoes"

〈〈n<

”times。

6:

#include〈iostream〉

#include<

cmath〉

doublearea;

Enterthefloorarae,insquarefeet,ofyourhome:

"

>

area;

doubleside;

side=sqrt(area);

That'

stheequivalentofasquare"

〈<

side

〈〈”feettotheside."

Howfascinating!

第三章

climits>

intn_int=INT_MAX;

shortn_short=SHRT_MAX;

longn_long=LONG_MAX;

〈”intis”<

sizeof(int)〈<

bytes."

shortis”〈〈sizeofn_short<

bytes。

longis"

sizeofn_long<

”bytes。

〈〈endl〈<

〈”Maximumvalues:

”int:

〈〈n_int〈<

〈”short:

n_short<

”long:

n_long〈〈endl;

Minimumintvalue=”〈<

INT_MIN<

Bitsperbyts=”<

CHAR_BIT<

return0;

#include〈climits>

#defineZERO0

usingnamespacestd;

shortsam=SHRT_MAX;

unsignedshortsue=sam;

”samhas”〈〈sam〈<

”dollarsandsuehas"

sue;

〈”dollarsdeposited."

〈endl

<

Add$1toeachaccount.”<

〈endl<

Now"

sam=sam+1;

sue=sue+1;

”Samhas"

〈〈sam〈<

dollarsandsuehas”〈〈sue;

dollarsdeposited。

\npoorsam!

sam=ZERO;

sue=ZERO;

samhas"

sam〈〈"

dollarsandsuehas"

〈sue;

”dollarsdeposited."

”Take$1fromeachaccount。

”〈〈endl<

〈”Now”;

sam=sam-1;

sue=sue-1;

cout〈〈”samhas"

〈sam<

dolarsandsuehas"

sue;

dollarsdeposited.”〈<

endl〈<

Luckysue!

intchest=42;

intwaist=0x42;

intinseam=042;

Monsieurcutsastrikingfigure!

\n"

chest=”<

chest〈〈”(42indecimal)\n"

waist="

〈waist<

〈”(0x42inhex)\n”;

inseam=”<

inseam〈〈"

(042inoctal)\n”;

intchest=42;

intwaist=42;

intinseam=42;

”Monsieurcutsastrikingfigure!

”chest="

chest<

(decimalfor42)”〈<

hex;

waist=”〈〈waist〈〈"

(hexadecimalfor42)”〈<

〈oct;

”inseam="

inseam<

”(octalfor42)\n”〈〈endl;

5:

cout〈〈”\aoperation\"

HyperHype\”isnowactivated!

Enteryouragentcode:

__________\b\b\b\b\b\b\b\b"

longcode;

code;

\aYouentered"

〈code〈〈"

.。

\acodeverified!

proceedwithplanz3!

charch;

Enteracharacter:

ch;

”Hola!

”Thankyouforthe"

ch<

〈”character。

7:

#include〈iostream>

charch=’M’;

inti=ch;

TheASCIIcodefor"

〈ch<

〈”is”〈<

i<

Addonetothecharactercode:

ch=ch+1;

i=ch;

”TheASCIIcodefor”〈〈ch〈〈”is”〈〈i〈<

”Displayingcharchusingcout。

put(ch):

cout。

put(ch);

cout.put(’!

’);

Done"

8:

cout.setf(ios_base:

:

fixed,ios_base:

floatfield);

//控制cout显示的形式

floattub=10。

0/3.0;

doublemint=10。

0/3.0;

constfloatmillion=1.0e6;

tub="

tub;

”,amilliontubs=”<

million*tub;

\nandtenmilliontubs="

〈10*million*tub<

cout〈〈”mint="

mint〈<

andamillionmints=”;

〈million*mint〈〈endl;

9:

floata=2.34e+22f;

floatb=a+1。

0f;

a=”〈〈a<

b—a=”〈〈b-a〈〈endl;

10:

#include〈iostream〉

doublehats,heads;

//或者是float

setf(ios_base:

fixed,ios_base:

floatfield);

”Enteranumber:

hats;

cout〈〈”Enteranothernumber:

cin〉〉heads;

”hats="

〈hats〈〈"

heads=”〈<

heads〈<

hats+heads="

hats+heads<

hats—heads=”<

〈hats—heads〈<

”hats*heads=”〈〈hats*heads<

”hats/heads=”<

hats/heads〈<

11:

fixed,ios_base:

Integerdivision:

9/5="

9/5<

〈”Floating-pointdivision:

9.0/5。

0=”;

9.0/5.0<

〈”Mixeddivision:

9.0/5="

9。

0/5〈<

doubleconstants:

1。

e7/9。

1.e7/9.0〈<

cout〈〈”floatconstants:

e7f/9。

0f="

cout〈〈1。

0f〈<

12:

constintLbs_per_stn=14;

intlbs;

Enteryourweightinpounds:

”;

cin〉〉lbs;

intstone=lbs/Lbs_per_stn;

intpounds=lbs%Lbs_per_stn;

lbs〈〈”poundsare"

〈〈stone

stone,"

〈〈pounds<

pound(s)。

13:

setf(ios_base:

fixed,ios_base:

floattree=3;

intguess(3。

9832);

intdebt=7。

2E12;

tree=”〈〈tree<

”guess=”<

〈guess<

”debt="

〈debt<

14:

intauks,bats,coots;

auks=19。

99+11.99;

bats=(int)19.99+(int)11.99;

coots=int(19。

99)+int(11.99);

auks="

〈〈auks〈〈”,bats="

〈bats;

”,coots=”〈〈coots<

charch='

Z’;

”Thecodefor”<

ch〈<

is”;

int(ch)<

”Yes,thecodeis”;

//cout〈<

statiic_cast<

int>

(ch)〈<

第四章

1:

intyams[3];

yams[0]=7;

yams[1]=8;

yams[2]=6;

intyamcosts[3]={20,30,5};

Totalyams=”;

yams[0]+yams[1]+yams[2]<

Thepackagewith”<

〈yams[1]〈<

yamscosts"

yamcosts[1]<

”centsperyam.\n"

inttotal=yams[0]*yamcosts[0]+yams[1]*yamcosts[1];

total=total+yams[2]*yamcosts[2];

Thetotalyamexpenseis”〈〈total〈<

cents.\n”;

\nSizeofyamsarray=”<

〈sizeofyams;

cout〈〈”bytes。

\n”;

”Sizeofoneelement="

〈〈sizeofyams[0];

bytes.\n"

2:

constintsize=15;

charname1[size];

charname2[size]=”C++owboy"

Howdy!

I’m”<

〈name2;

cout〈〈”!

what’syourname?

\n”;

name1;

Well,"

〈〈name1<

yournamehas”;

strlen(name1)<

〈”lettersandisstored\n”;

inanarrayof"

〈〈sizeofname1<

Yourinitialis"

name1[0]<

name2[3]='

\0'

〈”Herearethefirst3charchtersofmyname:

name2〈<

constintarsize=20;

charname[arsize];

chardessert[arsize];

”Enteryourname:

name;

Enteryourfavoritedessert:

dessert;

cout〈〈”Ihavesomedelicious”<

dessert;

”foryou,”<

〈name<

〈”。

charname[arsize];

chardessert[arsize];

Enteryourname:

cin.getline(name,arsize);

Enteryourfavoritedessert:

cin。

getline(dessert,arsize);

Ihavesomedelicious"

〈dessert;

foryou,"

〈〈name<

”。

charname[arsize];

”Enteryourname:

get(name,arsize)。

get();

cin.get(dessert,arsize);

〈〈dessert;

foryou,"

name<

”.\n"

6:

string〉

charcharr1[20];

charcharr2[20]="

jaguar”;

stringstr1;

stringstr2=”panther”;

Enterakindoffeline:

〉charr1;

cout〈〈”Enteranotherkindoffeline:

〉str1;

”Herearesomefelines:

charr1<

”<

〈charr2<

〈str1<

〈str2

〈”Thethirdletterin”<

charr2〈〈”is”

〈charr2[2]<

Thethirdletterin”<

〈str2〈〈”is”

〈str2[2]<

7:

string>

strings1="

penguin"

strings2,s3;

Youcanassignonestringobjecttoanother:

s2=s1\n”;

s2=s1;

”s1:

s1〈〈"

s2:

”〈<

s2<

〈”Youcanassignac-stylestringtoastringobject.\n"

cout〈〈”s2=\"

buzzard\”\n”;

s2="

buzzard”;

s2:

s2〈<

Youcanconcatenatestrings:

s3=s1

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

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2