I am writing code for a library management system. Under "case 1" I need to assign the letter "A" to a book after the user has inputted the book name. How do I do this?
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main() {
const int SIZE = 20;
string nameOfBook[SIZE];
char status[SIZE];
string customerName[SIZE];
bool del[SIZE];
int choice;
char A, B;
for (int i=0; i<SIZE; i++)
del[i] = true;
ifstream in;
in.open("library.txt");
if (in) {
int i=0;
while (!in.eof()) {
if (in.eof()) break;
in >> nameOfBook[i];
in >> status[i];
in >> customerName[i];
del[i] = false;
i++;
}
in.close();
}
do {
cout << "\t\tMain Menu\n\n";
cout << "1) Add a book\n\n";
cout << "2) Borrow a book\n\n";
cout << "3) Return a book\n\n";
cout << "4) Search for a book\n\n";
cout << "5) Exit\n\n";
cout << "Choice (1,2,3,4,5): ";
cin >> choice;
switch (choice) {
case 1: {
cout << "Add a book: \n";
int i;
for (i=0; i<SIZE; i++)
if (del[i]) break;
if (i == SIZE) {
cout << "Cannot add more books\n";
continue;
}
cout << "Enter book name: ";
getline(cin, nameOfBook[i]);
cin.ignore(100, '\n');
cout << status << endl;
del[i] = false;
break;
}
I need to assign the letter "A" to a book after the user has inputted the book name.
Could you please clarify?
Do you mean: after having inserted user input inside nameOfBook[i], let’s say “Moby-Dick”...
1) ...I need it to become “A Moby-Dick”
or
2) ...I need to insert ‘A’ into status[i]?