0
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

//In this section I create the class HotelRoom

class HotelRoom
{
protected:
    HotelRoom(){}
    char room_Number[4];
    char* guestName;
    double rate;

public:

    HotelRoom(char Num[], double daily, char* name);
    HotelRoom(const HotelRoom &);
    ~HotelRoom();
    int Get_Capacity();
    int Get_Status();
    double Get_Rate();
    const char* Get_Number();
    const char* Get_Guest();
    int Change_Status(int Stat);
};

HotelRoom::HotelRoom(char Num[], double daily, char* name)
{
    strcpy_s(room_Number, 4, Num);
    guestName = new char[strlen(name) + 1];
    strcpy_s(guestName, 20, name);
    rate = daily;
}
HotelRoom::HotelRoom(const HotelRoom& room_r)
{
    strcpy_s(room_Number, room_r.room_Number);
    guestName = new char[strlen(room_r.guestName) + 1];
    strcpy_s(guestName, 20, room_r.guestName);
    rate = room_r.rate; 
}
HotelRoom::~HotelRoom()
{
    cout << endl << endl;
    cout << "Decunstructor Activated." << endl;
    delete[] guestName;
}

double HotelRoom::Get_Rate()
{
    return rate;
}
const char* HotelRoom::Get_Number()
{
    return room_Number;
}
const char* HotelRoom::Get_Guest()
{
    return guestName;
}
class DerivedGuestRoom : public HotelRoom
{
public:
    DerivedGuestRoom(int max, int stat, int nights);
    DerivedGuestRoom(const DerivedGuestRoom&);
    ~DerivedGuestRoom();

protected:
    int capacity;
    int status = 0; //0 if unoccupied
    int days;

};

DerivedGuestRoom::DerivedGuestRoom(int max, int stat, int nights) :  capacity(max), status(stat), days(nights)
{
    cout << "data members set";
}

DerivedGuestRoom::~DerivedGuestRoom()
{
    cout << "\ndecunstrucor";
}
class DerivedMeetingRoom : public HotelRoom
{
public:
    DerivedMeetingRoom(int seat, int stat);
    DerivedMeetingRoom(const DerivedMeetingRoom&);
    ~DerivedMeetingRoom();

protected:
    int seats;
    int status; //1 if booked for meeting 0 otherwise
};
DerivedMeetingRoom::DerivedMeetingRoom(int seat, int stat) : seats(seat), status(stat)
{
    cout << "data members set";
}

DerivedMeetingRoom::~DerivedMeetingRoom()
{
    cout << "\ndecunstrucor";
}
void Display_info(HotelRoom&);
HotelRoom* Create_Hotel();
int main()
{
    cout << setprecision(2)
        << setiosflags(ios::fixed)
        << setiosflags(ios::showpoint);

    HotelRoom* Hotel_Rooms[200];

    int count = 0;
    char response;

    cout << endl;
    cout << "Do you want to enter information about a hotel room?(Y/N): ";
    response = cin.get();
    cin.get();

    while (toupper(response) == 'Y' && count < 10)
    {
        Hotel_Rooms[count] = Create_Hotel();
        ++count;
        cout << endl;
        cout << "Do you want to enter information about a hotel room?(Y/N): ";
        response = cin.get();
        cin.get();
    }
    //Display the accounts created
    for (int i = 0; i < count; ++i)
        Display_info(*Hotel_Rooms[i]);

    for (int i = 0; i < count; ++i)
        delete Hotel_Rooms[i];

    cout << endl;
    system("PAUSE");
    return 0;
}
void Display_info(HotelRoom& room)
{
    cout << "\n\nGuest's Name: " << room.Get_Guest() << endl << endl;

    cout << "\nYour room number is " << room.Get_Number() << endl << endl;

    cout << "\nDaily rate is: " << room.Get_Rate() << endl << endl;
    cout << endl;
    cout << endl;
}
HotelRoom* Create_Hotel()
{
    //These are the variables that will be holding data then passed through objects

    char roomNumber[4];
    char guestName[20];

    double dailyRate = 89.00;

    HotelRoom* room_ptr;

    //This portion asks for user input

    cout << "\nEnter Guest information\n\n";

    cout << "Enter the room number: ";
    cin.getline(roomNumber, 4);

    cout << "Enter the guest's name: ";
    cin.getline(guestName, 20);
    cout << endl;

    cin.get(); //Clears input buffer

    room_ptr = new HotelRoom(roomNumber, dailyRate, guestName);

    return room_ptr;
}

I took out HotelRoom(); from parent class constructor and I removed from the child class constructors. I Now only have this error:

LearningOOP.exe has triggered a breakpoint.

Which I have never encountered this so not sure what it means.

LoyalNewb
  • 43
  • 1
  • 1
  • 7

2 Answers2

2

You haven't defined your default constructor for the HotelRoom class.

class HotelRoom
{
protected:
    char room_Number[4];
    char* guestName;
    double rate;

public:
    HotelRoom(); //< Not defined!
    HotelRoom(char Num[], double daily, char* name);
    HotelRoom(const HotelRoom &);
    ~HotelRoom();
    int Get_Capacity();
    int Get_Status();
    double Get_Rate();
    const char* Get_Number();
    const char* Get_Guest();
    int Change_Status(int Stat);
};

