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


#include<iostream>
#include<string> using namespace std; int main()
{
string first_name;
string last_name;
char grade;
int age; cout << "What is your first name? ";
getline(cin,first_name);
cout << endl << "What is your last name? ";
getline(cin,last_name);
cout << endl << "What letter grade do you deserve? ";
cin >> grade;
cout << endl << "What is your age? ";
cin >> age; cout << "Name: " << last_name << ", " << first_name << endl;
cout << "Grade: " << char(grade + ) << endl;
cout << "Age: " << age << endl;
cin.get();
cin.get();
return ;
}

#include <iostream>
#include<string> int main()
{
using namespace std; string name;
string dessert; cout << "Enter your name:\n";
getline(cin,name);
cout << "Enter your favorite dessert:\n";
getline(cin,dessert);
cout << "I have some delicious " << dessert;
cout << " for you, " << name << ".\n";
cin.get();
return ;
}

#include<iostream>
#include<cstring> using namespace std; int main()
{
char first_name[];
char last_name[];
char name[]; cout << "Enter your first name: ";
cin >> first_name;
cout << endl << "Enter your last name: ";
cin >> last_name; strcpy_s(name, last_name);
strcat_s(name, ",");
strcat_s(name, first_name);
cout << endl << "Here’s the information in a single string: " << name; //cout << endl << "Here’s the information in a single string: " << last_name << " , " << first_name; cin.get();
cin.get();
return ;
}

#include<iostream>
#include<string> using namespace std; int main()
{
string first_name;
string last_name;
string name; cout << "Enter your first name: ";
getline(cin,first_name);
cout << "Enter your last name: ";
getline(cin,last_name); name = last_name + "," + first_name;
cout << "Here's the information in a single string: " << name << endl;
cin.get();
//system("pause");
return ;
}

#include<iostream>
using namespace std; struct CandyBar
{
char bard[];
double weight;
int calories;
}; int main()
{
CandyBar snack =
{
"Mocha Munch",
2.3, }; cout << "The bard of this candy is: " << snack.bard << endl;
cout << "The weight of this candy is: " << snack.weight << endl;
cout << "The calories of this candy is: " << snack.calories << endl; cin.get();
return ;
}

#include<iostream>
using namespace std; struct Candy {
char name[];
double weight;
int calories;
}; int main() {
//Candy snack[3];
//snack[0] = { "Mocha Munch1", 2.3, 350 };
//snack[1] = { "Mocha Munch2", 2.5, 360 };
//snack[2] = { "Mocha Munch3", 2.7, 390 };
Candy snack[] = { { "Mocha Munch1", 2.3, } ,
{ "Mocha Munch2", 2.5, } ,
{ "Mocha Munch3", 2.7, } };
cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n";
cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n";
cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n"; system("pause");
return ;
}

#include<iostream>
using namespace std; struct Pizza
{
char name[];
double diameter;
double weight;
}; int main()
{
Pizza x;
cout << "Please enter the name of this pizza: ";
cin >> x.name;
cout << "Please enter the diameter of this pizza: ";
cin >> x.diameter;
cout << "Please enter the weight of this pizza: ";
cin >> x.weight; cout << "The name of this pizza is " << x.name << endl;
cout << "The diameter of this pizza is " << x.diameter << endl;
cout << "The weight of this pizza is " << x.weight << endl; system("pause");
return ;
}

#include<iostream>
using namespace std; struct Pizza {
char name[];
double diameter;
double weight;
}; int main() {
Pizza *pizza = new Pizza;
cout << "Please enter the name of this pizza: ";
cin >> pizza->name;
cout << "Please enter the diameter of this pizza: ";
cin >> pizza->diameter;
cout << "Please enter the weight of this pizza: ";
cin >> pizza->weight; cout << "The name of this pizza is " << pizza->name << endl;
cout << "The diameter of this pizza is " << pizza->diameter << endl;
cout << "The weight of this pizza is " << pizza->weight << endl; delete pizza; system("pause");
return ;
}

#include<iostream>
using namespace std; struct Candy {
char name[];
double weight;
int calories;
}; int main()
{
Candy *snack = new Candy[];
snack[] = { "Mocha Munch1", 2.3, };
snack[] = { "Mocha Munch2", 2.5, };
snack[] = { "Mocha Munch3", 2.7, }; cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n";
cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n";
cout << snack[].name << "'s weight is " << snack[].weight <<
", and it includes " << snack[].calories << " calories.\n"; delete [] snack; system("pause");
return ;
}

