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 ...
随机推荐
- Java接口多线程并发测试 (二)
原文地址http://www.cnblogs.com/yezhenhan/archive/2012/01/09/2317636.html 这是一篇很不错的文章,感谢原博主的分享! JAVA多线程实现和 ...
- iOS开发--沙盒
IOS中的沙盒机制(SandBox)是一种安全体系,它规定了应用程序只能在为该应用创建的文件夹内读取文件,不可以访问其他地方的内容.所有的非代码文件都保存在这个地方,比如图片.声音.属性列表和文本文件 ...
- 案例:使用scan IP无法连接数据库
环境:Oracle RAC(11.2.0.3) 现象:通过scanIP连接数据库报错ORA-12514: ORA-12514: TNS:listener does not currently know ...
- Java事件监听的四种实现方式
1.事件对象: 一般继承自java.util.EventObject对象,由开发者自行定义. 2.事件源: 就是触发事件的源头,不同的事件源会触发不同的事件类型. 3.事件监听器: 事件监听器负责监听 ...
- 性能分析之– JAVA Thread Dump 分析
最近在做性能测试,需要对线程堆栈进行分析,在网上收集了一些资料,学习完后,将相关知识整理在一起,输出文章如下. 一.Thread Dump介绍 1.1什么是Thread Dump? Thread Du ...
- Python: 没有switch-case语句
初学Python语言,竟然很久才发现Python没有switch-case语句 官方的解释说,“用if... elif... elif... else序列很容易来实现 switch / case 语句 ...
- linux常用命令:ss 命令
ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.但ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信 ...
- Linux服务器---ssh登录
Ssh登录 Ssh是建立在应用层和传输层的安全协议,专门为远程登录回话和其他网络服务提供安全性.利用ssh可以有效的防止远程管理中的信息泄露问题,同时ssh传输的数据是经过压缩的,可以加快传输 ...
- linux服务器---squid缓存
Squid缓存 代理服务器会在本地硬盘设置缓存,这样可以提高网络效率 1修改squid配置文件“/etc/squid/squid.conf”,参数“cache_dir_ufs”就是设置缓存目录的 [r ...
- fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument
fastDFS errcode:9 path:Bad file descriptor errcode:22 path:Invalid argument <error>status:4 er ...