Project Description In this project you read lists of users and books from users
ID: 3567370 • Letter: P
Question
Project Description
In this project you read lists of users and books from users.txt and books.txt respectively. In each line of books.txt there are a unique ID and a unique title for a book that are separated by a space (Both fields are String). The format of each line in this file is as follows:
bookId bookTitle
users.txt file contains a list of users that are stored per line. Each user has a unique ID, a unique name and a number that represents the maximum allowed number of books that the user can have at a time. The format of each line in this file is as follows (Name and ID are String and the last field is an integer):
userId userName userMaxAllowedNumberOfBooks
There is a file named interactions.txt containing all users activities over a period of time in time order. Each line in this file has two string values that are separated by a space in the following format:
userId bookId
Each interaction (a line in this file) shows an activity of borrowing or returning a book with the given book ID by a user with the given user ID. If the user does not have the book, this interaction could be assumed as borrowing the book otherwise it shows the user is returning the book.
In this project you develop an application that simulates the interactions over the given sets of users and books and creates a file containing all users names with a list of books names that they have after the simulation. Each line in this file starts with a user name then a space and continues by comma separated books names that the user borrowed but never returned. Users name must be appeared in the same order as the user file.
Rules
1. A user can borrow any number of books up to the given maximum allowed number of
books.
2. Whenever a user requests to borrow a book and he or she already reached to the
maximum allowed number of books, you should ignore the request.
3. If a user requests a book which is already borrowed, you should queue this request for the
book and serve it later.
4. When a book is returned, you should serve the first person in the queue for this book. If
he or she already reached to the maximum allowed number of books and there is no room
for borrowing a new book, you should discard the request and serve the next person in
the queue.
Requirements
You should only have three classes: Book, User and LibraryManager. In LibraryManager there should be a function as the starting method with the following signature:
public static void start(string usersFileName, string booksFileName, string interactionsFileName, string outputFileName)
This method will be called to run your application.
Explanation / Answer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class stock
{
char author[50];
char title[50];
char pub[50];
double price;
int numcopies;
public:
stock();
int access_title(char a[]);
void input();
void getdata(int);
};
stock::stock()
{
char author[50]={"abc"};
char title[50]={"efg"};
char pub[50]={"hij"};
price=500;
numcopies=50;
}
int stock::access_title(char a[])
{
if(strcmp(title,a))
return 0;
else return 1;
}
void stock::getdata(int num)
{
if(numcopies>=num)
cout<<" Cost of "<<num<<" books is Rs. "<<(price*num);
else
cout<<" Sorry! These many copies are unavailable!";
}
void stock::input()
{
cout<<" Title: ";
gets(title);
cout<<" Author:";
gets(author);
cout<<" Publisher:";
gets(pub);
cout<<" Prices:";
cin>>price;
cout<<" copies available:";
cin>>numcopies;
}
void main()
{
clrscr();
stock obj[2];
int n;
char ttle[50];
cout<<"Enter details of 3 books";
for(int i=0;i<2;++i)
obj[i].input();
cout<<endl;
cout<<" Enter title of required book ";
gets(ttle);
for(i=0;i<2;i++)
{
if(obj[i].access_title(ttle))
{
cout<<" How many copies? ";
cin>>n;
obj[i].getdata(n);
}
else
cout<<" Book unavailable";
}
getch();
}
OUTPUT:
Enter details of 3 books
Title: Da Vinci Code
Author:Dan Brown
Publisher:Sun
Prices:455
copies available:300
Title: Harry Potter
Author:J K Rowling
Publisher:Bloomsbury
Prices:800
copies available:100
Enter title of required book
HarryPotter
Book available
How many copies? 20
Cost of 20 books is Rs. 16000
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.