欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    C++Primer Plus第六章编程练习.doc

    • 资源ID:52755627       资源大小:34.50KB        全文页数:10页
    • 资源格式: DOC        下载积分:20金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要20金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C++Primer Plus第六章编程练习.doc

    第六章编程练习1、#include <iostream>#include <cctype>int main() using namespace std; char ch; cin.get(ch); while(ch!='') if(isdigit(ch) cin.get(ch); else if(islower(ch) ch=toupper(ch); else ch=tolower(ch); cout<<ch; cin.get(ch); system("pause"); return 0; 2、#include <iostream>int main() using namespace std; double sum=0; double average=0; double num10; int i=0,total=0; double tmp; while(cin>>tmp&&i<10) numi=tmp; sum+=numi; +i; if(i!=0) average=sum/i; for(int j=0;j<i;+j) if(numj>average) +total; cout<<"这些数字的平均值为"<<average<<endl; cout<<"并且共有"<<total<<"个数字大于平均值。n" system("pause"); return 0; 3、#include <iostream>int main() using namespace std; cout<<"Please enter one of the following choices:n" <<"c)carnivore p)pianistn" <<"t)tree g)gamenfn" cout<<"Please enter a c, p, t, or g: " char ch; cin>>ch; while(ch!='c'&&ch!='p'&&ch!='t'&&ch!='g') cout<<"Please enter a c, p, t, or g: " cin>>ch; switch(ch) case 'c': cout<<"A maple is a tree.n" break; case 'p': cout<<"A maple is a pianist.n" break; case 't': cout<<"A maple is a tree.n" break; case 'g': cout<<"A maple is a game.n" system("pause"); return 0; 4、#include <iostream>const int strsize=20;struct bop char fullnamestrsize; char titlestrsize; char bopnamestrsize; int preference;int main() std:cout<<"Benevolent Order of Programmers Reportn" "a. display by name b. display by titlen" "c. display by bopname d. diplay by preferencen" "q. quit" char ch; bop member5="Wimp Macho","English Teacher","DEMON",0, "Raki Rhodes","Junior Programmer","BOOM",1, "Celia Laiter","Super Star","MIPS",2, "Hoppy Hipman","Analyst Trainee","WATEE",1, "Pat Hand","Police","LOOPY",2; std:cout<<"Enter your choice:" while(std:cin>>ch&&ch!='q') switch(ch) case 'a': for(int i=0;i<5;i+) std:cout<<memberi.fullname<<std:endl; break; case 'b': for(int i=0;i<5;i+) std:cout<<memberi.title<<std:endl; break; case 'c': for(int i=0;i<5;i+) std:cout<<memberi.bopname<<std:endl; break; case 'd': for(int i=0;i<5;i+) if(memberi.preference=0) std:cout<<memberi.fullname<<std:endl; else if(memberi.preference=1) std:cout<<memberi.title<<std:endl; else if(memberi.preference=2) std:cout<<memberi.bopname<<std:endl; std:cout<<"Next choice: " std:cout<<"Bye!n" system("pause"); return 0;5、#include <iostream>int main() using namespace std; double income,revenue; cout<<"请输入你的收入:" while(cin>>income&&income>=0) if(income<=5000) revenue=0.0; else if(income>5000&&income<=15000) revenue=0.1*(income-5000); else if(income>15000&&income<=35000) revenue=0.1*(15000-5000)+0.15*(income-15000); else revenue=0.1*(15000-5000)+0.15*(35000-15000)+0.2*(income-35000); cout<<"你的所得税为"<<revenue<<endl; cout<<"请输入你的收入:" system("pause"); return 0;6、#include <iostream>#include <string>struct patron std:string name; double money;int main() using namespace std; int num,tmp=0; cout<<"请输入捐款的人数:" cin>>num; cin.get(); patron *ps=new patronnum; for(int i=0;i<num;+i) cout<<"请输入第"<<i+1<<"位捐款人的名字:" getline(cin,psi.name); cout<<"请输入第"<<i+1<<"位捐款人捐款的数目:" cin>>psi.money; cin.get(); cout<<"Grand Patrons:n" for(int i=0;i<num;+i) if(psi.money>10000) cout<<psi.name<<endl; +tmp; if(tmp=0) cout<<"nonen" cout<<"Patrons:n" for(int i=0;i<num;+i) if(psi.money<=10000) cout<<psi.name<<endl; +tmp; if(tmp=0) cout<<"nonen" delete ps; system("pause"); return 0; 7、#include <iostream>#include <cctype>int main() using namespace std; int vowel,consonant,other; vowel=consonant=other=0; char word15; cout<<"Enter words (q to quit):n" while(cin>>word) if(isalpha(word0) if(word0='q'&&strlen(word)=1) break; else if(word0='a'|word0='i'| word0='u'|word0='e'|word0='o') +vowel; else +consonant; else +other; cout<<vowel<<" words beginning with vowelsn" cout<<consonant<<" words beginning with consonantsn" cout<<other<<" othersn" system("pause"); return 0; 8、#include <iostream>#include <fstream>#include <cstdlib>int main() using namespace std; char ch; int sum=0; ifstream inFile; inFile.open("abc.txt"); if(!inFile.is_open() cout<<"Could not open the file n" cout<<"Program terminating.n" exit(EXIT_FAILURE); inFile>>ch; while(inFile.good() +sum; inFile>>ch; if(inFile.eof() cout<<"End of file reached.n" else if(inFile.fail() cout<<"Input terminated by data mismatch.n" else cout<<"Input terminated for unkonwn reason.n" cout<<"总共有"<<sum<<"个字符在这个文件中。"<<endl; system("pause"); return 0; 9、#include <iostream>#include <fstream>#include <cstdlib>struct member char name20; double donation;int main() using namespace std; int num; int count1=0; int count2=0; ifstream fin; char file20; cout<<"Enter name of data file: " cin.getline(file,20); fin.open(file); if(!fin.is_open() cout<<"Could not open the file-"<<file<<endl; cout<<"Program terminating.n" exit(EXIT_FAILURE); fin>>num; fin.get(); member *pd=new membernum; for(int i=0;i<num;i+) fin.getline(pdi.name,20); fin>>pdi.donation; fin.get(); cout<<"Grand Patrons:n" for(int i=0;i<num;i+) if(pdi.donation>=10000) cout<<pdi.name<<" "<<pdi.donation<<endl; count1+; if(count1=0) cout<<"nonen" cout<<"Patrons:n" for(int i=0;i<num;i+) if(pdi.donation<10000) cout<<pdi.name<<" "<<pdi.donation<<endl; count2+; if(count2=0) cout<<"nonen" delete pd; system("pause"); return 0;

    注意事项

    本文(C++Primer Plus第六章编程练习.doc)为本站会员(飞****2)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开