c++primer 第l六章编程练习答案】的更多相关文章

6.11.1 #include<iostream> #include<cctype> int main() { using namespace std; char ch; cin.get(ch); while (ch != '@') { if (isdigit(ch)) cout << ch; else if (isupper(ch)) { ch = tolower(ch); cout << ch; } else if (islower(ch)) { ch…
#include <iostream> #include <cctype> using namespace std; int main() { char in_put; do { cout << "Please enter the letters (enter @ exit):"; cin >> in_put; if (islower(in_put)) cout << "The uppercase of the le…
第六章 函数 一.函数基础 函数定义:包括返回类型.函数名字和0个或者多个形参(parameter)组成的列表和函数体. 调用运算符:调用运算符的形式是一对圆括号 (),作用于一个表达式,该表达式是函数或者指向函数的指针. 圆括号内是用逗号隔开的实参(argument)列表. 函数调用过程: 1.主调函数(calling function)的执行被中断. 2.被调函数(called function)开始执行. 形参和实参:形参和实参的个数和类型必须匹配上. 返回类型: void表示函数不返回任…
1.编写一个程序,创建一个具有26 个元素的数组,并在其中存储26 个小写字母.并让该程序显示该数组的内容. #include<stdio.h> #define SIZE 26 int main(void){ int letter[SIZE]; int i; ;i<SIZE;i++){ letter[i] = 'a'+i; } ;i<SIZE;i++){ printf("The ASCII value for %c is %d \n",letter[i],let…
//1.模板定义以关键字template开始,后跟一个模板参数列表,此列表不能为空.编译器用推断出的模板参数来实例化一个特定版本的函数.类型参数前必须使用class或者typename(推荐使用typename). template <typename T> bool comp(T t0, T t1){return t0 > t1;} //2.除了定义类型参数外,还可以在模板中定义非类型参数.一个非类型参数表示一个值(必须是常量表达式,实际使用过程中,最好只使用整形,而不要使用其他类型)…
#include <iostream> #include <fstream> #include <cstdlib> #include <string> using namespace std; struct patron { double mon; string name; }; int main() { int num,count1=0,count2=0; ifstream fin; char filename[20]; cout<<"…
#include <iostream> #include <fstream> #include <cstdlib> const int SIZE=20; using namespace std; int main() { char filename[SIZE]; char ch; ifstream inFile;//inFile 是有一个ifstream对象 cout<<"Enter name of file: "; cin.get(fi…
#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string words; int yy=0; int fy=0; int other=0; cout<<"Enter words (q to quit):\n"; while(cin>>words) { if(isalpha(words[0]))…
#include <iostream> #include <string> using namespace std; const int MSIZE=100; struct juankuan { string name; double mon; }; int main() { int num; (cin>>num).get(); int *c1=new int[num];//存储捐款超过10000的捐款个体 int count1=0;//记录捐款超过10000的个数 i…
#include <iostream> using namespace std; const double N1=35000; const int N2=15000; const int N3=5000; int main() { double salary; double sui=0; cout<<"Enter the salary: "; while(cin>>salary && salary>=0) { if(salary…
#include <iostream> using namespace std; const int strsize=30; const int BOPSIZE=5; void showmenu() { cout<<"Benevolent Order of Programmers Report\n" "a. display by name b. display by title\n" "c. display by bopname d…
#include <iostream> using namespace std; void showmenu(void) { cout<<"Please enter one of the following choices:\n" "c) carnivore p) pianist\n" "t) tree g) game\n"; } void ak(void) { cout<<"Please enter…
#include <iostream> #include <cctype> using namespace std; const int MAXSIZE=10; int main() { double dd[MAXSIZE]; double donation; double aver=0; int num=0; int i=0; while(i<MAXSIZE && cin>>donation && !isdigit(donatio…
#include <iostream>#include <cctype>using namespace std;int main(){ char ch; while((ch=cin.get())!='@') {  if(isdigit(ch))   continue;  else if(islower(ch))   ch-='z'-'Z';  else if(isupper(ch))   ch+='z'-'Z';  cout<<ch; } system("pa…
#include <iostream>using namespace std;int main(){ int num; cout<<"Enter number of rows: "; (cin>>num).get(); for(int i=1;i<=num;i++) {  for(int j=num-i;j>0;j--)   cout<<".";  for(int k=1;k<=i;k++)   co…
#include <iostream>#include <string>using namespace std;int main (){ string words; int i=0; cout<<"Enter words (to stop, type the word done):\n"; (cin>>words).get(); while(words!="done") {  i++;  (cin>>wor…
#include <iostream>#include <cstring>const MAXSIZE=100;using namespace std;int main (){ char words[MAXSIZE]; int i=0; cout<<"Enter words (to stop, type the word done):\n"; (cin>>words).get(); while(strcmp(words,"done…
#include <iostream>#include <string>using namespace std;struct car{ string pro; int  year;};int main(){ int num; cout<<"How many cars do you wish to catalog? "; (cin>>num).get();//注意将输入后的回车键转换成的换行符读取并丢弃 car *newcar=new ca…
#include <iostream>using namespace std;const MAXSIZE=12;const year=3;int main(){ char *month[MAXSIZE]={"Janury","February","March","April","May","June","July","August",&…
#include <iostream>using namespace std;const MAXSIZE=12;int main(){ char *month[MAXSIZE]={"Janury","February","March","April","May","June","July","August","Septembe…
#include <iostream>using namespace std;int main(){ double count=0; long double cleo=100; long double dap=100; do {  cleo+=cleo*0.05;  dap+=10;  count++; }while(cleo<dap); cout<<"经过"<<count<<"年,cleo的财富 "<&l…
#include <iostream>using namespace std;const int MAXSIZE=100;int main(){ int a[MAXSIZE]; int sum=0; for(int i=0;i<MAXSIZE;i++) {  cin>>a[i];  if(a[i]==0)   return 0;     sum=sum+a[i];  cout<<"sum= "<<sum; } system(&quo…
#include <iostream>using namespace std;int main(){ int min,max; cout<<"Enter the min: "; cin>>min; cout<<"Enter the max: "; cin>>max; int sum=0; for(int i=min;i<=max;i++)  sum+=i; cout<<"The…
#include <iostream>#include <string>using namespace std;struct CandyBar{ //string kind; char kind[20]; float weight; double calory;};void Display(CandyBar ca,int n){    cout<<"The kind of ca["<<n<<"] is: "…
#include <iostream>using namespace std;const int Size=20;struct Pizza{ char company[Size]; double diameter; double weight;};int main(){ Pizza *piz=new Pizza;//使用new创建动态结构 cout<<"What's the diameter of pizza: "; cin>>piz->dia…
#include <iostream>using namespace std;struct Pizza{ char company[50]; float diameter; float weight;};int main(){ Pizza piz; cout<<"Enter the company name: "; cin.getline(piz.company,50); cout<<"The name of pizza company i…
#include <iostream>using namespace std;struct CandyBar{ char kind[20]; float weight; int calory;};void Display(CandyBar ca,int n){    cout<<"The kind of ca["<<n<<"] is: "<<ca.kind<<endl; cout<<…
#include <iostream>using namespace std;struct CandyBar{ char kind[20]; float weight; int calory;}; int main(){ CandyBar snack= {  "Mocha Munch",  2.3,  350 }; cout<<"The kind of snack is: "<<snack.kind<<endl; co…
#include <iostream>#include <string>using namespace std;int main(){ string fname; string lname; string name; cout<<"Enter your first name: "; getline(cin,fname); cout<<"Enter your last name: "; getline(cin,lname…
#include <iostream>#include <cstring>using namespace std;int main(){ char fname[20]; char lname[20]; char name[45]; cout<<"Enter your first name: "; cin.getline(fname,20); cout<<"Enter your last name: "; cin.get…