1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int num_1,num_2,sum=;
  7.  
  8. cout << "Please enter two number: ";
  9. cin >> num_1;
  10. cin >> num_2;
  11.  
  12. if (num_1 > num_2)
  13. {
  14. int a;
  15. a = num_1;
  16. num_1 = num_2;
  17. num_2 = a;
  18. }
  19.  
  20. for (int i = num_1; i <= num_2; i++)
  21. {
  22. sum += i;
  23. }
  24. cout << "The sum of num_1-num_2 is " << sum << endl;
  25.  
  26. system("pause");
  27. }

  

  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4. const int num=;
  5.  
  6. int main()
  7. {
  8. array<long double, num+> jiecheng;
  9. jiecheng[] = jiecheng[] = ;
  10. cout << << "! = " << jiecheng[] << endl;
  11. cout << << "! = " << jiecheng[] << endl;
  12. for (int i = ; i <= num; ++i)
  13. {
  14. jiecheng[i] = i * jiecheng[i - ];
  15. cout << i << "! = " << jiecheng[i]<<endl;
  16. }
  17.  
  18. system("pause");
  19. }

  1. #include <iostream>
  2. #include <array>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a,b=;
  8. cout << "Please enter a number other than zero: ";
  9. do
  10. {
  11. cin >> a;
  12. if (a == )
  13. cout << "Stop summing!\n";
  14. else
  15. {
  16. b = b + a;
  17. cout << "The sum of the numbers already entered is: " << b << endl;
  18. }
  19.  
  20. } while (a != );
  21. system("pause");
  22. }

  1. #include <iostream>
  2. using namespace std;
  3. const float lixi1 = 0.1;
  4. const float lixi2 = 0.05;
  5.  
  6. int main()
  7. {
  8. float Daphne_i = , Cleo_i = , Daphne = Daphne_i, Cleo = Cleo_i;
  9. int year = ;
  10.  
  11. while (Daphne >= Cleo)
  12. {
  13. Daphne = Daphne + Daphne_i * lixi1;
  14. Cleo = Cleo + Cleo * lixi2;
  15. year += ;
  16. // cout << Daphne << "," << Cleo<<"--"<< year<<endl;
  17. }
  18. cout << "In " << year << "th years, Cleo's funds exceed Daphne.\nAt this time, the funds of Cleo are " << Cleo << ", and the funds of Daphne are " << Daphne << ".\n";
  19. system("pause");
  20. }

  1. #include <iostream>
  2. using namespace std;
  3. const int month = ;
  4.  
  5. int main()
  6. {
  7. int num[month];
  8. int sum = ;
  9. const char* months[month] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
  10.  
  11. cout << "Please enter the monthly sales volume:\n";
  12. for (int i = ; i < month; ++i)
  13. {
  14. cout << months[i] << " : ";
  15. cin >> num[i];
  16. sum += num[i];
  17. }
  18.  
  19. cout << "The total sales this year is " << sum << ".\n";
  20.  
  21. system("pause");
  22. }

  1. #include <iostream>
  2. using namespace std;
  3. const int year = ;
  4. const int month = ;
  5.  
  6. int main()
  7. {
  8. int num[year][month];
  9. int sum[] = { ,,, };
  10. const char* months[month] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
  11.  
  12. for (int j = ; j < year; ++j)
  13. {
  14. cout << "Please enter the monthly sales volume of " << j + << "th year:\n";
  15. for (int i = ; i < month; ++i)
  16. {
  17. cout << months[i] << " : ";
  18. cin >> num[j][i];
  19. sum[j] += num[j][i];
  20. }
  21. cout << "The total sales of " << j+ << "th year is "<< sum[j] << ".\n";
  22. sum[year] = sum[year] + sum[j];
  23. }
  24.  
  25. cout << "The total sales of " << year << " years are "<<sum[year] << ".\n";
  26.  
  27. system("pause");
  28. }

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. struct car
  6. {
  7. string make;
  8. int year;
  9. };
  10.  
  11. int main()
  12. {
  13. int num;
  14.  
  15. cout << "How many cars do you wish to catalog?";
  16. cin >> num;
  17. car *all_car = new car[num];
  18.  
  19. for (int i = ; i < num; ++i)
  20. {
  21. cout << "Car #" << i+ << endl;
  22. cout << "Please enter the make : ";
  23. cin.ignore();
  24. getline(cin, all_car[i].make);
  25. cout << "Please enter the year made : ";
  26. cin >> all_car[i].year;
  27. }
  28.  
  29. cout << "Here is your collection:\n";
  30. for (int i = ; i < num; ++i)
  31. {
  32. cout << all_car[i].year << " " << all_car[i].make << endl;
  33. }

  34. delete [] all_car;
  35. system("pause");
  36. }

  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. const int num_words = ;
  5.  
  6. int main()
  7. {
  8. char words[];
  9. int s = ;
  10. bool flag = true;
  11.  
  12. cout << "Enter words (to stop, tpye the word done) :\n";
  13. for (int i = ; i < num_words; ++i)
  14. {
  15. cin >> words;
  16. if (flag && !strcmp(words, "done"))
  17. flag = false;
  18. if (flag && strcmp(words, "done"))
  19. s += ;
  20.  
  21. }
  22.  
  23. cout << "Your entered a total of " << s << " words.\n";
  24.  
  25. system("pause");
  26. }

  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. const int num_words = ;
  5.  
  6. int main()
  7. {
  8. const string sstop_word = "done";
  9. string str;
  10. int s = ;
  11. bool flag = true;
  12.  
  13. cout << "Enter words (to stop, tpye the word done) :\n";
  14. for (int i = ; i < num_words; ++i)
  15. {
  16. cin >> str;
  17. if (flag && str== sstop_word)
  18. flag = false;
  19. if (flag && !(str == sstop_word))
  20. s += ;
  21.  
  22. }
  23.  
  24. cout << "Your entered a total of " << s << " words.\n";
  25.  
  26. system("pause");
  27. }

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int num;
  7. cout << "Enter number of rows: ";
  8. cin >> num;
  9.  
  10. for (int i = ; i < num; ++i)
  11. {
  12. for (int j = ; j < (num - i); ++j)
  13. cout << ".";
  14. for (int j = ; j < i; ++j)
  15. cout << "*";
  16. cout << endl;
  17. }
  18.  
  19. system("pause");
  20. }

