IN C++
My project will be a library management system. It will have seven functions.
It HAS to contain: classes, structures, pointers and inheritance.
fix code according to below
1. Add a new book
allows the user to enter in book name and book code
Book code has to be in #
“Invalid book code”
“book name has been added to library”
book code will be used to borrow books
2. Add a new user
must use first
user must add a user ID and username
User ID must be in #
“Invalid user ID”
“Welcome username”
user ID is used for borrowing books
3. Borrow a book
uses the book code to borrow a book
Book code must be in #
“Invalid book code”
“Username has borrowed book name”
Borrowing a borrowed book
“This book is being borrowed by username”
once a book is borrowed no one else can borrow it
changes availability to unavailable in search a book
4. Return a book
-returns the availability of the book to available
enter in book code to return
Book code must be in #
“Invalid book code”
“Thank you for returning book name”
Changes availability of the book to available
5. Search a book
enter in book code
“Invalid book code”
shows availability
the message “sorry this book is borrowed by username”
shows who borrowed the book and book name
6. Displays users and number of books they have
Shows all user ID, Username and number of books they have
7. Exit
Exits the program
What i have so far (modify this code):
most of it is written just fix up the mistakes
#include <iostream>
using namespace std;
//structure to store library data
struct library{
int code;
char title[20];
int status;
};
//structure to store user data
struct users{
int id;
char name[20];
int booksNumber;
};
int main()
{
int tempId,i,flag=0,j;
char tempName[20];
int tempCode;
struct users user_details[100];//variable to hold 100 userdetails
struct library book_details[100];//variable to hold 100 book details
int user_count=0,books_count=0;
int choice;
//this loop runs until 7 is entered
do{
cout <<"MENU \n";
cout << "1. Add a new book\n";
cout << "2. Add a new user\n";
cout << "3. Borrow a book\n";
cout << "4. Return a book\n";
cout << "5. Search a book\n";
cout << "6. Displays users and number of books they have\n";
cout << "7. Exit\n";
cout << "Enter your choice : ";
cin >> choice;
switch(choice){
//Adds a new book in to the database and increase book count by 1
case 1:
cout<<"Bookname : ";
cin >> book_details[books_count].title;
cout <<"Bookcode : ";
cin >> book_details[books_count].code;
book_details[books_count].status = 1;
books_count++;
break;
case 2:
//adds a new user details in to database
cout << "Enter UserId : ";
cin >> tempId;
//flag variable to check whether user exists or not
flag=1;
for(i=0;i<user_count;i++){
if(tempId==user_details[i].id){
cout << "UserId already taken";
flag=0;
break;
}
}
//if user is not taken creating user id and increase user_count by 1
if(flag){
user_details[user_count].id=tempId;
cout << "Enter Username : ";
cin >> user_details[user_count].name;
user_details[user_count].booksNumber=0;
user_count++;
}
break;
case 3:
cout << "Please enter your userId : ";
cin >> tempId;
flag = 0;
//check whether user exists or not using flag variable
for(i=0;i<user_count;i++){
if(user_details[i].id==tempId){
flag = 1;
break;
}
}
//if user exists then print his name and check fof the requested book
if(flag){
cout << "Welcome " << user_details[i].name << "\n";
//if user has taken less than 5 books
if(user_details[i].booksNumber<=5){
cout << "Please enter book code you want to borrow : ";
cin >> tempCode;
for(j=0;j<books_count;j++){
if(book_details[j].code==tempCode && book_details[j].status!=0){
book_details[j].status=0;
user_details[i].booksNumber++;
flag = 0;
break;
}
}
if(flag){
cout << "Book not found or it has been currently borrowed\n";
}
}
else{
cout << "The user reaches the max. allowed books to borrow\n";
}
}
else{
cout << "Username incorrect ;";
}
break;
case 4:
// to return the book issued to a user
cout << "Please enter book code :";
cin >> tempCode;
flag=0;
for(i=0;i<books_count;i++){
if(book_details[i].code==tempCode){
flag = 1;
break;
}
}
//once book is found then check for user id
if(flag){
if(book_details[i].status==0){
cout << "Enter user id ";
cin >> tempId;
flag = 0;
for(j=0;j<user_count;j++){
if(user_details[j].id==tempId){
flag =1;
break;
}
}
//if user and book details are found
if(flag){
user_details[j].booksNumber--;
book_details[i].status = 1;
}
else{
cout << "User not found\n";
}
}
else{
cout << "Book hasn't been borrowed\n";
}
}
else{
cout << "Invalid code\n";
}
break;
case 5:
//Searching a book using bookcode
cout << "Enter book code : ";
cin >> tempCode;
for(i=0;i<books_count;i++){
if(book_details[i].code==tempCode){
cout << book_details[i].code <<"\t"<< book_details[i].title <<"\t"<< book_details[i].status << "\n";
break;
}
}
break;
case 6:
//printing details of user using user_details structure
cout << "UserID UserName BorrowerNo\n";
for(i=0;i<user_count;i++){
cout << user_details[i].id <<"\t"<< user_details[i].name <<"\t"<< user_details[i].booksNumber<<"\n";
}
cout << "\n";
break;
case 7:
cout << "ThankYou";
break;
//if user input doesnot match with any of the case then ask him to enter data again
default:
cout << "Please enter valid input : ";
}
}while(choice!=7);
return 0;
}
#include <iostream>
#include <sstream>
#include <cstring>
#include<string>
using namespace std;
//structure to store library data
struct library{
int code;
char title[30];
int status;
};
//structure to store user data
struct users{
int id;
char name[20];
int booksNumber;
};
bool isNumber(string s)
{
for (int i = 0; i < s.length(); i++)
if (isdigit(s[i]) == false)
return false;
return true;
}
int main()
{
int tempId,i,flag=0,j;
char tempName[20];
int tempCode;
struct users user_details[100];//variable to hold 100 userdetails
struct library book_details[100];//variable to hold 100 book details
int user_count=0,books_count=0;
int choice;
//this loop runs until 7 is entered
do{
cout <<"MENU \n";
cout << "1. Add a new book\n";
cout << "2. Add a new user\n";
cout << "3. Borrow a book\n";
cout << "4. Return a book\n";
cout << "5. Search a book\n";
cout << "6. Displays users and number of books they have\n";
cout << "7. Exit\n";
cout << "Enter your choice : ";
string str="";
cin >> str;
// Function returns 1 if all elements
// are in range '0-9'
if (isNumber(str)) {
stringstream geek(str);
geek >> choice;
switch(choice){
//Adds a new book in to the database and increase book count by 1
case 1:
{
cout<<"Bookname : ";
cin>>book_details[books_count].title;
cout <<"Bookcode : ";
string str="";
cin >> str;
// Function returns 1 if all elements
// are in range '0-9'
if (isNumber(str)) {
// object from the class stringstream
stringstream geek(str);
// The object has the value 12345 and stream
// it to the integer book_details[books_count].code
geek>>book_details[books_count].code;
book_details[books_count].status = 1;
books_count++;
cout<<"Book name has been added to library\n";
break;
}else
{
cout << "Invalid Book Code";
break;
}
//book_details[books_count].code
}
case 2:
{
//adds a new user details in to database
cout << "Enter UserId : ";
string str="";
cin >> str;
// Function returns 1 if all elements
// are in range '0-9'
if (isNumber(str)) {
// object from the class stringstream
stringstream geek(str);
// The object has the value 12345 and stream
// it to the integer tempId
geek>>tempId;
//flag variable to check whether user exists or not
flag=1;
for(i=0;i<user_count;i++){
if(tempId==user_details[i].id){
cout << "UserId already taken\n";
flag=0;
break;
}
}
//if user is not taken creating user id and increase user_count by 1
if(flag){
user_details[user_count].id=tempId;
cout << "Enter Username : ";
cin >> user_details[user_count].name;
user_details[user_count].booksNumber=0;
user_count++;
}
break;
}else
{
cout << "Invalid UserId\n";
break;
}
}
case 3:
{
cout << "Please enter your userId : ";
string str="";
cin >> str;
// Function returns 1 if all elements
// are in range '0-9'
if (isNumber(str)) {
// object from the class stringstream
stringstream geek(str);
// The object has the value 12345 and stream
// it to the integer tempId
geek>>tempId;
flag = 0;
//check whether user exists or not using flag variable
for(i=0;i<user_count;i++){
if(user_details[i].id==tempId){
flag = 1;
break;
}
}
//if user exists then print his name and check fof the requested book
if(flag){
cout << "Welcome " << user_details[i].name << "\n";
//if user has taken less than 5 books
if(user_details[i].booksNumber<=5){
cout << "Please enter book code you want to borrow :
";
string tempcodde;
cin >> tempcodde;
if (isNumber(tempcodde)) {
// object from the class stringstream
stringstream geek(tempcodde);
// The object has the value 12345 and stream
// it to the integer tempId
geek>>tempCode;
}
else{
cout<<"Invalid book code \n";
break;
}
for(j=0;j<books_count;j++){
if(book_details[j].code==tempCode && book_details[j].status!=0){
book_details[j].status=0;
user_details[i].booksNumber++;
flag = 0;
break;
}
}
if(flag){
cout << "Book not found or it has been currently borrowed\n";
}
}
else{
cout << "The user reaches the max. allowed books to borrow\n";
}
}
else{
cout << "Username incorrect ;";
}
break;
}else
{
cout << "Invalid UserId\n";
break;
}
}
case 4:
// to return the book issued to a user
cout << "Please enter book code :";
cin >> tempCode;
flag=0;
for(i=0;i<books_count;i++){
if(book_details[i].code==tempCode){
flag = 1;
break;
}
}
//once book is found then check for user id
if(flag){
if(book_details[i].status==0){
cout << "Enter user id ";
cin >> tempId;
flag = 0;
for(j=0;j<user_count;j++){
if(user_details[j].id==tempId){
flag =1;
break;
}
}
//if user and book details are found
if(flag){
user_details[j].booksNumber--;
book_details[i].status = 1;
}
else{
cout << "User not found\n";
}
}
else{
cout << "Book hasn't been borrowed\n";
}
}
else{
cout << "Invalid code\n";
}
break;
case 5:
//Searching a book using bookcode
cout << "Enter book code : ";
cin >> tempCode;
for(i=0;i<books_count;i++){
if(book_details[i].code==tempCode){
cout << book_details[i].code <<"\t"<< book_details[i].title <<"\t"<< book_details[i].status << "\n";
break;
}
}
break;
case 6:
//printing details of user using user_details structure
cout << "UserID UserName BorrowerNo\n";
for(i=0;i<user_count;i++){
cout << user_details[i].id <<"\t"<< user_details[i].name <<"\t"<< user_details[i].booksNumber<<"\n";
}
cout << "\n";
break;
case 7:
cout << "ThankYou";
break;
//if user input doesnot match with any of the case then ask him to enter data again
default:
cout << "Please enter valid input range from 1-7: \n";
}
}
else
{
cout<<"you should check your input . it may be
string or specific symbol\n";
}
}while(choice!=7);
cout<<"Please enter valid value ";
}
now i made some changes like entering char in the choice but the book name problem is still same... i m trying to finding new ways to solve the problem ,, the problem occurs because of multiple spaces..
input - the ways of kings contain 4 whitespace so the IDE treats it as new line or new input for the code.. thats why the problem occurs instead of using white space you should try "the_ways_of_kings" . well i am trying to finding new ways ..till then you can use this code.. i will provide the solution as soon as possible..
IN C++ My project will be a library management system. It will have seven functions. It...
IN C++ Help to fix code Library management program. Error is when i type a letter into options menu the code breaks. after your edits, the code should still run as normal. CODE: #include<iostream> using namespace std; //structure to store library data class BookDetails{ public: struct library { int code; char title[20]; int status; }; library book_details[100]; }; //structure to store user data class UserDetails:public BookDetails{ public: struct users { int id; char name[20]; int booksNumber; }; users user_details[100]; };...
I'm just a beginner in programming,how to make this program more simple without using #include<iostream> and #include<redex> here is the question Terms to know: If-else statement,for..while..do while,loops,pointer,address,continue,return,break. Create a C++ program which contain a function to ask user to enter user ID and password. The passwordmust contain at least 6 alphanumeric characters, 1 of the symbols !.@,#,$,%,^,&,* and 1 capital letter.The maximum allowable password is 20. Save the information. Test the program by entering the User ID and password. The...
fully comments for my program, thank you will thumb up #include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; struct book { int ISBN; string Author; string Title; string publisher; int Quantity; double price; }; void choice1(book books[], int& size, int MAX_SIZE) { ifstream inFile; inFile.open("inventory.txt"); if (inFile.fail()) cout <<"file could not open"<<endl; string str; while(inFile && size < MAX_SIZE) { getline(inFile, str); books[size].ISBN = atoi(str.c_str()); getline(inFile, books[size].Title); getline(inFile, books[size].Author); getline(inFile, books[size].publisher); getline(inFile,...
Program is in C++, program is called airplane reservation. It is suppose to display a screen of seating chart in the format 1 A B C D E F through 10. I had a hard time giving the seats a letter value. It displays a correct screen but when I reserve a new seat the string seats[][] doesn't update to having a X for that seat. Also there is a file for the struct called systemUser.txt it has 4 users...
I
wrote this code but there’s an issue with it :
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
class Borrower {
private:
string ID, name;
public:
Borrower() :ID("0"), name("no name yet") {}
void setID(string nID);
void setName(string nID);
string getID();
string getName();
};
void Borrower::setID(string nID) {
ID = nID;
}
void Borrower::setName(string nname) {
name = nname;
}
string Borrower::getID() {
return ID;
}
string Borrower::getName() {
return name;
}
class Book {
private:
string...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...
I am trying to run this program in Visual Studio 2017. I keep getting this build error: error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". 1>Done building project "ConsoleApplication2.vcxproj" -- FAILED. #include <iostream> #include<cstdlib> #include<fstream> #include<string> using namespace std; void showChoices() { cout << "\nMAIN MENU" << endl; cout << "1: Addition...
I have written my code for an employee management system that stores Employee class objects into a vector, I am getting no errors until I try and compile, I am getting the error: C2679 binary '==': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion). But I am not sure why any help would be great, Thank you! 1 2 3 4 5 6 7 8 9 10 11 12 13...
C++ language I am having some trouble with user validation, can someone look at my code and tell me what I am doing wrong: char firstInital, lastInitial; int userAge; std::cout << "Program 1-2: Get user initials and age in days\n "; std::cout << "-------------------------------------------------------------------------\n"; std::cout << "Please enter the first letter of your first name: \n " << flush; std::cin >> firstInital; std::cout << "Please enter the first letter of your last name: \n...