Question
Hello I need help with these questions. I am still a beginner with the c++ language and im having problems trying to understand what to
Hello I need help with these questions. I am still a beginner with the c++ language and im having problems trying to understand what to do here. IF you can include comments for what you did and how that would be appreciated! Will upvote thank you.
Book.h
#ifndef BOOK_H #define BOOK_H
#include
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
~
Book.cc
#include
#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; }
main.cc
#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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started