当前位置: 首页 > article >正文

《C++ primer plus》第六版课后编程题-第04章

第四章

1

#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;


struct Person {
	string first_name;
	string last_name;
	char deserve;
	unsigned short age;
};

void main() {
	cout << "What is your first name?" << endl;
	struct Person p;
	getline(cin,p.first_name);
	cout << "What is your last name?" << endl;
	getline(cin, p.last_name);
	cout << "What letter grade do you deserve?" << endl;
	cin >> p.deserve;
	cout << "What is your age?" << endl;
	cin >> p.age;
	cout << "Name:" << p.last_name << ", " << p.first_name << endl;
	cout << "Grade:" << ++p.deserve << endl << "age:" << p.age;
}

2

#include <iostream>

#include <string>
using namespace std;


void main() {
	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";

}

3

#include <iostream>
#include <cstring>
#include <string>
using namespace std;
const int ArSize = 20;
const char dot = ',';

void main() {
	cout << "Enter your first name:";
	char first_name[ArSize];
	cin.getline(first_name, ArSize);
	cout << "Enter your last name:";
	char last_name[ArSize];
	cin.getline(last_name, ArSize);
	cout << "Here's the information in a single string: ";
	char full_name[2 * ArSize];
	strcpy_s(full_name, last_name);
	strcat_s(full_name,",");
	strcat_s(full_name, first_name);
	cout << full_name << endl;
}

4

#include <iostream>
#include <string>

using namespace std;

void main() {
	cout << "Enter your first name:";
	string first_name;
	string last_name;
	cin >> first_name;
	cout << "Enter your last name:";
	cin >> last_name;
	cout << "Here's the information in a single string:";
	string full_name = last_name + ',' + first_name;
	cout << " "<<full_name << endl;
}

5

#include <iostream>
#include <string>

using namespace std;

struct CandyBar {
	string band;
	double weight;
	int calorie;

};


void main() {
	CandyBar snack = { "Mocha Munch",2.3,350 };
	cout << snack.band << endl << snack.weight << endl << snack.calorie << endl;
}


6

#include <iostream>
#include <string>

using namespace std;

struct CandyBar {
	string band;
	double weight;
	int calorie;

};


void main() {
	CandyBar snack[3] = { {"Mocha Munch",2.3,350},
							{"Mocha Munch",2.3,350},
							{"Mocha Munch",2.3,350} };
	cout << snack[1].band << endl << snack[0].weight << endl << snack[2].calorie << endl;
}

7

#include <iostream>
#include <string>

using namespace std;

struct piza {
	string company;
	double diameter;
	double weight;
};

void main() {
	cout << "输入公司名" << endl;
	piza p;
	cin >> p.company;
	cout << "这是" << p.company << "公司的披萨" << endl;
}


8

#include <iostream>
#include <string>

using namespace std;

struct piza {
	string company;
	double diameter;
	double weight;
};

void main() {
	cout << "输入公司名" << endl;
	struct piza* p = new piza;
	cin >> p->company;
	cout << "这是" << p->company << "公司的披萨" << endl;
}

9

#include <iostream>
#include <string>

using namespace std;

struct CandyBar {
	string band;
	double weight;
	int calorie;

};


void main() {
	CandyBar* snack = new CandyBar[3];
	for (int i = 0; i < 3; i++) {
		snack[i] = { "Mocha Munch", 2.3, 350 };
	}

	cout << snack[1].band << endl << snack[0].weight << endl << snack[2].calorie << endl;
}

10

#include <iostream>
#include <array>

using namespace std;


void main() {
	array<double,3> run;
	cin >> run[0];
	cin >> run[1];
	cin >> run[2];
	cout << (run[0] + run[1] + run[2]) / 3 << endl;
}

http://www.kler.cn/a/513965.html

相关文章:

  • Linux Bash 中使用重定向运算符的 5 种方法
  • 数据库索引(1)
  • sql实战解析-sum()over(partition by xx order by xx)
  • Linux系统的第一个进程是什么?
  • 【Java数据结构】排序
  • springboot基于安卓的智启教育服务平台app
  • 【王树森搜素引擎技术】概要03:搜索引擎的评价指标
  • 【ESP32】ESP32连接JY61P并通过WIFI发送给电脑
  • 软件测试 —— Postman(全局变量和环境变量,请求前置脚本,关联)
  • android studio 工具.gradle目录修改
  • 【Go语言圣经】第三节:基础数据类型
  • No. 34 笔记 | Python知识架构与数据类型相关内容 | 实操
  • postgresql清理wal日志
  • k8s的CICD实施项目
  • 基于微信小程序的民宿预订管理系统
  • map和set的使用(一)详解
  • K8s UI工具 Kuboard 安装
  • Mysql视图(学习自用)
  • 记一次 .NET某数字化协同管理系统 内存暴涨分析
  • Day 14 卡玛笔记
  • Java设计模式 十一 外观模式 (Facade Pattern)
  • django使用踩坑经历
  • springboot基于前后端分离的摄影知识网站
  • 新书速览|算法竞赛入门笔记
  • 吴恩达深度学习——建立逻辑回归分类器识别猫
  • html简单项目案例