Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE CODE IN C++ AND ALL THE FILES ARE FROM BASE CODE. Book.cc #include #include using namespace std; #include Book.h Book::Book(int i, string t, string

image text in transcribed

PLEASE CODE IN C++ AND ALL THE FILES ARE FROM BASE CODE.

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::setBook(int i, string t, string a, int y) { id = i; title = t; author = a; year = y; }

void Book::print() { cout

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

in.txt

1 101 Ender's Game Card, Orson Scott 1985 1 102 Dune Herbert, Frank 1965 1 110 Foundation Asimov, Isaac 1951 1 111 Hitch Hiker's Guide to the Galaxy Adams, Douglas 1979 1 112 1984 Orwell, George 1949 1 113 Stranger in a Strange Land Heinlein, Robert A. 1961 1 114 Farenheit 451 Bradbury, Ray 1954 1 115 2001: A Space Odyssey Clarke, Arthur C. 1968 1 116 I, Robot Asimov, Isaac 1950 1 117 Starship Troopers Heinlein, Robert A. 1959 1 118 Do Androids Dream of Electric Sheep? Dick, Philip K. 1968 1 119 Neuromancer Gibson, William 1984 1 120 Ringworld Niven, Larry 1970 1 121 Rendezvous with Rama Clarke, Arthur C. 1973 1 122 Hyperion Simmons, Dan 1989 0

Main.cc

#include using namespace std; #include

#include "Book.h"

#define MAX_ARR_SIZE 128

int mainMenu(); void printLibrary(Book arr[MAX_ARR_SIZE], int num);

int main() { Book library[MAX_ARR_SIZE]; int numBooks = 0; string title, author; int id, year; int menuSelection;

while (1) { menuSelection = mainMenu();

if (menuSelection == 0) break; else if (menuSelection == 1) { cout > id; cout > year;

library[numBooks].setBook(id, title, author, year); ++numBooks; } }

if (numBooks > 0) printLibrary(library, numBooks);

return 0; }

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

cout

while (selection numOptions) { cout > selection; }

return selection; }

void printLibrary(Book arr[MAX_ARR_SIZE], int num) { cout

for (int i=0; i

cout

Makefile

OPT = -Wall

t01: main.o Book.o g++ $(OPT) -o t01 main.o Book.o

main.o: main.cc Book.h g++ $(OPT) -c main.cc

Book.o: Book.cc Book.h g++ $(OPT) -c Book.cc

clean: rm -f *.o t01

Learning Outcomes After this tutorial, you will be able to design a program using control, view, and entity objects create a UML class diagram to document your design Instructions 1. You will begin with the code you saved from previous tutorials, or with the base code 2. Using paper and pencil, draw a UML class diagram of the existing code, as we covered in section 3.4 of the course material. Remember, functions are not the same as classes, so main) is not a class! Now add to your diagram a Control class that will be responsible for all control flow, specifically the work that's done in main). Now add a view class to deal with user VO. Think about what functions will be required in each class. You will keep adding to your UML diagram as you modify the code in each of the steps below 3. Create a new view class that is responsible for interacting with the user. The view class will contain: .a member function for displaying the main menu and reading the user's selection . a member function for reading all information from the user about one book .a member function for printing out the libray; this function will take the library as a parameter, and it will use delegation, as seen in Tutorial #3, to ask the Library class to print to the screen Except for printing the library at the end of the program, only the view class will interact with the user You must change the program so that user I/O goes through this class. After the Control and view classes are correctly implemented, your code should have no global functions other than ain) 4. Change the nain function so that its only responsibility is to declare a control object and call its launch) function. 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 VO a launch member function that implements the program control flow and does the following o 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 VO using the view class. It will not interact with the user directly. Learning Outcomes After this tutorial, you will be able to design a program using control, view, and entity objects create a UML class diagram to document your design Instructions 1. You will begin with the code you saved from previous tutorials, or with the base code 2. Using paper and pencil, draw a UML class diagram of the existing code, as we covered in section 3.4 of the course material. Remember, functions are not the same as classes, so main) is not a class! Now add to your diagram a Control class that will be responsible for all control flow, specifically the work that's done in main). Now add a view class to deal with user VO. Think about what functions will be required in each class. You will keep adding to your UML diagram as you modify the code in each of the steps below 3. Create a new view class that is responsible for interacting with the user. The view class will contain: .a member function for displaying the main menu and reading the user's selection . a member function for reading all information from the user about one book .a member function for printing out the libray; this function will take the library as a parameter, and it will use delegation, as seen in Tutorial #3, to ask the Library class to print to the screen Except for printing the library at the end of the program, only the view class will interact with the user You must change the program so that user I/O goes through this class. After the Control and view classes are correctly implemented, your code should have no global functions other than ain) 4. Change the nain function so that its only responsibility is to declare a control object and call its launch) function. 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 VO a launch member function that implements the program control flow and does the following o 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 VO using the view class. It will not interact with the user directly

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions

Question

How can Trip 7 prevent future supply chain uncertainties?

Answered: 1 week ago

Question

x = 1 ;while x Answered: 1 week ago

Answered: 1 week ago