Can anyone help me to make a new menu to delete all the books that have been entered? And how to make the title, name, and language can be entered with space? I've searched other questions about it, many of them using getline. But i don't understand how to use it on class like this.
(Sorry my grammar is bad, i'm not very good in English)
This is the source code that i've been made.
#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
class Book {
int number, year;
string language, name, title;
Book * head, * next;
public:
Book (string & name, string & title, int number, string & language, int year) {
head = NULL;
this -> name = name;
this -> title = title;
this -> language = language;
this -> number = number;
this -> year = year;
};
~ Book (void) {
delete head;
};
void display (void);
void add (void);
void dellete (string&);
};
void Book :: add (void) {
string name, title, language;
int year, number;
cout << endl << "Author:", cin >> name;
cout << "Title:", cin >> title;
cout << "Number of books:", cin >> number;
cout << "Language:", cin >> language;
cout << "Year of publication:", cin >> year;
Book * p = new Book (name, title, number, language, year);
p -> next = head;
head = p;
}
void Book :: display (void) {
Book * p = head;
while (p) {
cout << "----------------------------- \n";
cout << "Author:" << p -> name << endl;
cout << "Title:" << p -> title << endl;
cout << "Number of books:" << p -> number << endl;
cout << "Language:" << p -> language << endl;
cout << "Year of publication:" << p -> year << endl;
cout << endl;
p = p -> next;
}
}
int main (int argc, char const ** argv) {
string blank = "";
Book * B = new Book (blank, blank, false, blank, 0);
int opt;
cout << "\nBOOK STACKS \n";
for (;;) {
cout << "1) Add a book.\n";
cout << "2) Show all books.\n";
cout << "3) Exit. \n\n";
cout << "Options:", cin >> opt;
switch (opt) {
case 1:
B -> add ();
break;
case 2:
B -> display ();
break;
case 3:
exit (0);
default:
continue;
}
}
return 0;
}
Please help me to get the code because it's my mid-test task and i'm still a beginner at programming. Thanks.