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;
}
Neden "getDate" adlı bir işlev *** bir şey ayarladı? SetDate nerede? –
"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