产品类,图书类,氧化物类(C++)

1.产品类Product
题目描述
设计一个产品类Product,该类有产品名称、公司名称、产品型号、价格,出厂日期五个数据成员。其中出厂日期是Date类的对象。main函数的代码已经给出,请根据main函数代码和对应的输出给出Product类和Date类的代码。(需要提交main函数之外的其他代码部分)

main函数的代码如下:

int main(){

int year,month,day;

string name,company,type;

double price;

cin>>year>>month>>day;

Date date(year,month,day);

cin>>name>>company>>type>>price;

Product p(name,company,type,date,price);

p.printInfo();

return 0;

}

输入描述
输入产品的各种信息

输出描述
输出产品的各种信息

提示
输入:

2021 3 9

s90 volvo b5 32.6

输出:

s90 volvo b5 32.6

2021/3/9

2.员工类Employee
题目描述
设计一个员工类Employee,该类有姓名、部门、工号、工资,入职日期五个数据成员。其中入职日期是Date类的对象。main函数的代码已经给出,请根据main函数代码和对应的输出给出Employee类和Date类的代码。(需要提交main函数之外的其他代码部分)

main函数的代码如下:

int main(){

int year,month,day;

string name,department,id;

double salary;

cin>>year>>month>>day;

Date date(year,month,day);

cin>>name>>department>>id>>salary;

Employee e(name,department,id,date,salary);

e.printInfo();

return 0;

}

输入描述
输入员工的各种信息

输出描述
输出员工的各种信息

提示
输入:

2020 5 1

lucy it 1001 3500

输出:

lucy it 1001 3500

2020/5/1

3.氧化物类Oxide
题目描述
定义一个氧化物类Oxide,它包含四个私有数据成员,第一、三个数据成员(按惯例第三个成员必定是氧)都是元素类(Element)对象,第二、四个数据成员是这两个元素的个数。

元素类需要单独定义,包含私有数据成员英文元素符号以及必要的成员函数。

请为Oxide类定义有关成员函数,包括构造函数、打印分子式的函数。

为两个类添加你认为必要的其它成员函数。

在主函数中建立元素类的几个对象(如氢H、碳C、铁Fe、氧O等),再建立Oxide类的几个对象(如H2O水、CO一氧化碳、CO2二氧化碳、SO2二氧化硫、P2O5五氧化二磷、FeO氧化亚铁、Fe3O4四氧化三铁等等)并进行测试。

提示:当元素个数为1时,其分子式不显示个数,例如一氧化碳写作CO而不是C1O1。

mian函数已经写好,请根据main函数的内容完成相关类的定义。

int main(){

string symbol="H";

Element e1(symbol);

Element e2;

Oxide o1(e1,2,e2,1);

o1.printformula();

symbol="C";

Element e3(symbol);

Oxide o2(e3,1,e2,1);

o2.printformula();

symbol="S";

Element e4(symbol);

Oxide o3(e4,1,e2,2);

o3.printformula();

symbol="Fe";

Element e5(symbol);

Oxide o4(e5,3,e2,4);

o4.printformula();

symbol="P";

Element e6(symbol);

Oxide o5(e6,2,e2,5);

o5.printformula();

return 0;

}

输入描述
本题没有输入

输出描述
按照样例进行输出

样例输出
H2O
CO
SO2
Fe3O4
P2O5

//产品类

#include <iostream>
#include <cstring>
using  namespace std;

class Date
{
public:
    Date(int y,int m,int d) :year(y),month(m),day(d)
    {
    }
    
    int GetYear() const{return year;}
    int GetMonth() const{return month;}
    int GetDay() const{return day;}
private:
    int year,month,day;
};

class Product
{
public:
    Product(const string& n,const string& c,const string& t,
    const Date& d,const double p)
    : name(n),company(c),type(t),date(d),price(p)
    {
        
    }
    
    void printInfo()
    {
    cout << name << " " << company << " " << type << " " << price << endl;
    cout << date.GetYear() << "/" << date.GetMonth() << "/" << date.GetDay() << endl;
    }
    
    private:
        string name,company,type;
        Date date;
        double price;
};

int main(){

    int year,month,day;

    string name,company,type;

    double price;

    cin>>year>>month>>day;

    Date date(year,month,day);

    cin>>name>>company>>type>>price;

    Product p(name,company,type,date,price);

    p.printInfo();

    return 0;

}
//职工类

#include <iostream>
#include <cstring>
using  namespace std;

class Date
{
public:
    Date(int y,int m,int d) :year(y),month(m),day(d)
    {
    }
    
    int GetYear() const{return year;}
    int GetMonth() const{return month;}
    int GetDay() const{return day;}
private:
    int year,month,day;
};

class Employee
{
public:
    Employee(const string& n,const string& e,const string& i,
    const Date& d,const double s)
    : name(n),department(e),id(i),date(d),salary(s)
    {
        
    }
    
    void printInfo()
    {
    cout << name << " " << department << " " << id << " " << salary << endl;
    cout << date.GetYear() << "/" << date.GetMonth() << "/" << date.GetDay() << endl;
    }
    
    private:
        string name,department,id;
        Date date;
        double salary;
};

int main(){

    int year,month,day;

    string name,department,id;

    double salary;

    cin>>year>>month>>day;

    Date date(year,month,day);

    cin>>name>>department>>id>>salary;

    Employee e(name,department,id,date,salary);

    e.printInfo();

    return 0;

}