#include<iostream>
#include<array> using namespace std;
const int Times = ; int main()
{
array<double, Times> grade;
int i;
double avg_grade=0.0; cout << "Please enter your grade: " << endl; for (i = ; i <= ; i++)
{
cout << endl << ("%d", i+) << " time: ";
cin >> grade[i];
avg_grade += grade[i];
} avg_grade = avg_grade / Times;
cout << endl << "The grade of average is: " << avg_grade << endl; system("pause");
return ;
}
c++ primer plus 第四章 课后题答案的更多相关文章
- c++ primer plus 第七章 课后题答案
#include <iostream> using namespace std; double HAR_AVG(double, double); void TEST(bool); int ...
- c++ primer plus 第六章 课后题答案
#include <iostream> #include <cctype> using namespace std; int main() { char in_put; do ...
- c++ primer plus 第五章 课后题答案
#include <iostream> using namespace std; int main() { ; cout << "Please enter two n ...
- c++ primer plus 第三章 课后题答案
#include<iostream> using namespace std; int main() { ; int shen_gao; cout <<"Please ...
- c++ primer plus 第二章 课后题答案
#include<iostream> using namespace std; int main() { cout << "My name is Jiantong C ...
- 《80x86汇编语言程序设计教程》第二章课后题答案
2.5 习题 2.1 数据寄存器 1. 八个通用寄存器除了各自规定的专门用途外,它们均可以用于传送和暂存数据,可以保存算术逻辑运算中的各种操作数和运算结果. 2.1 AX和Al寄存器又称为累加器(ac ...
- python核心编程第5章课后题答案
5-8Geometry import math def sqcube(): s = float(raw_input('enter length of one side: ')) print 'the ...
- python核心编程第4章课后题答案(第二版75页)
4-1Python objects All Python objects have three attributes:type,ID,and value. All are readonly with ...
- python核心编程第3章课后题答案(第二版55页)
3-4Statements Ues ; 3-5Statements Use\(unless part of a comma-separated sequence in which case \ is ...
随机推荐
- JS参差不齐的数组
<html><head> <title>参差不齐的数组</title> <meta charset="utf-8"> & ...
- python 元组 序列上使用enumerate()函数
不能直接for n,x,y in enumerate(data)
- Windows批处理程序bat
@echo off 关闭回显,否则脚本中的命令都会输出,关闭后只显示结果. setlocal ENABLEDELAYEDEXPANSION 在for循环中变量扩展时需要用到 copy /Y ms ...
- C/C++之标准库和标准模板库
C++强大的功能来源于其丰富的类库及库函数资源.C++标准库的内容总共在50个标准头文件中定义.在C++开发中,要尽可能地利用标准库完 成.这样做的直接好处包括:(1)成本:已经作为标准提供,何苦再花 ...
- 又一国产855旗舰突然现身:支持5G
12月28日消息,中国联通官方微博放出了vivo NEX 5G版样机.如图所示,该机搭载骁龙855移动平台及X50 5G调制解调器. 早在8月30日,vivo就宣布完成了面向商用5G智能手机的软硬件开 ...
- MySQL备份与恢复-innobackupex
:上一片myloder搞崩溃,为什么百度的博文都是抄袭一模一样的,哎烦! 这一片文章我们来介绍物理备份工具xtracebackup! 首先是安装可以percona官网下载安装,下载rpm包直接yum安 ...
- Python入门之安装numpy和pandas
最近要对一系列数据做同比比较,需要用到numpy和pandas来计算,不过使用python安装numpy和pandas因为linux环境没有外网遇到了很多问题就记下来了. 首要条件,python版本必 ...
- Python入门之logging日志模块以及多进程日志
本篇文章主要对 python logging 的介绍加深理解.更主要是 讨论在多进程环境下如何使用logging 来输出日志, 如何安全地切分日志文件. 1. logging日志模块介绍 python ...
- leetcode 136 Single Number, 260 Single Number III
leetcode 136. Single Number Given an array of integers, every element appears twice except for one. ...
- 01: awk常用
1.1 awk基本使用 1.找出当前登录用户数量 [root@localhost ~]# w 14:09:07 up 48 min, 2 users, load average: 0.00, 0.01 ...