5 Replies - 498 Views - Last Post: 08 May 2010 - 08:00 PM Rate Topic: -----

#1 jeepguy1988  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 11-September 09

LNK errors galore

Posted 08 May 2010 - 07:24 PM

Hi all, here is my code:
#include <iostream>
#include <fstream>
#include "room.h"

using namespace std;

void room::setRoomType(int rType)
{
	room::rType = rType;
}

void room::displayRoomInfo()
{
   cout << "The room: " << rType << endl;
   cout << endl;
} 

#include <iostream>
#include <iomanip>

class room 
{
	public:
		int rType;
		static int sNon[30];
		static int sSmoking[30];
		static int dNon[30];
		static int dSmoking[30];
		static int suite[30];
		void setRoomType(int rType);
		void fillRoomArray();
		void displayRoomInfo();  
};


#include <iostream>
#include <iomanip>
#include <fstream>
#include "room.h"
#include "client.h"
#include "reservation.h"


using namespace std;

void reservation::setReservation()
{
	int menuHolder;
	int roomType;
	int day;
	bool menu = true;
	int holder;
	
	

	
	while (menu == true)
	{
		switch(roomType)
		{
		case 1:
			cout << "What day would you like to book the room for?" << endl;
			cin >> day;
			room::sNon[day] = holder;
			if ( holder = 0)
			{
				cout << "The room requested is available, would you like to book?" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder == 1)
				{
				room::sNon[day] = 1;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not available" << endl;
				break;
			}
		case 2:
			cout << "What day would you like to book the room for?" << endl;
			cin >> day;
			room::sSmoking[day] =  holder;
			if (holder = 0)
			{
				cout << "The room requested is available, would you like to book?" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder = 1)
				{
					room::sSmoking[day] = 1;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not available" << endl;
				break;
			}
		case 3:
			cout << "What day would you like to book the room for?" << endl;
			cin >> day;
			room::dNon[day] = holder;
			if (holder = 0)
			{
				cout << "The room requested is available, would you like to book?" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder = 1)
				{
				room::dNon[day] = 1;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not available" << endl;
				break;
			}
		case 4:
			cout << "What day would you like to book the room for?" << endl;
			cin >> day;
			room::dSmoking[day] = holder;
			if (holder = 0)
			{
				cout << "The room requested is available, would you like to book?" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder = 1)
				{
				room::dSmoking[day] = 1;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not available" << endl;
				break;
			}
		case 5:
			cout << "What day would you like to book the room for?" << endl;
			cin >> day;
			room::suite[day] = holder;
			if (holder = 0)
			{
				cout << "The room requested is available, would you like to book?" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder = 1)
				{
				room::suite[day] = 1;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not available" << endl;
				break;
			}
		}
	cout << "Would you like to book another day?" << endl;
	cout << "1 for yes, 2 for no" << endl;
	cin >> menuHolder;
	if (menuHolder = 2)
		menu = false;
	}
}

void reservation::cancelReservation()
{
	int menuHolder;
	int rType;
	int day;
	bool menu = true;


	
	while (menu == true)
	{
	
		cout << "Please pick room type:" << endl;
		cout << "1: Single Non-Smoking" << endl;
		cout << "2: Single Smoking" << endl;
		cout << "3: Double Non-Smoking" << endl;
		cout << "4: Double Smoking" << endl;
		cout << "5: Suite" << endl;
		cin >> rType;

		switch(rType)
		{
		
		case 1:
				cout << "What day would you like to cancel the room for?" << endl;
				cin >> day;
				if (room::sNon[day] == 1)
				{
			
				cout << "The room requested is booked, would you like to cancel" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
					if (menuHolder == 1)
					{
						room::sNon[day] = 0;
						break;
					}
					else
					break;
				}
				else
				{
				cout << "The room requested is not currently booked" << endl;
				break;
				}
			
		case 2:
			cout << "What day would you like to cancel the room for?" << endl;
			cin >> day;
			if (room::sSmoking[day] == 1)
			{
				cout << "The room requested is booked, would you like to cancel" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder == 1)
				{
			    room::sSmoking[day] = 0;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not currently booked" << endl;
				break;
			}
		case 3:
			cout << "What day would you like to cancel the room for?" << endl;
			cin >> day;
			if (room::dNon[day] == 1)
			{
				cout << "The room requested is booked, would you like to cancel" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder == 1)
				{
				room::dNon[day] = 0;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not currently booked" << endl;
				break;
			}
		case 4:
			cout << "What day would you like to cancel the room for?" << endl;
			cin >> day;
			if (room::dSmoking[day] == 1)
			{
				cout << "The room requested is booked, would you like to cancel" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
				if (menuHolder == 1)
				{
				room::dSmoking[day] = 0;
				break;
				}
				else
					break;
			}
			else
			{
				cout << "The room requested is not currently booked" << endl;
				break;
			}
		case 5:
			cout << "What day would you like to cancel the room for?" << endl;
			cin >> day;
			if (room::suite[day] == 1)
			{
				cout << "The room requested is booked, would you like to cancel" << endl;
				cout << "1 for Yes, 2 for No" << endl;
				cin >> menuHolder;
					if (menuHolder == 1)
					{
					room::suite[day] = 0;
					break;
					}
					else
						break;
			}
			else
				{
					cout << "The room requested is not currently booked" << endl;
					break;
				}
			}

	cout << "Would you like to cancel another day?" << endl;
	cout << "1 for yes, 2 for no" << endl;
	cin >> menuHolder;
	if (menuHolder == 2)
		menu = false;
	}
}


