Question: Base on C++ inplement new class to control User I/O Array.cc #include #include using namespace std; #include Book.h #include Array.h Array::Array(){ size=0; Book *elements[MAX_ARR_SIZE]={}; }

Base on C++ inplement new class to control User I/O

Base on C++ inplement new class to control User I/O Array.cc #include

Array.cc

#include #include using namespace std; #include "Book.h" #include "Array.h"

Array::Array(){ size=0; Book *elements[MAX_ARR_SIZE]={}; } void Array::add(Book *book){ elements[size]=&book; ++size; } void Array::print(){ for(int i=0;iprint(); } }

Array.h

#ifndef ARRAY_H #define ARRAY_H #define MAX_ARR_SIZE 128 using namespace std;

class Array{ public: Array(); void add(Book*); void print(); private: Book *elements[MAX_ARR_SIZE]; int size;

};

#endif

Book.cc

#include #include using namespace std;

#include "Book.h"

Book::Book(int i, string t, string a, int y) { id = i; title = t; author = a; year = y; }

void Book::print() { cout year; }

Book.h

#ifndef BOOK_H #define BOOK_H

#include using namespace std;

class Book { public: Book(int=0, string="Unknown", string="Unknown", int=0); void setBook(int, string, string, int); void print();

private: int id; string title; string author; int year; };

#endif

Library.cc

#include #include using namespace std; #include "Book.h" #include "Library.h" #include "Array.h"

Library::Library(){ } void Library::addBook(Book *book){ Arr.add(book); } void Library::print(){ cout

Library.h

#ifndef LIBRARY_H #define LIBRARY_H using namespace std; #include "Array.h"

class Library{ public: void addBook(Book*); void print(); Library(); private: Array Arr;

};

#endif

main.cc

#include using namespace std; #include #include "Book.h" #include "Library.h"

int mainMenu();

int main() { int numBooks = 0; string title, author; int id, year; int menuSelection; Library library=Library(); Book bookputin; while (1) { menuSelection = mainMenu();

if (menuSelection == 0) break; else if (menuSelection == 1) { cout > id; cout > year; bookyear=&Book(id,title,author,year); int i=0; while(ilessthan(bookyear[i+1])==false){ oldbookadd=bookyear[i]; bookyear[i]=bookyear[i+1]; bookyear[i+1]=oldbookadd; } i++; } library.addBook(bookputin); ++numBooks; } }

if (numBooks > 0) library.print();

return 0; }

int mainMenu() { int numOptions = 1; int selection = -1;

cout

while (selection numOptions) { cout > selection; }

return selection; }

Makefile

OPT = -Wall

t03: main.o Book.o Library.o Array.o

g++ $(OPT) -o t03 main.o Book.o Library.o Array.o

main.o: main.cc Book.h Library.h

g++ $(OPT) -c main.cc

Book.o: Book.cc Book.h

g++ $(OPT) -c Book.cc

Library.o: Library.cc Library.h Book.h Array.h

g++ $(OPT) -c Library.cc

Array.o:Array.cc Array.h Book.h

g++ $(OPT) -c Array.cc

clean:

rm -f *.o t03

5. Create a new Control class in the program to implement the control flow from the main() function. The Control class will contain: a data member for the Library object that used to be declared in main() .a data member for a new View object that will be responsible for user I/O .a launch() member function that implements the program control flow and does the following: use the view object to display the main menu and read the user's selection, until the user chooses to exit if required by the user, create a new Book object and add it to the library using existing functions use the view object to print the content of the library to the screen at the end of the program o o The control class will perform all user I/O using the view class. It will not interact with the user directly

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 Databases Questions!