Hata

2016-04-05 42 views
-1

Aşağıda MS C++ 2010 Express Edition kullanarak kaynak koduHata

#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

Neden "getDate" adlı bir işlev *** bir şey ayarladı? SetDate nerede? –

+0

"get ..." işlevlerinizi, bir şey döndüren ve hiçbir şey olarak almayan alıcılara ve hiçbir şey döndürmeyen ve hiçbir şeyi parametre olarak almayan ayarlayıcılara bölmelisiniz. – grisumbras

cevap

1

Hatanın sebebinin size olmasıdır çağrısında argüman belirtmek Yüklü: bazı dize eklemek gerekir

boxoffice[i].getDate() 

adlandırmak:

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

ama ... wh y getData işlevine bir parametre belirtirsiniz, adından yalnızca tarih döndürmeli ve aslında const olarak belirtilmelidir. Tarihleri ​​belirlediğiniz setBoxoffice zaten var.

Bu nedenle, değiştirmenizi öneririz: string getDate(string); - const string& getDate() const; ve bunu diğer get-like yöntemleriyle aynı şekilde yapın.

+0

Yardım için teşekkürler! Yaptığım hatayı buldum. Yerine i 'getDate()' benim alıcılar herhangi bir ayar olmamalıdır ve benim setter 'boşluk setBoxoffice şey belirlesin (dize, dize, dize, int kullanmalıdır' 'getDate (dize tarihi)); ' – Andrew