class reservation
{
	public:
	void setReservation();
	void cancelReservation();
}; 


#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include "client.h"
#include "room.h"
#include "reservation.h"

using namespace std;

char clientMenu();
char menu(char&);
void displayReservation();
void cancelReservation();
//void fillRoomArray();
void setRoomType();

int main()
{
	char operation;
	bool tryAgain = true;

	
	cout << "***WELCOME TO THE HOSPITALITY HOTEL RESERVATION SYSTEM***" << endl;
	while (tryAgain == true)  
	{
		menu(operation);

		switch(operation)
		{
		case 'M': case 'm': clientMenu();
							setRoomType();
							//reservationMenu(string fName, string lName, string ccTyp, string ccNum, string ccExp);
							break;
		case 'C': case 'c': cancelReservation(); 
							break;
		case 'D': case 'd': displayReservation(); 
							break;
		case 'X': case 'x': tryAgain = false;
							cout << "Goodbye ... " << endl;
							return 0;
							break;
		default: cout << "Invalid selection. Try again." << endl << endl;
							break;
		}
	}
}

  //method to display menu
char menu(char& operation)
{
	cout << "Enter a menu selection:" << endl;
	cout << "M  Make a reservation" << endl;
	cout << "C  Cancel a reservation" << endl;
	cout << "D  Display reservation information" << endl;
	cout << "X  Exit the program" << endl;
	cin >> operation;

	return operation;
}


char clientMenu()
{
   char fName[20];    
   char lName[30];   
   char ccType[20];
   char ccNum[17];
   char ccExpire[10];  

    client newClient;	

	cin.clear();
	cin.ignore(1, '\n');

	cout << "Enter first name: ";
	cin.getline(fName,20);
	cout << "Enter last name: ";
	cin.getline(lName,30);
	cout << "Enter credit card type: ";
	cin.getline(ccType,20);
	cout << "Enter credit card number: ";
	cin.getline(ccNum,17);
	cout << "Enter credit card expiration: ";
	cin.getline(ccExpire,10);

	newClient.setInfo(fName, lName, ccType, ccNum, ccExpire);
	newClient.writeFile();
    newClient.displayClientInfo();

	return 0;
}

void setRoomType()
{
	int rType;

	room newRoom;


		cout << "Please choose room type:" << endl;
		cout << "1: Single Non-Smoking" << endl;
		cout << "2: Single Smoking" << endl;
		cout << "3: Double Non-Smoking" << endl;
		cout << "4: Double Smoking" << endl;
		cout << "5: Suite" << endl;

		cin >> rType;
		
		
		newRoom.setRoomType(rType);
		newRoom.displayRoomInfo();

	
}


void displayReservation()
{
  string line;

  ifstream myReadfile ("clients.txt");
	if (myReadfile.is_open())
	{
		while (! myReadfile.eof() )
		{
			getline (myReadfile,line);
			cout << line << endl;
		}
    myReadfile.close();
	}

	else
	{
		cout << "Unable to open file"; 
	}
}

void cancelReservation()
{

	cin.clear();
	cin.ignore(1, '\n');

	vector<string> file;
	string temp;

	ifstream infile("clients.txt");

	while( !infile.eof() )
	{
		getline(infile, temp);
		file.push_back(temp);
	}

// done reading file
infile.close();

string name;

cout << "Enter first and last name of the reservation to cancel: ";
getline(cin, name);

for(int i = 0; i < (int)file.size(); ++i)
{
	if(file[i].substr(0, name.length()) == name)
	{
					
		file.erase(file.begin() + i);
		cout << "Your reservation has been cancelled!"<< endl;
		i = 0; // Reset search
	}
}

//write reservation list back out
ofstream out("clients.txt", ios::out | ios::trunc);

for(vector<string>::const_iterator i = file.begin(); i != file.end(); ++i)
{
	out << *i << endl;
}
out.close();
}


class client
{
  private:
   char fName[20];    //array to hold first name
   char lName[30];   
   char ccType[20];
   char ccNum[17];
   char ccExpire[10];       


  public:

	void setInfo(char firstName[], char lastName[], char cardType[], char cardNumber[], char cardExpire[]);
    void displayClientInfo();              //method to display info. 
	void writeFile(); 
};


