Project Help

closed account (3RGNvqkS)
Hello I've been working in the code and I need to modify the code below

My concern are the following:

- [6]Check Video Availability = when you input 6 in the system and enter the movie code, it will show the movie details that inputted by the user in the insert a video and check if the movie is available or not. If the copy of the movie inputted by the user reaches 0 (due to renting the movie which decreases the copies of the movie) it will state that the movie is unavailable.

- I also need to implement this:
[7] Customer Maintenance - If the user inputs 7 it will show another options:
[1] - Add Customer
[2] - Show Customer Details
[3] - List of Videos Rented by a Customer

* I must store the customers in a queue when I retrieved them from the text file
Rented videos will be stored in a stack and will be saved in the CUSTOMER-RENT text file when
the user chooses [8] Exit Program.

codes in the comment section
Last edited on
closed account (3RGNvqkS)
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#include <iostream>

  
using namespace std;
struct Cine
{
	int code;
	int year;
	int copies;
	char name[100]; 
	char genre[100]; 
	char production[100];
};

class CinemaList
{
private:
	struct MovieNode
	{
		Cine movie;
		struct MovieNode* next;

	};
	MovieNode* head;
public:
	CinemaList();
	~CinemaList();
	void appendNode(Cine cin);
	void insertNode(Cine cin);
	void showDetails(Cine cin);
	void deleteNode(Cine cin);
	void displayList();
	void availability (Cine cin); 
	
};


CinemaList::CinemaList()
{
	head = NULL;
}

CinemaList::~CinemaList()
{
	MovieNode *nodePtr, *nextNode;

	nodePtr = head;
	while (nodePtr != NULL)
	{
		nextNode = nodePtr->next;
		delete nodePtr;
		nodePtr = nextNode;
		
	}

}
void CinemaList::appendNode(Cine mov)
{
	MovieNode *newNode, *nodePtr;
	
	newNode = new MovieNode;
	newNode->movie = mov;
	newNode->next = NULL;

	if (!head)
		head = newNode;
	else	
	{
		
		nodePtr = head;
		
		while (nodePtr->next)
			nodePtr = nodePtr->next;
		
		nodePtr->next = newNode;
	}
	
}

void CinemaList::displayList()
{
	MovieNode *nodePtr;
	if (head == NULL)
		printf("\x1B\n\t\t\t\t\t\a[31mNo results found. \033[0m\t\t\n");
	else
	{
		printf("\033\n\t\t\t\t\t\a[1;47;35mThe Video Nodes on the List\033[0m\t\t\n");
		nodePtr = head;
		while (nodePtr)
		{
			printf("\x1B\n\t\t\t\t\t\a[32m Year Released:\033[0m ");
			cout << nodePtr->movie.code << endl;
			printf("\x1B\t\t\t\t\t\a[32m Video Name:\033[0m "); 
			cout << nodePtr->movie.name << endl;
			printf("\x1B\t\t\t\t\t\a[32m Production:\033[0m "); 
			cout << nodePtr->movie.production << endl;
			nodePtr = nodePtr->next;
		}
	}
}
void CinemaList::showDetails(Cine mov)
{
	MovieNode *nodePtr;

	if (head == NULL)
		printf("\x1B\n\t\t\t\t\t\a[31mNo results found. \033[0m\t\t\n");
	else {
		
		nodePtr = head;
		while (nodePtr)
		{
			printf("\x1B\n\t\t\t\t\t\a[32m Video Code:\033[0m "); 
			cout << nodePtr->movie.code << endl;
			printf("\x1B\t\t\t\t\t\a[32m Video Name\033[0m ");  
			cout << nodePtr->movie.name << endl;
			printf("\x1B\t\t\t\t\t\a[32m Year Released:\033[0m ");  
			cout << nodePtr->movie.year << endl;
			printf("\x1B\t\t\t\t\t\a[32m Genre:\033[0m ");  
			cout << nodePtr->movie.genre << endl;
			printf("\x1B\t\t\t\t\t\a[32m Production:\033[0m ");  
			cout << nodePtr->movie.production << endl;
			printf("\x1B\t\t\t\t\t\a[32m Copies:\033[0m ");  
			cout << nodePtr->movie.copies << endl;
			
			nodePtr = nodePtr->next;
			cout << '\n';
		}
	}
}

