Librarian's Assistant Program Help

Hi, I need some help with a program.

The software needs to build the software to manage the library, its books, and library card holders.

This project needs to incorporate two main objects, books and cards:

•Book - this class defines the data that makes up a book object and the actions a book object can take. The data consists of:
o A title of the book
o Author
o Book number
o Whether it’s checked out or not
o Who has the book (Card ID of the holder, 0 if checked in)

A book needs to be able to create itself (constructor), check the status, change the status when a book is checked out/in, check who has the book, and change who has the book


•Card - this class defines the data that makes up a library card object and the actions a card object can take. The data consists of:
o Card holder’s name
o Card holder’s phone number
o Card ID number
o The book number of the book checked out (0 if none)

A card needs to be able to create itself (constructor), check any of the variables of the class, and change the book number.

The program needs to have a recurring main menu that reappears after every menu action is completed and must contain the following options.

1.Show all library cards
2.Show all books
3.Check out a book
4.Check in a book
5.Exit the system

I will post my code in subsequent posts below. Any additional tips would be appreciated. Thanks in advance if you can help!
Main code:

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
// Description: This program simulates the checking out and checking in of books from a library


#include <iostream>
#include <fstream>
#include "card.h"
#include "book.hpp"
#include <iomanip>
using namespace std;

void ShowMenu();
int findLibraryCard(int card, class card cards[]);
int findbook(int book, class book books[]);


int main()
{


	// declare an array of 20 cards
	card cards[20];
	int numCards = 0;
	int i = 0, j = 0;
	int command = 0;


	// declare an array of 20 books


	// declare a file pointer and open the cards file
	ifstream cardInput("cards.rtf");
	if (!cardInput)
	{
		cout << "ERROR: Cannot open file cards.rtf " << endl;
		system("pause");
		exit(1);
	}

	cout << "File openned.  Reading cards.rtf... " << endl;

	// read the next line from the file
	char name[30];
	char phone[15];
	int cardID;
	char junk[5];

	cardInput.getline(name, 30, ',');

	while (cardInput)
	{
		cardInput.getline(junk, 5, ' ');
		cardInput.getline(phone, 15, ',');
		cardInput.getline(junk, 5, ' ');
		cardInput >> cardID;
		cardInput.getline(junk, 5, '\n');

		//: Update the next empty card
		cards[i].setName(name);
		cards[i].setPhone(phone);
		cards[i].setCardID(cardID);
		numCards++;
		i++;

		cardInput.getline(name, 30, ',');
	}

	for (i = 0; i < numCards; i++)
	{
		cards[i].print();

	}



	// declare a file pointer and open the books file


	// read the next line from the file


	// display main menu
	ShowMenu();
	cout << "Enter a command: ";
	cin >> command;


	while (command != 0)
	{
		switch (command)
		{
		case 1: // Print all cards
			for (i = 0; i < numCards; i++)
			{
				cards[i].printcard();
			}
			break;
		case 2: // print all books
			for (i = 0; i < numBooks; i++)
			{
				books[i].printBook();
			}
			break;

		case 3: // check out a book
			// Ask for CardID
			cout << "Enter a Card Id: ";
			cin >> cardID;

			// Search cards[] for ID
			i = 0;

			while (i < numCards && cardID != cards[i].getCardID())
			{
				i++;
			}
			// If NOT found, Error and stop
			if (i == numCards)
			{
				cout << "ERROR: Card Not Found. Go to create card ID to make one. " << endl;
			}
			else
			{

				// if have a book, error and stop
				if (cards[i].getBookID() != 0)
				{
					cout << "ERROR: Already have a book checked out." << endl;
				}
				else
				{

					// Ask for bookID
					cout << "Enter the BookID: ";
					cin >> bookID;

					// Search books[] for ID
					j = 0;

					while (j < numBooks && bookID != books[j].getBookID())
					{
						j++;
					}

					// if NOT found. error and stop
							// If NOT found, Error and stop
					if (j == numBooks)
					{
						cout << "ERROR: Book Not Found." << endl;
					}
					else
					{

						// if have a book, error and stop
						if (books[j].isCheckedOut())
						{
							cout << "ERROR: Book checked out." << endl;
						}
						else
						{

							// check out the book
							cards[i].setBookID(bookID);

							books[j].setCardID(cardID);
						}
					}
				}
			}
			break;

		case 4: // check in a book
			// Ask for CardID
			cout << "Enter a Card Id: ";
			cin >> cardID;

			// Search cards[] for ID
			i = findLibraryCard(cardID);

			// If NOT found, Error and stop
			if (i >= 0)
			{


				// Ask for bookID
				cout << "Enter the BookID: ";
				cin >> bookID;


				j = findBook(bookID);

				if (j >= 0 && !books[j].isCheckedOut())
				{
					// check out the book
					cards[i].setBookID(0);
					books[j].setCardID(0);
				}




				break;


		case 5: // create a new card
			cout << "Enter your name: ";
			cin >> name; // joe_smith (no spaces in name)

			cout << "Enter your phone number: ";
			cin >> phone;    // Use 999-999-1234 format (no Spaces)

			cout << "Enter a Card ID: ";
			cin >> cardID;

			cards[numCards].setName(name);
			cards[numCards].setPhone(phone);
			cards[numCards].setCardID(cardID);
			numCards++;
			break;

		case 0:


		default:
			cout << " ERROR: Menu options must be between 0 and 5. " << endl;
			}

			ShowMenu();
			cin >> command;
		}


	}
}