An "Unresolved external symbol" linker error means that you've declared and used a piece of code in your application, but you haven't defined it before using it.

EDIT (Based on your follow up comment below):

You can't take the constructor out because it's needed in other parts of your code. See this line in your code:

DerivedGuestRoom::DerivedGuestRoom(int max, int stat, int nights) : HotelRoom(), capacity(max), status(stat), days(nights)
//                                                                  ^---------^
//                                                                       |
//                                                            Using the default constructor.

DerivedMeetingRoom::DerivedMeetingRoom(int seat, int stat) : HotelRoom(), seats(seat), status(stat)
//                                                           ^---------^
//                                                                |
//                                                         And again here!

You either need to remove implement the default constructor for the HotelRoom class, or add parameters to your DerivedMeetingRoom and DerivedGuestRoom class constructors so that you can use the HotelRoom(char Num[], double daily, char* name) constructor.

Karl Nicoll
  • 16,090
  • 3
  • 51
  • 65
  • I was telling OldProgrammer that if I take out HotelRoom(); that I get these errors: – LoyalNewb Dec 01 '13 at 19:53
  • Error 1 error C2512: 'HotelRoom' : no appropriate default constructor available c:\users\student\documents\visual studio 2013\projects\learningoop\learningoop\classesandmore.cpp 77 1 LearningOOP Error 2 error C2512: 'HotelRoom' : no appropriate default constructor available c:\users\student\documents\visual studio 2013\projects\learningoop\learningoop\classesandmore.cpp 97 1 LearningOOP – LoyalNewb Dec 01 '13 at 19:54
  • See the edit to my post :) – Karl Nicoll Dec 01 '13 at 20:31
  • @SyntaxEyes - Where does it trigger a breakpoint? For future reference, you shouldn't edit your question for an unrelated error, you should create a new question or add a comment. People looking for the same linker error code will get confused by your unrelated question! – Karl Nicoll Dec 01 '13 at 20:51
  • I do appoligize, I didn't even think about that, I will keep in mind. To answer your question it breakpoints at the end of program, more specific, when I enter 'n' when it asks to enter new information. – LoyalNewb Dec 01 '13 at 21:00
  • @SyntaxEyes - Does it give an error code or an explanation for the break? Or does it just say "triggered a breakpoint"? – Karl Nicoll Dec 01 '13 at 21:16
  • it only says "triggered a breakpoint" – LoyalNewb Dec 01 '13 at 22:16
2

You declared a default constructor:

class HotelRoom
{
public:
  HotelRoom();
}

and there is no implementation for that default constructor method. You can change to:

class HotelRoom
{
public:
  HotelRoom() {}
}

or implement HotelRoom:HotelRoom { } in your cpp file.

wilx
  • 17,697
  • 6
  • 59
  • 114
OldProgrammer
  • 12,050
  • 4
  • 24
  • 45
  • I Noticed when I take out HotelRoom() I get these errors: – LoyalNewb Dec 01 '13 at 19:51
  • Error 1 error C2512: 'HotelRoom' : no appropriate default constructor available c:\users\student\documents\visual studio 2013\projects\learningoop\learningoop\classesandmore.cpp 77 1 LearningOOP Error 2 error C2512: 'HotelRoom' : no appropriate default constructor available c:\users\student\documents\visual studio 2013\projects\learningoop\learningoop\classesandmore.cpp 97 1 LearningOOP – LoyalNewb Dec 01 '13 at 19:51
  • @SyntaxEyes No-one is telling you to take out `HotelRoom()` they are telling you to *define* it. All you've done is *declare* it. Declaring it is like a promise to the compiler that it exists. Now you've got to follow through on that promise and define `HotelRoom::HotelRoom()`. You've already decalred and defined everything else in your program, so I'm not sure why this one is a stumbling block. – john Dec 01 '13 at 20:07
  • @OldProgrammer the reason I took HotelRoom() out was because I don't need it. The only reason I put it in was because it got rid of the error I shown you just now. – LoyalNewb Dec 01 '13 at 20:12
  • @SyntaxEyes You say you don't need it, but you use it here `DerivedMeetingRoom::DerivedMeetingRoom(int seat, int stat) : HotelRoom(), seats(seat), status(stat)`, (same also for `DerivedGuestRoom`). By putting `HotelRoom()` you are using the default constructor. Maybe you can fix that, and then you really won't need it. – john Dec 01 '13 at 20:17
  • So just add the default implementation or remove from the derived class. You can't have it both ways. – OldProgrammer Dec 01 '13 at 20:20
  • @OldProgrammer Right I have "DerivedMeetingRoom::DerivedMeetingRoom(int seat, int stat) : HotelRoom(), seats(seat), status(stat), (same also for DerivedGuestRoom). By putting HotelRoom()" because I have HotelRoom(char Num[], double daily, char* name); HotelRoom(const HotelRoom &); – LoyalNewb Dec 01 '13 at 20:24