#include <iostream>
#include "client.h"

using namespace std;




void client::setInfo(char firstName[], char lastName[], char cardType[], char cardNumber[], char cardExpire[])
{
	strcpy_s(fName,firstName);
	strcpy_s(lName,lastName);
	strcpy_s(ccType,cardType);
	strcpy_s(ccNum,cardNumber);
	strcpy_s(ccExpire,cardExpire);
}
void client::displayClientInfo()
{
   cout << "The client named " << fName << " " << lName << endl;
   cout << ccType << endl;
   cout << ccNum << endl;
   cout << ccExpire << endl;
   cout << endl;
}



I'm getting 8 errors involving LNK2001 and LNK2005. I'm completely lost, as this is not in my text book. Any help?

Is This A Good Question/Topic? 0
  • +

Replies To: LNK errors galore

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: LNK errors galore

Posted 08 May 2010 - 07:27 PM

Do you want to zip all these files up and attach them to your post? If this is a VC++ 2008 or VC++ 2010 project that would help as well.

If you can't do that then at least name all of the code blocks you posted. (e.g. main.cpp)
Was This Post Helpful? 0
  • +
  • -

#3 jeepguy1988  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 14
  • Joined: 11-September 09

Re: LNK errors galore

Posted 08 May 2010 - 07:30 PM

View Posteker676, on 08 May 2010 - 06:27 PM, said:

Do you want to zip all these files up and attach them to your post? If this is a VC++ 2008 or VC++ 2010 project that would help as well.

If you can't do that then at least name all of the code blocks you posted. (e.g. main.cpp)

Here is the zip with everything created. Thanks!Attached File  Hotel Reservation.zip (5.2K)
Number of downloads: 85
I'm using Visual Studio 2008.

This post has been edited by jeepguy1988: 08 May 2010 - 07:34 PM

Was This Post Helpful? 0
  • +
  • -

#4 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 841
  • View blog
  • Posts: 2,472
  • Joined: 20-March 10

Re: LNK errors galore

Posted 08 May 2010 - 07:33 PM

http://support.microsoft.com/kb/148652
Was This Post Helpful? 0
  • +
  • -

#5 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: LNK errors galore

Posted 08 May 2010 - 08:00 PM

Quote

I'm getting 8 errors involving LNK2001 and LNK2005. I'm completely lost, as this is not in my text book. Any help?
Here's an idea. How about copy pasting those errors here into a post? You can't understand them right? Do you think we can? Do you think that perhaps those errors have information that we can understand? Do you think that with that information, we might be able to tell you what's wrong with your code?

Then why do you prevent people from being able to help you, by not posting errors on the forum? Copy paste. Ctrl-C and Ctrl-V.

As for the text book portion, you're right, text books omit discussion of handling errors. Partly that's because errors are always compiler dependent. Here's the thing: you can Google. What happened when you Googled for those errors? What about reading the errors? Did you try reading?


Let me show you. I compiled your code and got a few linker errors. Here's one of them:

clientImp.obj : error LNK2005: "public: void __cdecl client::setInfo(char * con
t,char * const,char * const,char * const,char * const)" (?setInfo@client@@QEAAX
EAD0000@Z) already defined in classImp.obj



Starting from left to right: clientImp.obj. You might not have any idea what an obj file is. However, you know that you have a clientImp.cpp file, so you might guess that the problem might relate to clientImp.cpp as well. How about that?

Next: error LNK2005. Well, "error" is clear enough. No idea what 'LNK2005' means, but it's some kind of identification code, it seems. You try googling for "error LNK2005"?

Next: "public: void __cdecl client::setInfo(char * con
t,char * const,char * const,char * const,char * const)" (?setInfo@client@@QEAAX
EAD0000@Z)

What a mess. But you can extract somethings out of this. There's a reference to client::setInfo. You recognize that, don't you?

Next: already defined in classImp.obj

Well, what could already defined mean? Well, it's referring to client::setInfo in clientImp.obj, and says it's already defined in classImp.obj. Now, if we guess that obj relates to C++ files, and that define means creating the function (or we *surprise* Google it!), we could check if we repeated that function in both clientImp.cpp and classImp.cpp.

So you want to take a look?
Was This Post Helpful? 1
  • +
  • -

#6 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: LNK errors galore

Posted 08 May 2010 - 08:00 PM

Okay, I looked through it.

Your problems are coming from all the static arrays in room.h

I'm going to see if I can't find a solution but you may have to rewrite the program to use and instance of room rather than using static variables.


Another note, You cannot change the value of a static variable in a class after you have declared it. The only way to change the value is in the header file where the variable is declared. Then you have to use a special syntax.

Edit: I'm wrong, I was thinking about initializing the static variables

variabletype class::variableName = value;


And for anyone who would like to look at the code here is the VC++ 2010 Solution/Project all ready to go.

This post has been edited by eker676: 08 May 2010 - 08:10 PM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1