Question: EXPERT CREATE A COMPUTER FLOW DIAGRAM FOR MY CODE #include #include using namespace std; const int MAX _ BOOKS = 1 0 0 ; struct

EXPERT CREATE A COMPUTER FLOW DIAGRAM FOR MY CODE
#include
#include
using namespace std;
const int MAX_BOOKS =100;
struct Book {
string title;
string author;
bool isBorrowed;
};
void addBook(Book books[], int &count);
void viewBooks(const Book books[], int count);
void borrowBook(Book books[], int count);
void returnBook(Book books[], int count);
int main(){
Book books[MAX_BOOKS];
int count =0;
int choice;
do {
cout << "Library Management System
";
cout <<"1. Add Book
";
cout <<"2. View Books
";
cout <<"3. Borrow Book
";
cout <<"4. Return Book
";
cout <<"5. Exit
";
cout << "Choose an option: ";
cin >> choice;
switch (choice){
case 1: addBook(books, count); break;
case 2: viewBooks(books, count); break;
case 3: borrowBook(books, count); break;
case 4: returnBook(books, count); break;
case 5: cout << "Exiting...
"; break;
default: cout << "Invalid option!
"; break;
}
} while (choice !=5);
return 0;
}
void addBook(Book books[], int &count){
if (count < MAX_BOOKS){
cout << "Enter book title: ";
cin.ignore();
getline(cin, books[count].title);
cout << "Enter author name: ";
getline(cin, books[count].author);
books[count].isBorrowed = false;
count++;
} else {
cout << "Library is full!
";
}
}
void viewBooks(const Book books[], int count){
for (int i =0; i < count; i++){
cout << i +1<<"."<< books[i].title <<" by "<< books[i].author;
if (books[i].isBorrowed){
cout <<"(Borrowed)";
}
cout << endl;
}
}
void borrowBook(Book books[], int count){
int index;
viewBooks(books, count);
cout << "Select book number to borrow: ";
cin >> index;
if (index >0 && index <= count && !books[index -1].isBorrowed){
books[index -1].isBorrowed = true;
cout << "You borrowed \""<< books[index -1].title <<"\".
";
} else {
cout << "Invalid selection or book already borrowed!
";
}
}
void returnBook(Book books[], int count){
int index;
viewBooks(books, count);
cout << "Select book number to return: ";
cin >> index;
if (index >0 && index <= count && books[index -1].isBorrowed){
books[index -1].isBorrowed = false;
cout << "You returned \""<< books[index -1].title <<"\".
";
} else {
cout << "Invalid selection or book not borrowed!
";
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!