资讯动态

面向对象程序设计-类与对象1-衣服Clothing类定义

发布时间:2026/10/3 7:36:26 来源:尧图企业网站定制
作者 xyzyl单位 惠州学院按题目的输入输出样例定义一个Clothing类。包括四个私有数据成员string brand;string material;double price;string size;五个公有成员函数setBrand(), setMaterial(), setPrice(), setSize()和showInfo()裁判测试程序样例在这里给出函数被调用进行测试的例子。例如 #include iostream #include string using namespace std; /* 请在这里填写答案 */ int main() { Clothing cloth;// 创建Clothing对象 string s1,s2,s3; double d; cins1s2ds3; // 使用set方法设置品牌、材质、价格和尺寸 cloth.setBrand(s1); cloth.setMaterial(s2); cloth.setPrice(d); cloth.setSize(s3); cloth.showInfo();//调用showInfo()函数显示衣服信息 }输入样例在这里给出一组输入。例如李宁 纯棉 199.99 XXL输出样例在这里给出相应的输出。例如品牌: 李宁 材质: 纯棉 价格: RMB 199.99 尺寸: XXL参考示例class Clothing{ private: string brand; string material; double price; string size; public: void setBrand(string b){ brandb; } void setMaterial(string m){ materialm; } void setPrice(double p){ pricep; } void setSize(string s){ sizes; } void showInfo(){ cout品牌: brandendl; cout材质: materialendl; cout价格: RMB priceendl; cout尺寸: sizeendl; } };

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