帮我编写一段产品管理模块设计的计算机代码
#include<iostream>
#include<string>
using namespace std;
class Product { //定义产品类
private:
int id; //产品id
string name; //产品名称
string specification; //规格参数
double price; //价格
public:
Product(int id, string name, string specification, double price) {
this->id = id;
this->name = name;
this->specification = specification;
this->price = price;
}
void setId(int id) {this->id = id;} //设置id的函数;
void setName(string name) {this->name=name;} //设置名字的函数;
void setSpecification(string specification) {this->specification=specification;} //设置规格参数的函数;
void setPrice(double price) {this->price=price;} //设置价格的函数;
int getId() const{return this->id;} //得到id的函数;
string getName() const{return this->name;} //得到名字的函数; double getPrice() const{return this->price;} //得到价格的函数; }; int main() { Product p1(1001,"电子产品","尺寸大小",1000.0); cout<<"ID:"<<p1.getId()<<endl <<"Name:"<<p1.getName()<<endl <<"Specification:"<<p1.getSpecification()<<endl <<"Price:"<<p1.getPrice(); }
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!