i wirote a program in which i declare a class called house info,i am having trouble of displaying no of house entries and things.i have declard an array name avalible[3],it gets input in function getdat() but not giving any output.
class houseInfo
{
string ownersName;
string adress;
int bedrooms;
longint price;
string avalible[3];//declaring array of 3 entires
public:
void getdata();
void display();
};
void houseInfo::getdata()
{
cout<<"Enter The Owner's Name"<<endl;
cin>>ownersName;
cout<<"Enter The Adress"<<endl;
cin>>adress;
cout<<"Enter The Bedrooms"<<endl;
cin>>bedrooms;
cout<<"Enter The Price"<<endl;
cin>>price;
cout<<"enter the house entires "<<endl;
for(int i=0;i<3; i++){
cout<<"enter the price"<<endl;//help me in this portion,first loop for house entries
cin>>avalible[i];
}
{
for(int j=0;j<3;j++)//this loop is for price.
cin>>avalible[j];
}
}
void houseInfo::display()
{
cout<<"The Name Of The Owner Is"<<' '<<ownersName<<endl;
cout<<"The Adress Of The Employer Is"<<' '<<adress<<endl;
cout<<"The Number Of Bedrooms Are"<<' '<<bedrooms<<endl;
cout<<"The Price Of The House Is"<<' '<<price<<endl;
cout<<"the house entries and price is"<<avalible[i][j];//i am confused here,i and j is giving error.what i should add instead of i and j here?
}
int main(){
houseInfo house;
cout<<"\t \t \t Wellcome To Information System"<<endl;
cout<<"\t \t \t -----------------------------"<<endl<<endl;
house.getdata();
house.display();
getch();
return 0;
}
{
for(int j=0;j<3;j++)//this loop is for price.
cin>>avalible[j];
}
Is simply overwritting the information from the previous for loop.
available[i][j] you are using a multidimensional array, but you have only declared this array as a single dimensional one: string available[i]
I'm somewhat confused as to what you're trying to do here. It looks like you have just one house, with 3 different prices. Is that what you intended? Also, if available[i] is a price, why not use a double to store the data?
Anyway, if you reply here with what you're trying to achieve as an end goal, I'll post up a guide to the correct solution after work (in 5-6 hours or so).
actully dear i am writng whole question for you.it would help you.
Declare avalible to be an array of 10 objects of type houseInfo.the driver program should read in about5-10 house entries into the avalible and print the data in the form of list sorted in the descending order.
You need to declare an array of the class of size 10.
houseInfo myhouse[10]; //Declares an array of 10 objects of type houseInfo
I would suggest a do...while loop for taking user input.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
do
{
//get all the info from the user here which is stuff such as:
cout<<"Enter The Owner's Name"<<endl;
cin>>ownersName;
cout<<"Enter The Adress"<<endl;
cin>>adress;
cout<<"Enter The Bedrooms"<<endl;
cin>>bedrooms;
cout<<"Enter The Price"<<endl;
cin>>price;
cout<<"enter the house entires "<<endl;
}while(i < 10);
You may want to include a break condition in there. Such as: