C++Primer Plus第六章编程练习Word下载.docx
《C++Primer Plus第六章编程练习Word下载.docx》由会员分享,可在线阅读,更多相关《C++Primer Plus第六章编程练习Word下载.docx(13页珍藏版)》请在冰豆网上搜索。
<
ch;
}
system("
pause"
);
return0;
}
2、
doublesum=0;
doubleaverage=0;
doublenum[10];
inti=0,total=0;
doubletmp;
while(cin>
>
tmp&
&
i<
10)
num[i]=tmp;
sum+=num[i];
++i;
if(i!
=0)
average=sum/i;
for(intj=0;
j<
i;
++j)
if(num[j]>
average)
++total;
"
这些数字的平均值为"
average<
endl;
并且共有"
total<
个数字大于平均值。
\n"
;
3、
Pleaseenteroneofthefollowingchoices:
<
c)carnivorep)pianist\n"
t)treeg)game\nf\n"
Pleaseenterac,p,t,org:
"
cin>
c'
ch!
p'
t'
g'
switch(ch)
case'
:
Amapleisatree.\n"
break;
Amapleisapianist.\n"
Amapleisagame.\n"
}
4、
constintstrsize=20;
structbop
charfullname[strsize];
chartitle[strsize];
charbopname[strsize];
intpreference;
};
std:
cout<
BenevolentOrderofProgrammersReport\n"
a.displaybynameb.displaybytitle\n"
c.displaybybopnamed.diplaybypreference\n"
q.quit"
bopmember[5]={{"
WimpMacho"
"
EnglishTeacher"
DEMON"
0},
{"
RakiRhodes"
JuniorProgrammer"
BOOM"
1},
CeliaLaiter"
SuperStar"
MIPS"
2},
HoppyHipman"
AnalystTrainee"
WATEE"
PatHand"
Police"
LOOPY"
2}};
Enteryourchoice:
while(std:
cin>
ch&
q'
a'
for(inti=0;
5;
i++)
member[i].fullname<
std:
b'
member[i].title<
member[i].bopname<
d'
if(member[i].preference==0)
if(member[i].preference==1)
if(member[i].preference==2)
Nextchoice:
Bye!
5、
doubleincome,revenue;
请输入你的收入:
income&
income>
if(income<
=5000)
revenue=0.0;
elseif(income>
5000&
income<
=15000)
revenue=0.1*(income-5000);
15000&
=35000)
revenue=0.1*(15000-5000)+0.15*(income-15000);
revenue=0.1*(15000-5000)+0.15*(35000-15000)+0.2*(income-35000);
你的所得税为"
revenue<
6、
string>
structpatron{
stringname;
doublemoney;
intnum,tmp=0;
请输入捐款的人数:
num;
cin.get();
patron*ps=newpatron[num];
++i)
请输入第"
i+1<
位捐款人的名字:
getline(cin,ps[i].name);
位捐款人捐款的数目:
ps[i].money;
GrandPatrons:
if(ps[i].money>
10000)
ps[i].name<
++tmp;
if(tmp==0)
none\n"
Patrons:
if(ps[i].money<
=10000)
delete[]ps;
7、
intvowel,consonant,other;
vowel=consonant=other=0;
charword[15];
Enterwords(qtoquit):
word)
if(isalpha(word[0]))
if(word[0]=='
strlen(word)==1)
elseif(word[0]=='
||word[0]=='
i'
||
word[0]=='
u'
e'
o'
++vowel;
++consonant;
++other;
vowel<
wordsbeginningwithvowels\n"
consonant<
wordsbeginningwithconsonants\n"
other<
others\n"
8、
fstream>
cstdlib>
intsum=0;
ifstreaminFile;
inFile.open("
abc.txt"
if(!
inFile.is_open())
Couldnotopenthefile\n"
Programterminating.\n"
exit(EXIT_FAILURE);
inFile>
while(inFile.good())
++sum;
if(inFile.eof())