plz help me,its urgent..i have to summit my project tomoorw

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.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class houseInfo
{
	string ownersName;
	string adress;
	int bedrooms;
	long int 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;
}



first create a variable to store that value. then a sign that value to the array.

1
2
3
4
cin >> value;

array[i] = value;
plz do this for me,i am very confused..i will be very thnkful to you.which loop i assigned to that value?first loop or second loop
A few spelling errors:

*address
*entries
*available

Onto the code:

The second for loops
1
2
3
4
5
	{

		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:
1
2
3
4
5
6
7
 
cout << "Do you wish to continue Y/N?"; 
cin >> choice; 
if(choice == 'y' || choice == 'Y')
{
break;
}


Nowhere in this code do you want to be using a multidimensional array.
1
2
array[10][10]; //This is multidimensional. Don't use it in this project. You need only a single array.
houseInfo myhouse[10]; //Like that.  


To output the data, just cycle through your array:
1
2
3
4
5
for(i = 0; i < 10; ++i)
{
    cout << "Ownername: " << myhouse[i].ownername; 
    etc...
}

Hope that helps.
Last edited on
Topic archived. No new replies allowed.