Help, I totally don't understand why my code is not working

Honestly, I'm new to C++ and don't really understand the structure yet. My professor give me a homework to do which is what I am trying to do right now. The program that my company should run is a virtual architecture design business and my company is specialize in designing specific types of room . I need a system to keep record on all the orders made by customers systematically.

This one is the header file
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
  #include <iostream>
#include <string>

#include <conio.h>
using namespace std;
string roomType;
int roomNumber;
int bed;
int table;
int towel;
int sofa;



class Node
{
public:

	string roomType;
	int roomNumber;
	int bed;
	int table;
	int towel;
	int sofa;
	Node *next;

	Node(int x, string a, int b, int c, int d, int e, Node *z)
	{
		roomType = a;
		roomNumber = x;
		bed = b;
		table = c;
		towel = d;
		sofa = e;
		next = z;
	}
};



class Room
{
private:
	Node *head;
	int count;
public:
	Room();//Room(DoubleRoom);
	void Menu();
	void roomtype(int);
	void addRoom();
	void deleteRoom(int x);
	void viewRoom();

};

class Roomtype : Room
{
private:
	Node * head;
public:
	Roomtype();
	string single();
	string twin();
	string supreme();

};



and this is the cpp file

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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include<iostream>
#include<string>
#include<cstdlib>
#include<ctime>
#include<iomanip>
#include"room.h"
using namespace std;
//---------------------------------------------== CLASS CUSTOMER ==---------------------------------------------------------------------------
class customer
{

public:

	int id;
	string name;
	customer*next;
	int phone;


	customer(int x, string y, customer *z, int b) //Constructor witn parameter
	{
		id = x;
		name = y;
		next = z;
		phone = b;

	}
};



//--------------------------------------------==CLASS ROOMREGISTRATION==-----------------------------------------------------------------

class RoomRegistration
{
private:customer*head;

		double total1;
		double total2;

public:
	RoomRegistration()
	{
		head = 0;
		total1 = 0.00;
		total2 = 0.00;
	}

};
//----------------------------------------------==MENU==------------------------------------------------------------------------------------
	void menu()
	{
		cout << " 1.Add customer\n 2.Delete a customer\n 3.Edit customer\n 4.View customer\n 5.Total customer and order\n 6.Exit\n";
		cout << " \n\n Please enter your choice: ";
	}

//-----------------------------------------------== ADD FUNCTION ==--------------------------------------------------------------------------
void addcust()

	{
		customer*p;
		p = head;
		int id = 0;

		string name = " ";
		string strg;
		int phone;


		cout << " Enter Your Name = ";
		cin >> name;
		cout << " Enter Your Id  = ";
		cin >> id;
		customer *temp, *second, *third;
		temp = head;
		while (temp != NULL)
		{
			if (temp->id == id)
			{
				cout << " Cannot add repeated id\n\n" << endl;
				system("pause");
				return;
			}
			temp = temp->next;
		}

		cout << " Enter Your Phone Number = ";
		cin >> phone;


		system("pause");
		system("cls");


		if (head == NULL)
		{
			head = new customer(id, name, NULL, phone);
		}

		else if (head->id > id)
		{
			second = head;
			head = new customer(id, name, NULL, phone);
			head->next = second;

		}

		else if (head->id > id)
		{
			second = head;
			third = head;

			while (second != NULL && second->id < id)
			{
				third = second;
				second = second->next;
			}

			p = new customer(id, name, NULL, phone);
			p->next = second;
			third->next = p;
		}
	}
	void Room::addRoom()
	{
			cout << "Please enter your information: " << endl;
			cout << " Room type" << endl;
			cout << "\n1.single\n2.double\n3.supreme\n:";
			cin >> roomType;
			cout << "Room Number ";
			cin >> roomNumber;
			cout << "No of bed: ";
			cin >> bed;
			cout << "No. of Table: ";
			cin >> table;
			cout << "No. of Towel: ";
			cin >> towel;
			cout << "No. of Sofa: ";
			cin >> sofa;
			cout << "Room Registered." << endl;

			Node *p;
			if (head == NULL)
			{
				head = new Node(roomNumber, roomType, bed, table, towel, sofa, NULL);
			}
			else
			{
				p = head;
				while (p->next != NULL)
					p = p->next;
				p->next = new Node(roomNumber, roomType, bed, table, towel, sofa, NULL);
			}

			//count ++;
	
}

//-----------------------------------------------==DROP FUNCTION ==--------------------------------------------------------------------------
void drop()
{
	int id;
	cout << " Enter id: ";
	cin >> id;
	customer *del = NULL;
	customer *temp = head;
	customer *second = head;

	while (second != NULL && ((*second).id) != id)
	{
		temp = second;//let temp point to watever end is pointed to
		second = (*second).next;
	}

	if (second == NULL)
	{
		cout << id << " No Data Deleted" << endl;
		delete del;//free memory;
	}

	else
	{
		del = second;
		second = (*second).next;
		(*temp).next = second;

		if (del == head)
		{
			head = (*head).next;
			temp = NULL;
		}

		delete del;
		cout << "The value " << id << " was deleted." << endl;
	}

}
Last edited on
What exactly doesn't work?

1
2
3
4
5
6
7
8
9
10
11
class Roomtype : Room // Note: this private inheritance, i.e. Roomtype cannot access anything from Room
{
private:
	Node * head; // Note: This shadows head from Room, i.e. head exists twice
public:
	Roomtype();
	string single();
	string twin();
	string supreme();

};


1
2
3
4
5
void addcust()

	{
		customer*p;
		p = head; // Where does this head come from? 


You cannot/shall not define variables in a header file. You will get multiple definition error by the linker if the header is included more than once.
Ouh, I see..

actually I'm upgrading the code from my previous assignment
So...I don't really understand how to do the improvement
The previous code work just fine, but when I add things, it produce multiple errors
Topic archived. No new replies allowed.