c++ primer plus 第五章 课后题答案的更多相关文章

  1. c++ primer plus 第七章 课后题答案

    #include <iostream> using namespace std; double HAR_AVG(double, double); void TEST(bool); int ...

  2. c++ primer plus 第六章 课后题答案

    #include <iostream> #include <cctype> using namespace std; int main() { char in_put; do ...

  3. c++ primer plus 第四章 课后题答案

    #include<iostream> #include<string> using namespace std; int main() { string first_name; ...

  4. c++ primer plus 第三章 课后题答案

    #include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please ...

  5. C程序设计(谭浩强)第五版课后题答案 第一章

    大家好,这篇文章分享了C程序设计(谭浩强)第五版课后题答案,所有程序已经测试能够正常运行,如果小伙伴发现有错误的的地方,欢迎留言告诉我,我会及时改正!感谢大家的观看!!! 1.什么是程序?什么是程序设 ...

  6. c++ primer plus 第二章 课后题答案

    #include<iostream> using namespace std; int main() { cout << "My name is Jiantong C ...

  7. python核心编程第5章课后题答案

    5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the ...

  8. python核心编程第4章课后题答案(第二版75页)

    4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...

  9. python核心编程第3章课后题答案(第二版55页)

    3-4Statements Ues ; 3-5Statements Use\(unless part of a comma-separated sequence in which case \ is ...

随机推荐

  1. 摘自(http://www.ruanyifeng.com/blog/2011/07/linux_load_average_explained.html)

    理解Linux系统负荷   作者: 阮一峰 一.查看系统负荷 如果你的电脑很慢,你或许想查看一下,它的工作量是否太大了. 在Linux系统中,我们一般使用uptime命令查看(w命令和top命令也行) ...

  2. Django初级手册3-视图层与URL配置

    设计哲学 在Django中一个视图有指定函数和指定模版组成.对于某些特定的应用应该分成若干视图.例如博客系统 Blog主页面 详细页面入口 基于年的页面展示 基于月的页面展示 基于天的页面展示 评论行 ...

  3. java的时间处理

    采用joda.time库 gradle,可以简化calendar的 compile "joda-time:joda-time:2.7" 例子:http://blog.csdn.ne ...

  4. VS2010/MFC编程入门之五十一(图形图像:GDI对象之画刷CBrush)

    上一节中鸡啄米主要讲的是画笔CPen的用法,前面也说了,GDI对象中最常用的就是画笔和画刷,本节就讲讲画刷CBrush. 鸡啄米依然是通过实例的方式来说明画刷的用法.此实例要实现的功能是,对话框上有一 ...

  5. EditPlus 4.3.2555 中文版已经发布

    新的版本修复了之前版本出现的多行文本缩进调整的问题. 下载连接在页面左上角!

  6. jQuery 批量操作checkbox

    困扰很久的问题: 如果只是 $('input[type=checkbox]').attr('checked',true);//全选 $('input[type=checkbox]').attr('ch ...

  7. ROS知识(2)----理解ROS系统结构

    学习新事物,方法高于技术本身,如果没有把握"BIG PICTURE"的话很难理解进去.通过以下几点进行理解ROS: ROS实际上不是操作系统,他只是一个通信的框架,一个代码管理的架 ...

  8. 完美解决Linux服务器tomcat开机自启动问题

    经过多次测试终于彻底解决tomcat开机自启动的问题了 PID3=`ps aux | grep /home/server/shichuan/ | grep java | awk '{print $2} ...

  9. 基于webview的Hybrid app和React Native及html5

    基于webview的Hybrid app和React Native及html5 React Native 结合了 Web 应用和 Native 应用的优势,可以使用 JavaScript 来开发 iO ...

  10. linux chkconfig 管理服务开机自启动

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...