1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string first_name;
  9. string last_name;
  10. char grade;
  11. int age;
  12.  
  13. cout << "What is your first name? ";
  14. getline(cin,first_name);
  15. cout << endl << "What is your last name? ";
  16. getline(cin,last_name);
  17. cout << endl << "What letter grade do you deserve? ";
  18. cin >> grade;
  19. cout << endl << "What is your age? ";
  20. cin >> age;
  21.  
  22. cout << "Name: " << last_name << ", " << first_name << endl;
  23. cout << "Grade: " << char(grade + ) << endl;
  24. cout << "Age: " << age << endl;
  25. cin.get();
  26. cin.get();
  27. return ;
  28. }

  1. #include <iostream>
  2. #include<string>
  3.  
  4. int main()
  5. {
  6. using namespace std;
  7.  
  8. string name;
  9. string dessert;
  10.  
  11. cout << "Enter your name:\n";
  12. getline(cin,name);
  13. cout << "Enter your favorite dessert:\n";
  14. getline(cin,dessert);
  15. cout << "I have some delicious " << dessert;
  16. cout << " for you, " << name << ".\n";
  17. cin.get();
  18. return ;
  19. }

  1. #include<iostream>
  2. #include<cstring>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. char first_name[];
  9. char last_name[];
  10. char name[];
  11.  
  12. cout << "Enter your first name: ";
  13. cin >> first_name;
  14. cout << endl << "Enter your last name: ";
  15. cin >> last_name;
  16.  
  17. strcpy_s(name, last_name);
  18. strcat_s(name, ",");
  19. strcat_s(name, first_name);
  20. cout << endl << "Here’s the information in a single string: " << name;
  21.  
  22. //cout << endl << "Here’s the information in a single string: " << last_name << " , " << first_name;
  23.  
  24. cin.get();
  25. cin.get();
  26. return ;
  27. }

  1. #include<iostream>
  2. #include<string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. string first_name;
  9. string last_name;
  10. string name;
  11.  
  12. cout << "Enter your first name: ";
  13. getline(cin,first_name);
  14. cout << "Enter your last name: ";
  15. getline(cin,last_name);
  16.  
  17. name = last_name + "," + first_name;
  18. cout << "Here's the information in a single string: " << name << endl;
  19. cin.get();
  20. //system("pause");
  21. return ;
  22. }

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct CandyBar
  5. {
  6. char bard[];
  7. double weight;
  8. int calories;
  9. };
  10.  
  11. int main()
  12. {
  13. CandyBar snack =
  14. {
  15. "Mocha Munch",
  16. 2.3,
  17.  
  18. };
  19.  
  20. cout << "The bard of this candy is: " << snack.bard << endl;
  21. cout << "The weight of this candy is: " << snack.weight << endl;
  22. cout << "The calories of this candy is: " << snack.calories << endl;
  23.  
  24. cin.get();
  25. return ;
  26. }

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Candy {
  5. char name[];
  6. double weight;
  7. int calories;
  8. };
  9.  
  10. int main() {
  11. //Candy snack[3];
  12. //snack[0] = { "Mocha Munch1", 2.3, 350 };
  13. //snack[1] = { "Mocha Munch2", 2.5, 360 };
  14. //snack[2] = { "Mocha Munch3", 2.7, 390 };
  15. Candy snack[] = { { "Mocha Munch1", 2.3, } ,
  16. { "Mocha Munch2", 2.5, } ,
  17. { "Mocha Munch3", 2.7, } };
  18. cout << snack[].name << "'s weight is " << snack[].weight <<
  19. ", and it includes " << snack[].calories << " calories.\n";
  20. cout << snack[].name << "'s weight is " << snack[].weight <<
  21. ", and it includes " << snack[].calories << " calories.\n";
  22. cout << snack[].name << "'s weight is " << snack[].weight <<
  23. ", and it includes " << snack[].calories << " calories.\n";
  24.  
  25. system("pause");
  26. return ;
  27. }

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Pizza
  5. {
  6. char name[];
  7. double diameter;
  8. double weight;
  9. };
  10.  
  11. int main()
  12. {
  13. Pizza x;
  14. cout << "Please enter the name of this pizza: ";
  15. cin >> x.name;
  16. cout << "Please enter the diameter of this pizza: ";
  17. cin >> x.diameter;
  18. cout << "Please enter the weight of this pizza: ";
  19. cin >> x.weight;
  20.  
  21. cout << "The name of this pizza is " << x.name << endl;
  22. cout << "The diameter of this pizza is " << x.diameter << endl;
  23. cout << "The weight of this pizza is " << x.weight << endl;
  24.  
  25. system("pause");
  26. return ;
  27. }

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Pizza {
  5. char name[];
  6. double diameter;
  7. double weight;
  8. };
  9.  
  10. int main() {
  11. Pizza *pizza = new Pizza;
  12. cout << "Please enter the name of this pizza: ";
  13. cin >> pizza->name;
  14. cout << "Please enter the diameter of this pizza: ";
  15. cin >> pizza->diameter;
  16. cout << "Please enter the weight of this pizza: ";
  17. cin >> pizza->weight;
  18.  
  19. cout << "The name of this pizza is " << pizza->name << endl;
  20. cout << "The diameter of this pizza is " << pizza->diameter << endl;
  21. cout << "The weight of this pizza is " << pizza->weight << endl;
  22.  
  23. delete pizza;
  24.  
  25. system("pause");
  26. return ;
  27. }

  1. #include<iostream>
  2. using namespace std;
  3.  
  4. struct Candy {
  5. char name[];
  6. double weight;
  7. int calories;
  8. };
  9.  
  10. int main()
  11. {
  12. Candy *snack = new Candy[];
  13. snack[] = { "Mocha Munch1", 2.3, };
  14. snack[] = { "Mocha Munch2", 2.5, };
  15. snack[] = { "Mocha Munch3", 2.7, };
  16.  
  17. cout << snack[].name << "'s weight is " << snack[].weight <<
  18. ", and it includes " << snack[].calories << " calories.\n";
  19. cout << snack[].name << "'s weight is " << snack[].weight <<
  20. ", and it includes " << snack[].calories << " calories.\n";
  21. cout << snack[].name << "'s weight is " << snack[].weight <<
  22. ", and it includes " << snack[].calories << " calories.\n";
  23.  
  24. delete [] snack;
  25.  
  26. system("pause");
  27. return ;
  28. }

  1. #include<iostream>
  2. #include<array>
  3.  
  4. using namespace std;
  5. const int Times = ;
  6.  
  7. int main()
  8. {
  9. array<double, Times> grade;
  10. int i;
  11. double avg_grade=0.0;
  12.  
  13. cout << "Please enter your grade: " << endl;
  14.  
  15. for (i = ; i <= ; i++)
  16. {
  17. cout << endl << ("%d", i+) << " time: ";
  18. cin >> grade[i];
  19. avg_grade += grade[i];
  20. }
  21.  
  22. avg_grade = avg_grade / Times;
  23. cout << endl << "The grade of average is: " << avg_grade << endl;
  24.  
  25. system("pause");
  26. return ;
  27. } 

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> using namespace std; int main() { ; cout << "Please enter two n ...

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

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

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

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

  6. 《80x86汇编语言程序设计教程》第二章课后题答案

    2.5 习题 2.1 数据寄存器 1. 八个通用寄存器除了各自规定的专门用途外,它们均可以用于传送和暂存数据,可以保存算术逻辑运算中的各种操作数和运算结果. 2.1 AX和Al寄存器又称为累加器(ac ...

  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. iOS 网易彩票-4设置模块一

    概述 基本上,每一款APP都有相应的设置模块.怎么设置才能更灵活和通用呢,这也是大家一直思考的.下面说说在网易彩票中,设置模块的设置思想. 基本上有三种方案: static cell(呆板,完全没有动 ...

  2. Docker深入浅出1

    Docker是一个开源的应用容器引擎,基于GO语言并遵从apache2.0协议开源. Docker可以让开发者打包他们的应用以及依赖包到一个轻量级,可移植的容器中,然后发布到任何流行的Linux机器上 ...

  3. webapi swagger学习笔记

    版权声明:部分摘抄其他博主朋友的博文内容,旨在分享学习,如给您带来不便,请原谅.原文地址 http://www.cnblogs.com/yanweidie/p/5709113.html#_label3 ...

  4. Lower Power with CPF(二)

    CPF文件可以有两种组织方式:Flat CPF file or Hierarchical CPF file. 由于在大型的SoC设计中,一般都采用Hierarchical的形式,所以本文主要按这个方式 ...

  5. IO(基础知识)

        IO流类的构造方法决定是输入流还是输出流.输入流连接一个文件,它会将文件中的内容读到流里面,read方法是将流里面的内容     往外读.输出流连接一个文件,它的write方法,是将内存中的内 ...

  6. SNMP学习笔记之SNMP介绍,OID及MIB库

    1.1.    SNMP概览 SNMP的基本知识介绍简单网络管理协议(SNMP-Simple Network Management Protocol)是一个与网络设备交互的简单方法.该规范是由IETF ...

  7. Python3 Selenium自动化-select下拉框

    Python3 Selenium自动化-select下拉框 selenium介绍select下拉框相关的操作方法:

  8. 20145321《网络对抗》Exp2 后门原理与实践

    实验内容 (1)使用netcat获取主机操作Shell,cron启动 (2)使用socat获取主机操作Shell, 任务计划启动 (3)使用MSF meterpreter生成可执行文件,利用ncat或 ...

  9. 如何让VS2012编写的程序在XP下运行

    Win32主程序需要以下设置 第一步:在工程属性General设置 第二步:在C/C++ Code Generation 设置 第三步:SubSystem 和  Minimum Required Ve ...

  10. Hadoop错误日志

    1.错误日志:Directory /tmp/hadoop-root/dfs/name is in an inconsistent state: storage directory does not e ...