【C++ Primer Plus习题】4.7

问题:

解答:

cpp 复制代码
#include <iostream>
#include <string>
using namespace std;

typedef struct _Pizza
{
	string companyName;
	float diameter;
	float wieght;
}Pizza;

int main()
{
	Pizza p;
	cout << "请输入披萨的公司名: ";
	getline(cin, p.companyName);
	cout << "请输入披萨的直径: ";
	cin >> p.diameter;
	cout << "请输入披萨的重量: ";
	cin >> p.wieght;
	cout << "披萨公司名:" << p.companyName << endl;
	cout << "披萨直径:" << p.diameter << endl;
	cout << "披萨重量:" << p.wieght << endl;

	return 0;
}

运行结果:

考查点:

  • 结构体的访问

2024年8月24日20:24:59

相关推荐
不想写代码的星星1 小时前
std::function 详解:用法、原理与现代 C++ 最佳实践
c++
樱木Plus2 天前
深拷贝(Deep Copy)和浅拷贝(Shallow Copy)
c++
blasit4 天前
笔记:Qt C++建立子线程做一个socket TCP常连接通信
c++·qt·tcp/ip
肆忆_5 天前
# 用 5 个问题学懂 C++ 虚函数(入门级)
c++
不想写代码的星星5 天前
虚函数表:C++ 多态背后的那个男人
c++
端平入洛7 天前
delete又未完全delete
c++
端平入洛8 天前
auto有时不auto
c++
郑州光合科技余经理9 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1239 天前
matlab画图工具
开发语言·matlab
西岸行者9 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习