Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c++ General Notes (Important): 1. In this assignment, you are given part of the implementation as a help 1.1. Feel free to use it
in c++
General Notes (Important): 1. In this assignment, you are given part of the implementation as a help 1.1. Feel free to use it 1.2. It is not complete, for example it does not implement any validation 1.3. You will need to address any requirements that are not implemented yourself 2. This is an individual assignment. 2.1. You are not allowed to work in groups 2.2. make sure you do not share you code with any other student 2.3. It does not matter if you give your code to other students or they get it without your permission! In both cases that would be considered as cheating. 2.4. Cheating is strictly prohibited and will cost you severely, possibly the whole course or even the semester 3. You should submit your work via e-learning as one zip/tar file that has 3.1. header files * h: for class interface (one for each class) 3.2. source files *.cpp : for class implementation (one for each class) 3.3. main.cpp : main program (only one) 3.4. guard your header files against multiple inclusions 4. Use the this pointer in all of your setter functions 5. Read and abide the Coding conventions in the last page 6. The member functions that do not modify data members should be declared and defined as const QUESTION 1(10 pts): Implement the class Price that represents prices in the Jordanian currency (dinars and piasters). The class should have: 1. data members to represent a. dinars (int), amount of dinars, must be >=0 b. piasters (int), amount of piasters, must be in the range 0 to 99 inclusive 2. A parametrized constructor Price (with appropriate validation) 3. Appropriate setters for all data members (with appropriate validation, force user to input correct values) 4. Getters for all data members 5. void printPrice, a member function to print the price in JD and piasters Submit two files for this part, price.h (for the class interface) and price.cpp (for the class implementation) QUESTION 2 (15 pts): Implement class Book that represents a book with the following: 1. Attributes a. book_title (string), b. book_author (string), c. book_count (int), to represent the available number of copies of the book d. book_price (Price). 2. A parameterized constructor to set all Book data members 3. setters for all data members 4. getters for all data members 5. void modifyBookCount(int n), modify current value of book_count by the amount n (n can be positive or negative). 6. void printBook(), a member function to print the book information (title, author, and price). Submit two files for this part, book.h (for the class interface) and book.cpp (for the class implementation) QUESTION 3 (50 pts): Implement class Bookshop that represents a shop that sells books. This class should have: 1. the following attributes: max_num_titles (int), to represent the maximum number titles, (must be positive integr) Book * booksptr, A pointer of type Book, will be used to create a dynamic array of type Book current (int), that represents number of current book titles in the bookshop, (must be >=0) 2. The class should have a default constructor set max_num_titles to 10, and current to 0 create a dynamic array of type Book and size max_num_titles, and make booksPtr point to it 3. A parameterized constructor that will receive arguments for all the data members initialize all the data members, with appropriate validation. 4. Create a dynamic array of type Book and size max_num_titles, and make booksPtr point to it. 5. Library(): Deallocates the dynamic array of Bookshop. 6. isEmpty(), a boolean function that returns true if current==0. and false otherwise. 7. isFull(), a boolean function that returns true if current==max_num_titles, and false otherwise. 8. int findTitle(string title) returns the index of the book with that title if found in booksPtr array, otherwise returns -1. HINT: you can use string compare function from the string library. 9. void addBook (const Book & b): this function does the following: add book b into the end of list booksPtr, if the Bookshop is not full and book title does not already exist in the list. If the title of book b is already in list, then increment the count available copies of this book by 1, and then print the updated number of copies. . If the title of the book b is not in list, but the list is full, then print a suitable message to say that the add book operation failed. 10. void adjustMaxNumTitles(int n), a member function to increase/resize the size of the dynamic array pointed to by booksPtr by the amount n without losing its original contents. The function must also update max_num_titles accordingly. Submit two files for this part, bookshop.h and bookshop.cpp QUESTION 4 (25 pts) (Submit one file for this: main.cpp): 1. void printBookTitles(const Bookshop &), as a global friend function of class Bookshop to print information about all book titles in the bookshop dynamic array, and the current number book titles. 2. In the main function, do the following: 2.1. define an array, booksArray, of type Book with size equal to SIZE 2.1.1. SIZE should be declared and initialized to 8 2.1.2. You must initialize booksArray with meaningful data using one of the following methods: from user, from a data file, or from an initialization list 2.2. Define the object bShop of type Bookshop such that it will have a dynamic array of size 10. That dynamic array would initially be empty (i.e., with no books). 2.3. Add the books from booksArray to the dynamic array of bShop, one by one using a loop and a proper function call. 2.4. Add the third book from booksArray to the dynamic array of bshop 2.5. Using a proper function call, resize the dynamic array of the object bShop by adding space for 5 more objects of type Book. 2.6. Search for the title of the 4th book of booksArray in bshop and display a useful message to show the search result. 2.7. Print the details of all bShop list of books CODING CONVENTIONS 1) Naming Conventions: Class names should start with a capital letter. All other letters should be small except for beginnings of words. Examples: BankAccount, Graduate Student, RightTriangle. Local variable names should be in small caps and words should be separated by underscores. Examples: bank_account, graduate student, right_triangle. Constants should be named with all caps and words should be separated with underscores. Examples: BANK ACCOUNT, GRADUATE STUDENT, RIGHT_TRIANGLE. Meaningful names should always be used. Avoid names such as a, b, c, etc. 2) Comments: Each class and function should be preceded by a comment that explains what the class is and any other necessary important related to its usage. Data members should be explained with comments preceding them only if not all information is clear directly from the name. Any line/part of the code that is complex or is difficult to understand should be explained with appropriate comments preceding it. Explaining obvious lines of code with comments should be avoided
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