#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 第四章 课后题答案的更多相关文章

  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. BCB 按钮添加背景图

    使用控件:TBitBtn 位于 Additional分类 属性:GlyPh

  2. excel 批量在一列数据添加单引号以及逗号

    在A列后插入一列B1输入="'"&a1&"'," 然后向下填充 就ok 了 向下填充:选中上方连续单元格,鼠标放在选中区域右下角处(会显示“十” ...

  3. OAuth 白话简明教程 3.客户端模式(Client Credentials)

    转自:http://www.cftea.com/c/2016/11/6704.asp OAuth 白话简明教程 1.简述 OAuth 白话简明教程 2.授权码模式(Authorization Code ...

  4. Oracle 启动的时候需要的服务

  5. quartz开源作业调度框架的配置

    quartz开源作业调度框架的job服务实现,Quartz是一个完全由java编写的开源作业调度框架,使用时候需要创建一个实现org.quartz.Job接口的java类,Job接口包含唯一的方法: ...

  6. Javascript 判断对象是否相等

    在Javascript中相等运算包括"==","==="全等,两者不同之处,不必多数,本篇文章我们将来讲述如何判断两个对象是否相等? 你可能会认为,如果两个对象 ...

  7. 20145328《网络对抗技术》Final

    系内选拔赛write-up 1 信息隐藏 第一题图片藏东西,后缀名改txt,没有发现,改rar,发现压缩包内存在key.txt,解压提示存在密码,尝试使用修复,得到key.txt,打开获取flag,S ...

  8. Python3基础 list 查看filter()返回的对象

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. 又一个改写MBR的病毒(TDSS TDL4)

    此毒为TDSS TDL4 的又一个变种.RIS2011 目前尚未收录此毒.此毒的主要行为是改写MBR,并在硬盘尾部的190个扇区内写入病毒代码.病毒的上述动作可穿透还原类软件对系统的保护.我在Acro ...

  10. 常见几种校验方法(CS和校验、CRC16、CRC32、BCC异或校验)

    总结一些通讯协议中常用到的几种校验方法: 1.CS和校验(如:标准188协议校验方式) /// <summary> /// CS和校验 /// </summary> /// & ...