[Solved] SOLVED:Laboratory Exercise Week 8 solution

30 $

File Name: SOLVED:Laboratory_Exercise_Week_8_solution.zip
File Size: 395.64 KB

SKU: [Solved] SOLVED:Laboratory Exercise Week 8 solution Category: Tag:

Or Upload Your Assignment Here:


Task One: DebuggingVirtual.cpp and Throw.cpp contain various errors; syntax, logical and/or with respect to the sample output.Fix the bugs so the programs can be compiled and run correctly producing the following output**************************A x: 4A x: 6B y: 5**************************SixSevenThreeFour Five**************************Task Two: A leaky programThe program Leaky.cpp has memory leaks. Find them and fix them. Remember you can use bcheck to check for memory leaks.Task Three: ExceptionsWrite code in a file Book.cpp that contains a Book class with fields for a book identification number, title, authors, number of pages and price. The book title and author should be stored as character pointers, and the constructor should allocate 80 characters of new memory for each. You should include appropriate insertion and extraction operators for the Book. Remember to define destructor for the class Book.Create a BookException class inherits runtime_error in the file Book.cpp that holds a Book and an error message. When a Book is being created, two exceptions are to be looked for based on the following rules:1. The number of pages should be divisible by four.2. The price should be between $5.00 and $250.00 inclusive.If one of these conditions is not met, you should create and throw an appropriateBookException object. Override what() function in the class BookException to return exception message.Write a main() function in the file Book.cpp which creates an array of two Book objects. If a BookException object is thrown during the data entry of a Book, the user should be required to enter data for a new Book to replace the invalid Book. Thus you keep on entering Book details until you have two valid books. Then display those two books.

Testing task Three:Compile your program by CC –o task3 Book.cppYour program outputs may look like following (Red data means inputs from keyboard). Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1027The no. 1 book error.Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1027Price: 0.00Incorrect number of pages.Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1028Price: 1128.3The no. 1 book error.Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1028Price: 1128.30Incorrect price.Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1028Price: 112.83Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 882The no. 2 book error.Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 882Price: 0.00Incorrect number of pages.Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 884Price: 1.235The no. 2 book error.Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 884Price: 1.24Incorrect price.Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 884Price: 123.5Two books are:Id number: 1Title: How to program C++Authors: Paul Deitel, Harvey DeitelNumber of pages: 1028Price: 112.83Id number: 2Title: A structure programming approach using C++Authors: Behrouz A. Forouzan, Richard F. GilbergNumber of pages: 884Price: 123.50You can use the input data file input_books.txt to test your program:

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] SOLVED:Laboratory Exercise Week 8 solution
30 $