第一范文网 - 专业文章范例文档资料分享平台

cprimerplus第六版课后编程练习答案

来源:用户分享 时间:2025/8/5 11:11:34 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

//ex4.8pizzapie披萨饼使用new创建动态结构

#include

#include

constintSize=20;

structpizza//声明结构

{

charcompany[Size];

doublediameter;

doubleweight;

};

intmain()

{

usingnamespacestd;

pizza*pie=newpizza;//使用new创建动态结构

cout<<\

cin>>pie->diameter;

cin.get();//读取下一个字符

cout<<\

cin.get(pie->company,Size);

cout<<\

cin>>pie->weight;

cout<<\

cout<<\

cout<<\

deletepie;//delete释放内存

return0;

}

//ex.4.9使用new动态分配数组—方法1

#include

#include

usingnamespacestd;

structCandyBar

{

stringbrand;

doubleweight;

intcalory;

};

intmain()

{

CandyBar*snack=newCandyBar[3];

snack[0].brand=\单个初始化由new动态分配的内存

snack[0].weight=1.1;

snack[0].calory=200;

snack[1].brand=\

snack[1].weight=2.2;

snack[1].calory=400;

snack[2].brand=\

snack[2].weight=4.4;

snack[2].calory=500;

for(inti=0;i<3;i++)

{

cout<<\

cout<<\

cout<<\

}

delete[]snack;

return0;

}

数组—方法1

#include

intmain()

{

usingnamespacestd;

constintSize=3;

搜索更多关于: cprimerplus第六版课后编程练习答案 的文档
cprimerplus第六版课后编程练习答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c88oza90hm17e16g2f5026bod04q32p00ozi_8.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top