473,396 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need help with vecotrs and other thing please!

7
Hi, just new to this forum, and i was wondering if anyone could help me.

I've got a piece of work to do, i have done the majority of it, just the last, and the most important thing lol, that i am stuck with.

there are 4 classes, Room, Bedroom (type of room), ConferenceRoom (type of room) and Date(in a header file).

Expand|Select|Wrap|Line Numbers
  1. class Room{
  2.                 private:
  3.                     int roomNumber;
  4.                     double rate;
  5.                     string customer;
  6.                     Date booking;
  7.  
  8.                 public:
  9.                     Room (int, double);
  10.                     void bookRoom (string, Date);
  11.                     Date getBooking() {return booking;}
  12.                     double getRate();
  13.                     int getRoomNumber();
  14.                     string getDetails();
  15.  
  16.            };
  17.  
  18. class Bedroom{
  19.       friend class Room;
  20.  
  21.                 private:
  22.                     string facilities;
  23.  
  24.                 public:
  25.                     Bedroom (int, double, string);
  26.                     string getDetails;
  27.              };
  28.  
  29. class ConferenceRoom{
  30.       friend class Room;
  31.  
  32.                 private:
  33.                     int seatingCapacity;
  34.  
  35.                 public:
  36.                     ConferenceRoom (int, double, int);
  37.                     int getCapacity;
  38.                     string getDetails();
  39.                     };
Basically, i have got to make a program which:

takes info about a hotel and its rooms from a text file (DONE)

put that info into a vector name Rooms (Done, sort of)

i then need to be able to print info about the rooms using the getDetails member functions from the three room classes.

i need to be able to book a room by getting the user to input the date they require and there name.

need to be able to show all vacant rooms for a inputted date.

need to be able to show the hotels income for a certain date by adding up the price from what hotels are booked for a certain date,
Expand|Select|Wrap|Line Numbers
  1. vector <Room> Hotel;
Now the bit i am stuck on is getting info from the vector which is declared globally into the classes so that i can print relevant info.

Also, is there any way i can hold objects of type Bedroom and ConferenceRoom inside the vector for Rooms?

it seems a lot but once i grasp the vecotr situation i think it will be easier!

i cant find any good tutorials with vecotrs that are of type that is user defined!

Its just that i cant find any way of doing what i am supposed to do!!

Any help much appreciated!!

thanks

Shaun
Aug 12 '07 #1
6 1723
weaknessforcats
9,208 Expert Mod 8TB
You said ti yourself:
there are 4 classes, Room, Bedroom (type of room), ConferenceRoom (type of room) and
A Room is a base class
A Bedroom derives from Room
A ConferecneRoom derives from Room

You have a vector<Room>.

All of your functions have Room* or Room& arguments.

You create a Bedroom object and add it to the vector. It's Room isn't it??
Ditto for ConferenceRoom.

That's enough hints for now.
Aug 14 '07 #2
shaunb
7
hi, much appreciated for replying!

I was sort of going down that sort of path last night, but your comment has just reassured me! thank you!

But i am having trouble getting it to work now!

i have declared the vector:

Expand|Select|Wrap|Line Numbers
  1. vector <Room*> hotel;
then i read in my values to create a Bedroom object:

Expand|Select|Wrap|Line Numbers
  1. hoteldetails >> h_rNumber;
  2.         hoteldetails >> h_rate;
  3.         getline(hoteldetails, h_facilities);
  4.  
  5.         Bedroom *nwbed = new Bedroom(h_rNumber, h_rate, h_facilities);
  6.  
  7.         hotel.push_back(nwbed);
and then i get an error on line 58:

58: no matching function for call to `Room::Room()'
note: candidates are: Room::Room(const Room&)
note: Room::Room(int, double)

the code on line 58 is:

Expand|Select|Wrap|Line Numbers
  1. 57: Bedroom::Bedroom(int roomNumber, double rate, string facilities)
  2. 58: {
  3. 59:     roomNumber = 0;
  4. 60:     rate = 0.0;
  5. 62:     facilities = " ";
  6. 63: }
and i cant work out where i am going wrong, please help!!!

Thank you again!!

Shaun B
Aug 15 '07 #3
RRick
463 Expert 256MB
Bedroom is derived from Room. The Bedroom constructor also needs to set the Room's constructor values. Your Bedroom doesn't set any constructor for Room, so the compiler looks for the default constructor for Room. It couldn't find one, so it gave you an error message.

The Base class is set by the Derived class using the ':'. For example:
Expand|Select|Wrap|Line Numbers
  1. class Derived( int ival, double dval): Base( ival)
  2. {
  3.      blah blah blah
  4. }
  5.  
In this case, Derived is calling the Base( int) constructor. If one doesn't exist, the compiler will let you know.
Aug 15 '07 #4
shaunb
7
Hi, once again, many thanks for the replys, i have now got the program adding the objects to the vector, i ahve just tried printing it out and it is outputting the actual memory addresses, does anyone have any ideas?

Code:

Expand|Select|Wrap|Line Numbers
  1. Bedroom *nwbed = new Bedroom(h_rNumber, h_rate, h_facilities);
  2.  
  3.         hotel.push_back(nwbed);
  4.  
  5.         for (int p = 0; p < hotel.size(); p++)
  6.         {
  7.             cout << hotel[p] << endl;
  8.         }
Thanks!!!

Shaun B
Aug 15 '07 #5
RRick
463 Expert 256MB
This is printing out what you ask it to do. hotel[p] returns a pointer to Room and cout prints that.

To get cout to print out the values of Room, you'll have to dereference the pointer and have a method return something that cout can print. Usually this is a string. In fact, in java, there is a special virtual method called "toString" that does this.

You can define a toString method in Room and have it print out Room info, and then override it for the other rooms. You can also have the derived classes use Room's toString to make their own. The declaration and use looks like:
Expand|Select|Wrap|Line Numbers
  1. std::string  Room::toString( const std::string & indent="")
  2. .........
  3. cout << hotel[p]->toString( "    ") << endl;
  4.  
The indent variable is a "cool" feature that allows the caller to specify a shift for you info. This makes the output more readable. Inside the toString method, make sure indent is the first thing printed for each new line.
Aug 16 '07 #6
shaunb
7
hi, thanks for you help, im going to try that tonight!!

Another question though im afraid, really sorry!

Once i have put all the data into the vecotr (all the bedrooms and conference rooms)

is there any way that i will just be able to print out the Bedrooms from the vector?

And, also, is there any way i can say, just print out a Bedroom that has the room number, for example 200. can you search individual elements of the object in the vector like that?

Thanks

Shaun B
Aug 16 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If...
48
by: Chad Z. Hower aka Kudzu | last post by:
A few of you may recognize me from the recent posts I have made about Indy <http://www.indyproject.org/indy.html> Those of you coming to .net from the Delphi world know truly how unique and...
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: Y2J | last post by:
I am working through this book on C++ programming, the author is speaking of using linked lists. He gave and example which I found confusing to say the least. So I rewrote the example in a way that...
0
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
7
by: dragoncoder | last post by:
Hello experts, I have the following code me. =cat mystring.h #include<iostream> using namespace std; class mystring {
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.