void CinemaList::insertNode(Cine cin)
{
	MovieNode *newNode, *nodePtr, *previousNode;


	newNode = new MovieNode;
	newNode->movie = cin;


	if (!head)
	{
		head = newNode;
		newNode->next = NULL;
	}
	else	
	{

		nodePtr = head;
		previousNode = NULL;

		{
			previousNode = nodePtr;
			nodePtr = nodePtr->next;
		}

		if (previousNode == NULL)
		{
			head = newNode;
			newNode->next = nodePtr;
		}
		else
		{
			previousNode->next = newNode;
			newNode->next = nodePtr;
		}
	}
	
	
	
}

void CinemaList::deleteNode(Cine cin)
{
	MovieNode *nodePtr, *previousNode;
	int found = 0;

	
	if (!head)
	{
		printf("\x1B\n\t\t\t\t\t\a[31mNo results found. \033[0m\t\t\n");
		return;
	}

	
	if (head->movie.code == cin.code)
	{
		nodePtr = head->next;
		delete head;
		head = nodePtr;
		printf("\033\n\t\t\t\t\t\a[1;47;35mVideo Rented!\033[0m\t\t\n");
		found = 1;
	}
	else
	{
		
		nodePtr = head;
		previousNode = NULL;

		
		while (nodePtr != NULL && nodePtr->movie.code != cin.code)
		{
			previousNode = nodePtr;
			nodePtr = nodePtr->next;
		}

	
		if (nodePtr != NULL)
		{
			previousNode->next = nodePtr->next;
			delete nodePtr;
			system ("clear");
      printf("\033\n\t\t\t\t\t\a[1;47;35mVideo Rented!\033[0m\t\t\n");
			found = 1;
		}
	}
	if (found == 0)
		printf("\x1B\n\t\t\t\t\t\a[31mNo results found. \033[0m\t\t\n");
}

void CinemaList::availability(Cine mov) //new
{
	MovieNode *nodePtr;

	if (head == NULL)
		printf("\x1B\n\t\t\t\t\t\a[31mNo results found. \033[0m\t\t\n");
	else {
		
		nodePtr = head;
		while (nodePtr)
		{
			printf("\x1B\n\t\t\t\t\t\a[32m Video Code:\033[0m "); 
			cout << nodePtr->movie.code << endl;
			printf("\x1B\t\t\t\t\t\a[32m Video Name\033[0m ");  
			cout << nodePtr->movie.name << endl;
			printf("\x1B\t\t\t\t\t\a[32m Year Released:\033[0m ");  
			cout << nodePtr->movie.year << endl;
			printf("\x1B\t\t\t\t\t\a[32m Genre:\033[0m ");  
			cout << nodePtr->movie.genre << endl;
			printf("\x1B\t\t\t\t\t\a[32m Production:\033[0m ");  
			cout << nodePtr->movie.production << endl;
			printf("\x1B\t\t\t\t\t\a[32m Availability:\033[0m ");  
			cout << nodePtr->movie.copies << endl;
			
			nodePtr = nodePtr->next;
			cout << '\n';
		}
	}
}

int menu()
{ 
    
	int ch;
	
	system("clear");
	printf("\033\n\t\t\t\t\t\a[1;47;35mNEIGHNORHOOD VIDEO STORE\033[0m\t\t\n");
	printf("\x1B\n\t\t\t\t\t[32m[1] Insert a Video\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[2] Rent a Video\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[3] Return a Video\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[4] Show Video Details\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[5] Display All Videos\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[6] Check Video Availability\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[32m[7] Customer Maintenance\033[0m\t\t");
	printf("\x1B\n\t\t\t\t\t[31m[8] Exit the System \033[0m\t\t\n");
	printf("\x1B\n\t\t\t\t\t[93mEnter a Number:\033[0m ");
	cin >> ch;
	return(ch);
}

