use of classes

I am generating a hotel program and iam doing it in steps.....very new to c++
this is what i have so far;
my problem is when i call the function Get_Rate it giving errors. Love if any one could help

# include <iostream>
# include <iomanip>
using namespace std;

class HotelRoom
{
private:
int rm_num;
int rm_cap;
int rm_status;
double drate;

public:
HotelRoom ();
void SetRm_Number(int);
void SetRm_Capacity(int);
void SetRm_Status(int);
void SetRm_Rate(double);

int Get_Number(int);
int Get_Capacity(int);
int Get_Status(int);
double Get_Rate(double);
};

void HotelRoom::SetRm_Number(int num)
{
num = rm_num;
}

void HotelRoom::SetRm_Capacity(int cap)
{
cap = rm_cap;
cap == 0;
cout<< cap;
}

void HotelRoom::SetRm_Status(int status)
{
status = rm_status;
}

void HotelRoom::SetRm_Rate(double rate)
{
rate = drate;
}

int HotelRoom::Get_Number(int _rmnumber)
{
return _rmnumber;
}

int HotelRoom::Get_Capacity(int _rmcapacity)
{
return _rmcapacity;
}

int HotelRoom::Get_Status(int _rmstatus)
{
return _rmstatus;
}

double HotelRoom::Get_Rate(double _rrate)
{
_rrate = 12;
return _rrate;
}



main ()

{
HotelRoom hotel;
hotel.Get_Rate(13);

cout<< Get_Rate()<< endl<< endl;

system ("pause");
return EXIT_SUCCESS;
Get_rate() function

can not call this way

should call or through pointer or object

as follows

HotelRoom *p;

p->Get_Rate(3.4);

or

HotelRoom n;

n.Get_Rate(3.4);
Last edited on
when I do hotel.Get_Rate(12) it gives a linker error
this also gives a linker error
HotelRoom *p;

p->Get_Rate(3.4);

You haven't implemented the constructor. Put this into your code:
1
2
3
4
HotelRoom::HotelRoom()
{
 
}

you have a constructor declaration
but does not define
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
68
69
70
71
72
73
74
75
76
77
78
79
80

class HotelRoom
{
private:
int rm_num;
int rm_cap;
int rm_status;
double drate;

public:
//HotelRoom ();  // not defination
void SetRm_Number(int);
void SetRm_Capacity(int);
void SetRm_Status(int);
void SetRm_Rate(double);

int Get_Number(int);
int Get_Capacity(int);
int Get_Status(int);
double Get_Rate(double);
};

void HotelRoom::SetRm_Number(int num)
{
rm_num = num; 
}

void HotelRoom::SetRm_Capacity(int cap)
{
rm_cap = cap; 
cap == 0;
cout << cap;
}

void HotelRoom::SetRm_Status(int status)
{
	rm_status = status; 
}

void HotelRoom::SetRm_Rate(double rate)
{
	drate = rate;
}

int HotelRoom::Get_Number(int _rmnumber)
{
	return _rmnumber;
}

int HotelRoom::Get_Capacity(int _rmcapacity)
{
	return _rmcapacity;
}

int HotelRoom::Get_Status(int _rmstatus)
{
	return _rmstatus;
}

double HotelRoom::Get_Rate(double _rrate)
{
	return _rrate;
}



int main ()

{
HotelRoom hotel;
hotel.Get_Rate(13);



//system ("pause");
//return EXIT_SUCCESS;

return 0;

}
thanks firix and null.....Is it possible for you to explain the use of constructor and how they are used.

I am seeing it being proposed but i guess i had it wrong in my program.
If you want to learn C++.see all...

http://www.cplusplus.com/doc/tutorial/
Topic archived. No new replies allowed.