Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 课堂设计任务的文字描述?_C++_Oop_Class - Fatal编程技术网

C++ 课堂设计任务的文字描述?

C++ 课堂设计任务的文字描述?,c++,oop,class,C++,Oop,Class,我有一个问题: 从出版、书籍和磁带课程开始。添加一个基类sales 它持有一个由三个浮动组成的数组,以便记录美元 过去三个月特定出版物的销售额。包括 函数的作用是:从用户和 putdata()函数以显示销售数字。修改书和 磁带类,因此它们是从出版物和销售中派生的。一 类book或tape的对象应输入销售数据及其 其他数据。编写main()程序来创建book对象和磁带 对象并练习其输入/输出功能 我不太理解它,我应该在哪个类中包含getdata()和putdata()函数!到目前为止,我编写了以下

我有一个问题:

从出版、书籍和磁带课程开始。添加一个基类sales 它持有一个由三个浮动组成的数组,以便记录美元 过去三个月特定出版物的销售额。包括 函数的作用是:从用户和 putdata()函数以显示销售数字。修改书和 磁带类,因此它们是从出版物和销售中派生的。一 类book或tape的对象应输入销售数据及其 其他数据。编写main()程序来创建book对象和磁带 对象并练习其输入/输出功能

我不太理解它,我应该在哪个类中包含getdata()和putdata()函数!到目前为止,我编写了以下代码:

   #include<iostream>
#include<string>
using namespace std;
class sales{
private:
    float dollar[3];
public:
    void getData(float f1,float f2, float f3){
        dollar[0]=f1;// sales of first month
        dollar[1]=f2;// sales of second month
        dollar[2]=f3;// sales of third month
    }
    void putData(){
        int count=0;
        while(count!=3){
        cout<<dollar[count]<<"\t$"<<endl;
        count++;
        }
    }
};


class publication:public sales{
private:
    string PubName;
    int PubYear;
public:
    void SetName(string s){
        PubName=s;
    }
    string GetName(){
        return PubName;
    }
        void SetYear(int y){
        PubYear=y;
    }
    int GetYear(){
        return PubYear;
    }
};

class book:public publication{
private:
    string Author;
public:
    void SetAuthor(string a){
        Author=a;
    }
    string GetAuthor(){
        return Author;
    }


};

class tape:public publication{
private:
    string singer;
public:
    void SetSinger(string s){
        singer=s;
    }
    string GetSinger(){
        return singer;
    }


};



int main() {
    tape Tobj;
    book Bobj;

// input/output capabilities of tape object.
    Tobj.getData(33,55,88);
    Tobj.SetName("General music tape");
    Tobj.SetSinger("David");
    Tobj.SetYear(2011);
    cout<<Tobj.GetName()<<" for "<<Tobj.GetSinger()<<"\nattained the following sales for the last three months:"<<endl;
    Tobj.putData();
    cout<<"in "<<Tobj.GetYear()<<endl<<endl<<endl;

// input/output capabilities of book object.    
    Bobj.getData(65.6,585,808.2);
    Bobj.SetName("Art of math");
    Bobj.SetAuthor("John");
    Bobj.SetYear(2009);
    cout<<Bobj.GetName()<<" for "<<Bobj.GetAuthor()<<"\nattained the following sales for the last three months:"<<endl;
    Bobj.putData();
    cout<<"in "<<Bobj.GetYear()<<endl<<endl<<endl;
    system("pause");

return 0;
}
#包括
#包括
使用名称空间std;
班级销售{
私人:
浮动美元[3];
公众:
void getData(浮点f1、浮点f2、浮点f3){
美元[0]=f1;//第一个月的销售额
美元[1]=f2;//第二个月的销售额
美元[2]=f3;//第三个月的销售额
}
void putData(){
整数计数=0;
while(计数!=3){
cout“包括一个getdata()函数以从用户处获取三个销售金额,以及一个putdata()函数以显示销售数字。”


从它的措辞来看,它向我建议getData()和putData()应该是“用户”类的一部分。但是,由于没有“用户”类,在我看来,你把它放在了正确的位置。

你真的做了一个文本截图,而不是在这里键入你的问题?这一定是懒屁股徽章的竞争者!作为getData()是一个函数吗?它可能不应该包含在任何类中?@Stals:我不认为这个术语在这里指的是非方法。main()被称为程序,而不是函数。根据问题描述,在类销售中的位置似乎是合理的(尽管出版物似乎不存在)。@KerrekSB放松点。向下投票并继续:)