C++primer.plus
路易宫里的红泥小火炉
天高地迥,觉宇宙之无穷;兴尽悲来,识盈虚之有数。
展开
-
C++Primer.plus第五章5.9编程练习第9题
# include <iostream>#include <string>int main(){ using namespace std; cout<<"Enter a word: "; string word; cin>>word; //物理修改字符串对象 char temp; int i, j; for (j = 0, i = word.size() - 1; j < i; --i, ++j) { tem...原创 2021-08-25 09:54:33 · 103 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第8题
//5.8 block.cpp -- use a block statement# include <iostream>int main(){ using namespace std; cout<<"The Amazing Accounto will sum average "; cout<<"five number for you.\n"; cout<<"Please enter five values: \n"; doub...原创 2021-08-25 09:53:27 · 108 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第7题
// plus_one.cpp -- the increment operator(递增操作符)# include <iostream>int main(){ using namespace std; int a = 20; int b = 20; cout<<"a = "<<a<<"; b = "<<b<<"\n"; cout<<"a++ = "<<a++<<"; ++b ...原创 2021-08-25 09:52:08 · 115 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第6题
// forstr1.cpp -- using for with a string# include <iostream># include <string>int main(){ using namespace std; cout<<"Enter a word: "; string word; cin>>word; //用相反的方向打印字符串 for (int i = word.size()-1;i >= 0; i--)...原创 2021-08-25 09:50:07 · 142 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第5题
//bigstep.cpp -- count as directed# include <iostream>int main(){ using namespace std; cout<<"Enter an integer: "; int by; cin>>by; cout<<"Counting by "<<by<<"s: \n"; for (int i = 0; i < 100; i = i + by)...原创 2021-08-25 09:47:53 · 106 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第4题
// formore.cpp -- more looping with for(更多使用循环for)阶乘# include <iostream>using namespace std;const int ArSize = 16; //外部声明示例int main(){ double factorials[ArSize]; factorials[1] = factorials[0] = 1.0; int i; for(i = 2;i < ArSize;i++)...原创 2021-08-25 09:43:12 · 103 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第3题
//5.3 expression.cpp -- values of expressions# include <iostream>using namespace std;int main(){ int x; cout<<"The expression x = 100 has the value "; cout<<(x = 100)<<endl; cout<<"Now x = "<<x<<en...原创 2021-08-25 09:41:52 · 89 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第2题
//num_test.cpp -- use numeric test in for loop# include <iostream>int main(){ using namespace std; cout<<"Enter the starting countdown value: "; int limit; cin>>limit; int i; for(i = limit; i;i--) { cout<<"i = "<...原创 2021-08-25 09:40:34 · 94 阅读 · 0 评论 -
C++Primer.plus第五章5.9编程练习第1题
//5.1 forloop.cpp -- introducing the for loop(引入for循环)# include <iostream>int main(){ using namespace std; int i; //创造一个计数器 //初始化、测试、更新 for(i = 0;i < 5;i++) { cout<<"C++ knows when loops.\n"; } cout<<"C++ knows when t...原创 2021-08-25 09:38:14 · 106 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第9题
编程练习6链接:https://blog.csdn.net/qq_34847850/article/details/119509313?spm=1001.2014.3001.5501根据上面内容做题://4.11.9.cpp -- 使用new和数组、结构体# include <iostream># include <string>using namespace std;struct CandyBar{ string kind; double we...原创 2021-08-08 10:17:27 · 107 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第8题
编程练习7链接:https://blog.csdn.net/qq_34847850/article/details/119509429?spm=1001.2014.3001.5501根据上面内容做题://4.141.8.cpp -- 使用new和结构体# include <iostream>using namespace std;struct Pizza{ char name[80]; float diameter; float weight;};in...原创 2021-08-08 10:15:08 · 174 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第7题
//4.11.7.cpp -- 结构体的输入和输出# include <iostream>using namespace std;struct Pizza{ char name[80]; float diameter; float weight;};int main(){ Pizza kehu1; cout<<"请输入比萨饼的公司名称:"; cin.getline(kehu1.name,80); cout<<"请输入比萨饼的直径:"...原创 2021-08-08 10:12:48 · 387 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第6题
编程练习5的链接:https://blog.csdn.net/qq_34847850/article/details/119509236?spm=1001.2014.3001.5501根据上面内容做题://4.11.6.cpp -- 结构体和数组# include <iostream>using namespace std;struct CandyBar{ char kind[80]; float weight; int calorie;};int ...原创 2021-08-08 10:11:24 · 134 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第5题
//4.11.5.cpp -- 结构体# include <iostream>using namespace std;struct CandyBar{ char kind[80]; float weight; int calorie;};int main(){ CandyBar snack={"Mocha Munch",2.3,350}; cout<<"糖块的品牌: "<<snack.kind<<"\n"; cout<...原创 2021-08-08 10:06:24 · 162 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第4题
//4.11.4.cpp -- string对象和头文件string函数# include <iostream># include <string>int main(){ using namespace std; string Fistname; string Lastname; cout<<"Enter your fist name: "; cin>>Fistname; cout<<"Enter your last n...原创 2021-08-08 10:04:51 · 100 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第3题
//4.11.3.cpp -- char和cstring函数# include <iostream>#include <cstring>int main(){ using namespace std; char Fistname[30]; char Lastname[30]; cout<<"Enter your fist name: "; cin>>Fistname; cout<<"Enter your last nam...原创 2021-08-08 10:03:03 · 119 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第2题
程序清单4.4//instr2.cpp -- reading more than one word with getline# include <iostream>int main(){ using namespace std; const int ArSize = 20; char name[ArSize]; char dessert[ArSize]; cout<<"Enter your name:\n"; cin.getline(name,ArS..原创 2021-08-08 10:00:59 · 212 阅读 · 0 评论 -
C++Primer.plus第四章4.11编程练习第1题
//4.11.1.cpp -- 字符串和cout# include <iostream>int main(){ using namespace std; char name1[80]; char name2[80]; cout<<"What is your fist name? "; cin.getline(name1,80); cout<<"What is your last name? "; cin.getline(name2,80); ...原创 2021-08-08 09:55:45 · 97 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第6题
//3.7_cpp# include <iostream>int main(){ using namespace std; const int K = 100; const double F = 62.14; const double L = 3.875; double Ju=0,Ran=0,l=0; double Ranl=1,Jul=100; cout<<"Enter the UK the Fuel consumption: "; cin>...原创 2021-08-07 11:05:05 · 522 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第5题
//3.7_5.cpp 耗油量/里程# include <iostream>int main(){ using namespace std; double mile=0,gallon=0,L=0; cout<<"Enter the mileage: "; cin>>mile; cout<<"Enter the Fuel consumption: "; cin>>gallon; L = mile / gallon...原创 2021-08-07 11:02:45 · 285 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第4题
//3.7_4.cpp # include <iostream>int main(){ using namespace std; const int Dver = 24; const int Hver = 60; const int Mver = 60; long seconds = 0; cout<<"Enter the number of seconds: "; cin>>seconds; int s = seconds % Mver;...原创 2021-08-07 11:00:14 · 101 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第3题
//3.7_3.cpp# include <iostream>int main(){ using namespace std; const double Cver = 1/60.0; int degrees=0,minutes=0,seconds=0; cout<<"Enter alatitude in degrees,minutes, and seconds:\n"; cout<<"First,enter the degrees: "; c...原创 2021-08-07 10:54:51 · 115 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第2题
//3.7-2.cpp # include <iostream>int main(){ using namespace std; const int Cver = 12; const double Mver = 0.0254; const double Kver = 2.2; float foot=0,inch=0,pound=0,kg=0,BMI=0; cout<<"Please enter your height(foot and inch):\n...原创 2021-08-07 10:50:56 · 132 阅读 · 0 评论 -
C++Primer.plus第三章3.7编程练习第1题
//3.7_1.cpp 1英尺=12英寸# include <iostream>int main(){ using namespace std; const int Cver = 12; //定义常量,英尺转换英寸因子 int inch = 0; //定义初始化英寸,等待输入 cout<<"Please enter your height (inch and integer):__\b\b"; //提示用户输入 cin>>...原创 2021-08-07 10:46:58 · 94 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第6题
//2.7_6.cpp 小时和分钟显示# include <iostream>using namespace std;void func(int,int);int main(){ int hours=0,minutes=0; cout<<"Enter the number of hours: "; cin>>hours; cout<<"Enter the number of minutes: "; cin>>min...原创 2021-08-06 23:05:32 · 73 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第4题
//2.7_4.cpp 摄氏度转华摄氏度# include <iostream>using namespace std;int Fahrenheit(int);int main(){ int Celsius=0; cout<<"Please enter a Celaius value: "; cin>>Celsius; int Fah=Fahrenheit(Celsius); cout<<Celsius<<" d...原创 2021-08-06 23:01:43 · 375 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第5题
//2.7_5.cpp 光年转天文值# include <iostream>using namespace std;int GN(double);int main(){ double guang; cout<<"Enter the number of light years: "; cin>>guang; int TW=GN(guang); cout<<guang<<" light years = "<<...原创 2021-08-06 23:05:05 · 58 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第3题
//2.7_3.cpp 三个函数# include <iostream>using namespace std;void func1();void func2();int main(){ func1(); func1(); func2(); func2(); return 0;}void func1(){ cout<<"Three blind mice \n";}void func2(){ cout<<"See ho...原创 2021-08-06 22:56:43 · 204 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第2题
//2.7_2.cpp 浪转码# include <iostream>using namespace std;int main(){ int Lang; cout<<"输入一个以浪为单位的距离:"; cin>>Lang; int Ma=Lang*220; cout<<Lang<<"浪="<<Ma<<"码\n"; return 0;}/*输出结果:输入一个以浪为单位的距离:11浪=2...原创 2021-08-06 22:42:26 · 119 阅读 · 0 评论 -
C++Primer.plus第二章2.7编程练习第1题
//2.7_1.cpp 显示姓名和地址,姓名:张三李四,地址:广东广州市大学城宿舍# include <iostream>using namespace std;//名称空间,using编译指令int main() //主函数{ cout<<"姓名:张三李四\n"; //<<插入操作符,\n换行符 cout<<"地址:广东广州市大学城宿舍\n"; return 0; //结束主函数}/*输出结果:姓...原创 2021-08-06 22:35:44 · 65 阅读 · 0 评论