int main()
{
    home:
	CinemaList list;
	Cine num;
	int ch;
	
	
	do 
	{
		ch = menu();
		
		system("clear");
		
		if (ch == 1)
		{
		  
			printf("\033\n\t\t\t\t\t\a[1;47;35mInsert a Movie \033[0m\t\t\n");
			printf("\x1B\n\t\t\t\t\t[32m Enter Movie Code:\033[0m ");
			    cin >> num.code;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Year Released:\033[0m ");
			    cin >> num.year;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Movie Name:\033[0m ");
				cin >> num.name;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Movie Genre:\033[0m ");
				cin >> num.genre;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Movie Production:\033[0m ");//help
				cin >> num.production;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Number of Copies:\033[0m "); //help
				cin >> num.copies;
			system ("clear");
	        printf("\033\n\t\t\t\t\t\a[1;47;35mMovie Inserted!\033[0m\t\t\n");
	        system ("sleep 3s");
			list.insertNode(num);
			

		}
		else if (ch == 2)
		{
			printf("\033\n\t\t\t\t\t\a[1;47;35mRent a Movie\033[0m\t\t\n");
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Movie Code:\033[0m ");
			cin >> num.code;
			list.deleteNode(num);
			system ("sleep 3s");
		}
		else if (ch == 3)
		{
			printf("\033\n\t\t\t\t\t\a[1;47;35mReturn a Movie\033[0m\t\t\n");
			printf("\x1B\n\t\t\t\t\t[32m Enter Movie Code:\033[0m ");
			cin >> num.code;
			printf("\x1B\n\t\t\t\t\t\a[32m Enter Year Released:\033[0m ");
			cin >> num.year;
			system ("clear");
	        printf("\033\n\t\t\t\t\t\a[1;47;35mMovie Returned!\033[0m\t\t\n");
	        system ("sleep 3s");
			list.insertNode(num);
			system ("sleep 3s");
			
			
		}
		else if (ch == 4)
		{
			printf("\033\n\t\t\t\t\t\a[1;47;35mShow Movie Details\033[0m\t\t\n");
			list.showDetails(num);
			system ("sleep 3s");
			
		}
		else if (ch == 5)
		{
			printf("\033\n\t\t\t\t\t[1;47;35mPrint Movie List\033[0m\t\t\n");
			list.displayList();
			system ("sleep 3s");
			
		}
		else if (ch == 8)
		{
			printf("\033\n\t\t\t\t\t\a[1;47;35mThank you for Using C++ Programming Language\033[0m\t\t\n");
			system ("sleep 3s");
			printf("\x1B\n\t\t\t\t\t\t[31m Linked List Movie Destroyed! \033[0m\t\t\n");
			list.~CinemaList();
			return 0;
			
		
	
		}

	else if (ch == 6)
		{
			printf("\033\n\t\t\t\t\t[1;47;35mCheck Video Availability\033[0m\t\t\n");
			list.displayList();
			system ("sleep 3s");
			
		}
	
		
	} while (ch >= 1 && ch <= 8);

        if (ch != 1 && ch != 2 && ch != 3 && ch != 4 && ch != 5 && ch != 8)
		{
		    
		    printf("\x1B\n\t\t\t\t\t\a[31mInvalid Number. Going back to homepage... \033[0m\t\t\n");
		    system ("sleep 2s");
		    goto home;
		    
		} 
}
What issue exactly are you having?
closed account (3RGNvqkS)
hello. I've updated my concern sorry for inconvenience. my concern is to help me modify the code based on the following:

- [6]Check Video Availability = when you input 6 in the system and enter the movie code, it will show the movie details that inputted by the user in the insert a video and check if the movie is available or not. If the copy of the movie inputted by the user reaches 0 (due to renting the movie which decreases the copies of the movie) it will state that the movie is unavailable.

- I also need to implement this:
[7] Customer Maintenance - If the user inputs 7 it will show another options:
[1] - Add Customer
[2] - Show Customer Details
[3] - List of Videos Rented by a Customer
Last edited on
On line 150, you're missing, what I assume, should be this:

while(nodePtr != NULL)

The bigger issue is that renting a movie deletes the node while returning it creates a new node again. This is NOT how you want to do it.

You ask the user for the number of copies of the movie you have. When you rent a movie, you don't delete the node, you subtract 1 from the variable "copies". If copies is already 0, then you tell them you can't rent it because it's unavailable.

When they return the movie, you increase "copies" by 1.

So when they enter the code, search for the node as you already are, but don't delete it!
I must store the customers in a queue when I retrieved them from the text file
Rented videos will be stored in a stack


There seems to be some confusion over this. CinemaList seems to be a single forward linked list. But this is not a stack/queue. For a stack, items are pushed onto the top of the stack when added and removed from the top of the stack (LIFO). For a queue, items are pushed onto the top of the queue and removed from the bottom of the queue (FIFO). For either, you don't amend an already added item and you don't remove an item other than at the top for stack or bottom for queue. Usually you don't iterate over a stack/queue either. You just know about the top (for stack) or bottom (for queue) element.

Now if you are required to use a stack/queue as opposed to lists and if you are required to implement your own stack/queue from scratch (as opposed to using the C++ std::stack and std::queue containers), then first I would suggest to actually implement a class for a stack and a class for a queue based upon a double linked (with head/tail pointers) list class. Once you have a working stack/queue then you can code the requirements for the program around these.
closed account (3RGNvqkS)
okay tnx for that. I'll try to work on it.
Topic archived. No new replies allowed.