void ShowMenu()
{
	cout << endl << endl;
	cout << "    [ M a i n   M e n u]      " << endl;
	cout << "============================  " << endl;
	cout << " 1. show all library cards    " << endl;
	cout << " 2. show all books            " << endl;
	cout << " 3. check out a book          " << endl;
	cout << " 4. check in a book           " << endl;
	cout << " 5. Create a new Library Card " << endl;
	cout << " 0. Exit the system           " << endl;
}




int findLibraryCard(int card, card cards[])
{

	// Search cards[] for ID
	int i = 0;

	while (i < numCards && cardID != cards[i].getCardID())
	{
		i++;
	}
	// If NOT found, Error and stop
	if (i == numCards)
	{
		cout << "ERROR: Card Not Found. Go to create card ID to make one. " << endl;
		return -1;
	}
	else
	{
		return i;
	}
}

int findbook(int book, class book books[])
{
	int j = 0;

	// Search books[] for ID

	while (j < numBooks && bookID != books[j].getBookID())
	{
		j++;
	}

	// if NOT found. error and stop
	// If NOT found, Error and stop
	if (j == numBooks)
	{
		cout << "ERROR: Book Not Found." << endl;

		return -1;
	}
	else
	{
		return j;
	}
}
card.h file

#include <iostream>
using namespace std;

#ifndef Card_H

#define Card_H



class card
{
private:
char name[30];
char phone[15];
int cardID;
int bookID;

public:
card();
card(char n[], char p[], int c[]);
void setCardID(int c);
void setName(char n[]);
void setPhone(char p[]);
void setBookID(int b);
int getBookID();
int getCardID();
void printcard();


};

#endif
book.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
#include <iostream>
#include "book.hpp"
using namespace std;




book::book()
{
    bookID = 0;
    CardID = 0;
    CheckedOut = false;
    
}



book::book(int bID, char t[], char a[])

{
    bookID = bID;
    CardID = 0;
    CheckedOut = false;
    strcpy(Title, t);
    strcpy(Author, a);
}

void book::setTitle(char t[])
{
    strcpy(Title, t);
}

void book::setAuthor(char a[])
{
    strcpy(Author, a);
}


bool book::isCheckedOut()
{
    if(CardID == 0)
        CheckedOut = false;
    else
        CheckedOut = true;
    return CheckedOut;
}


void book::setCheckedOut(int c)

{
    
    
}


int book::getCardID()
{
    
    
}

void book::setCardID(int c)
{
    CardID = c;
    
}

void book::printBook()
{
    cout << bookID << "  "
         << Title << "  "
         << Author << "  "
         << (CheckedOut ? "Checked Out":"On Shelf");
         << CardID << endl;
}
book.h 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
// Description: This program simulates the checking out and checking in of books from a library


#include <iostream>
#include <iomanip>
#ifndef Book_H
#define Book_H

class book{
    
private:
    int bookID;
    char Title[30];
    char Author[25];
    bool CheckedOut;
    int CardID;
    
    
public:
    book();
    book(int bID, char t[], char a[]);
    int getBookID();
    void setBookID(int b);
    void setTitle(char t[]);
    void setAuthor(char a[]);
    bool isCheckedOut();
    void setCheckedOut(int c);
    int getCardID();
    void setCardID(int c);
    void printBook();
};

#endif 
card.c 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
#include <iostream>
#include "card.h" 
using namespace std; 



card::card()
{
    bookID = 0;
    cardID = 0;
    
}


card::card(char n[], char p[], int c[])
{
    cardID = 0;
    strcpy(name, n);
    strcpy(phone, p);
    
}

void card::setCardID(int c)
{
    cardID = c;
}

void card::setName(char n[])
{
    strcpy(name, n);
}

void card::setPhone(char p[])
{
    strcpy(phone, p);
}

void card::setBookID(int b)
{
    bookID = b;
}

int card::getBookID()
{
    
}


void card::printcard()
{
    cout << cardID << "   "
         << name << "  "
         << phone << "  "
    << bookID << endl; 
}
What kind of help do you need?
Topic archived. No new replies allowed.