2011-11-30 82 views
0

我有這樣的疑問:類描述設計任務?

開始與出版,書和磁帶類。添加一個基類銷售 ,其中包含三個花車陣列,以便它可以記錄過去三個月內某個特定出版物的銷售額 。包括一個 getdata()函數以獲取用戶的三個銷售額和一個 putdata()函數以顯示銷售數字。修改這本書和 磁帶類,以便它們來自發布和銷售。課本或磁帶的對象應該輸入銷售數據以及其他數據。 其他數據。編寫一個main()程序來創建一個書對象和一個磁帶對象,並鍛鍊它們的輸入/輸出能力。

我不明白它非常好,在這種類應該包括我的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; 
} 

是我所做的真實! 「

+4

你誠實地做了一個文本**的截圖,而不是在這裏鍵入*你的問題?這必須是Lazy Ass徽章的競爭者! –

+0

as getdata()是一個**函數**可能它不應該包含在任何類中? – Stals

+0

@Stals:我不認爲這個詞在這裏用來表示非方法。 main()被稱爲程序,而不是函數。考慮到問題的描述,在課堂銷售中的安排似乎是合理的(雖然出版物似乎沒有出現)。 – ccoakley

回答

1

」包含一個getdata()函數以從用戶獲得三個銷售額並使用putdata()函數顯示銷售額。「

隨着它的措辭,它向我建議getData()和putData()應該是「User」類的一部分。但由於沒有「用戶」類,所以在我看來,你把它放在正確的地方。