64,654
社区成员
发帖
与我相关
我的任务
分享
#ifndef MATERIAL
#define MATERIAL
#include <iostream>
#include <string>
using namespace std;
class Material
{
private:
char *name_m;
string type_m;
int amount_m;
int date_m;
float price_m;
public:
Material(){}; // default constructor
~Material(){}; // noisy destructor
virtual void registermaterials_m(char *n, string t, int a, int d, float p); //登记新商品,此处是函数头
void delete_m();
char *getname_m(); //读取商品名
string gettype_m();
int getamount_m(); //读取商品数量
int getdate_m();
float getprice_m(); //读取商品单价
virtual void outputdetails_m();
};
#endif
#include "Material.h"
void Material::registermaterials_m(char *n, string t, int a, int d, float p)
{
this->name_m = n;
this->type_m = t;
this->amount_m = a;
this->date_m = d;
this->price_m = p;
//this->total_price_m = tp;
}
void Material::outputdetails_m()
{
cout << "Material " << name_m << " Type " << type_m << " Amount " << amount_m << " Date " << date_m << " Price " << price_m << endl;
cout << "total value " << amount_m*price_m << endl;
};
char *Material::getname_m()
{
return this->name_m;
}
string Material::gettype_m()
{
return this->type_m;
}
int Material::getamount_m()
{
return this->amount_m;
}
int Material::getdate_m()
{
return this->date_m;
}
float Material::getprice_m()
{
return this->price_m;
}
#include "Material.h"
class Copper :public Material
{
public:
Copper();
Copper(char *name_m, string type_m,int amount_m, int date_m, float price_m);
virtual void registermaterials_m(char *n, string t, int a, int d, float p);
//void FeedAnimal(Animal *animal, string food, int quantity);
virtual void outputdetails_m();
};
#include "Copper.h"
Copper::Copper() :Material() {};
Copper::Copper(char *n, string t, int a, int d, float p) :Material(*n, t, a, d, p) {}
void Copper::outputdetails_m()
{
Material::outputdetails_m();
}
#include "Material.h"
#include "Copper.h"
//#include "Steel.h"
int main(int argc, char* argv[])
{
Copper z;
z.registermaterials_m("c102", "Copper", 30, 20150531, 1.5);
z.outputdetails_m();
return 0;
}
void Material::registermaterials_m(char *n, string t, int a, int d, float p):Material()
{
this->name_m = n;
this->type_m = t;
this->amount_m = a;
this->date_m = d;
this->price_m = p;
//this->total_price_m = tp;
}