2016-04-05 6 views
-1

以下はMS C++ 2010 Express Editionを使用して、私のソースコードでは、エラーが

#include <iostream> 
#include <iomanip> 
#include <string> 

using namespace std; 

// declaration section 
class Boxoffice 
{ 
    private: 
    string title; 
    string releaseDate; 
    string rating; 
    int runningTime; 

    public: 
    Boxoffice(string =" ", string =" ", string =" ", int =1);  
    string getTitle(string); 
    string getDate(string); 
    string getRating(string); 
    int getTime(int); 
    void setBoxoffice(string, string, string, int); 
    void displayBoxoffice(void); 

}; 
//======================== 
Boxoffice::Boxoffice(string movieTitle, string date, string rate, int time) 
{ 
    title = movieTitle; 
    releaseDate = date; 
    rating = rate; 
    runningTime = time; 
} 


string Boxoffice::getTitle(string movieTitle) 
{ 
    title = movieTitle; 
    return title; 
} 

string Boxoffice::getDate(string date) 
{ 
    releaseDate = date; 
    return releaseDate; 
} 

string Boxoffice::getRating(string rate) 
{ 
    rating = rate; 
    return rating; 
} 

int Boxoffice::getTime(int time) 
{ 
    runningTime = time; 
    return runningTime; 
} 

void Boxoffice::setBoxoffice(string movieTitle, string date, string rate, int time) 
{ 
    title = movieTitle; 
    releaseDate = date; 
    rating = rate; 
    runningTime = time; 
} 

void Boxoffice::displayBoxoffice(void) 
{ 
    cout<<"Boxoffice title is: "<< title<<endl 
     <<"Boxoffice released date is: "<<releaseDate<<endl 
     <<"Boxoffice rating is: "<<rating<<endl 
     <<"Boxoffice running time is: "<<runningTime<<endl; 
} 


int main() 
{ 
    //ARRAY (hard code)========================================= 
    Boxoffice boxoffice[5]; 
    boxoffice[0].setBoxoffice("name_a","date_a","rating_a",100); 
    boxoffice[1].setBoxoffice("name_b","date_b","rating_b",100); 
    boxoffice[2].setBoxoffice("name_c","date_c","rating_c",100); 
    boxoffice[3].setBoxoffice("name_d","date_d","rating_d",100); 
    boxoffice[4].setBoxoffice("name_e","date_e","rating_e",100); 

    //===================================================== 
       string input; 
       cout<<"Enter date : "; //read input - release date 
       cin>>input; 
       for(int i =0; i<5; i++) //traverse 
       { 
        if(input == boxoffice[i].getDate()) //error here , to compare input and data stored in array 
        { 
         boxoffice[i].displayBoxoffice();//display movie that matches the release date entered. 
        } 
       else{ 
      cout<<"Invalid input."; 
       } 
     } 
     system("Pause"); 
    return 0; 

} 
+3

なぜ 'getDate'という名前の関数が***を設定しましたか? 'setDate'はどこですか? –

+0

'get ...'関数を、何かを返すgetterと、何も返しないgetterと、何も返さず何かをパラメータとして取るsetterに分割する必要があります。 – grisumbras

答えて

1

あなたのエラーの原因は、あなたということですコールの引数を指定してはいけない:

boxoffice[i].getDate() 

あなたはそれを呼び出すために、いくつかの文字列を追加する必要があります

boxoffice[i].getDate("date?") 

けど、... WH y getData関数へのパラメータを指定します。その名前からはdateのみを返すべきです。実際にはconstとして指定する必要があります。日付を設定する場所はすでにsetBoxofficeです。

string getDate(string);からconst string& getDate() const;に変更することをお勧めします。他のget-likeメソッドでも同じことをしてください。

+0

助けてくれてありがとう!私が作ったエラーを見つけました。代わりに 'getDate(文字列の日付)' 'getDate()' 私はgetterに何も設定すべきではないので、私のセッターに何かを設定すべきです 'void setBoxoffice(string、string、string、int ); ' – Andrew