Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the minimum assignment and the optional section. Ignore the discussion board section. Below is also some code to get started. #include #include using namespace

Complete the minimum assignment and the optional section. Ignore the discussion board section. Below is also some code to get started.

image text in transcribed

  1. #include

  2. #include

  3. using namespace std;

  4. // class Book

  5. // with three private data fields: book title, author, copyright, and price

  6. // four public methods to retrieve fields (called "getters")

  7. // and one public non-default constructor

  8. class Book {

  9. public:

  10. // member function prototypes

  11. void assign (string, string, int, float); // this is your constructor

  12. string getTitle();

  13. string getAuthor();

  14. int getCopyRightYear();

  15. float getPrice();

  16. private:

  17. // data members

  18. string title;

  19. string author;

  20. int copyRightYear;

  21. float price;

  22. };

  23. // these are the actual member functions

  24. // this member function is a "constructor" that will create a new book

  25. void Book::assign (string bookTitle, string bookAuthor, int bookDate, float bookPrice) {

  26. title = bookTitle;

  27. author = bookAuthor;

  28. copyRightYear = bookDate;

  29. price = bookPrice;

  30. }

  31. // this member function is a "getter" that will retrieve that book title value

  32. string Book::getTitle() {

  33. return title;

  34. }

  35. // this member function is a "getter" that will retrieve the primary book author value

  36. string Book::getAuthor() {

  37. return author;

  38. }

  39. // this member function is a "getter" that will retrieve the year the book was copyrighted

  40. int Book::getCopyRightYear() {

  41. return copyRightYear;

  42. }

  43. // this member function is a "getter" that will retrieve the list price of the book

  44. float Book::getPrice() {

  45. return price;

  46. }

  47. int main()

  48. {

  49. cout

  50. // Set up space to create 5 instances of the class Book to use with our constructor

  51. Book b1, b2, b3, b4, b5;

  52. // Use our constructor to create the first book, replace my book below with info on your favorite book, use b1

  53. b1.assign ("C++ for Dummies", "Stephen R Davis", 1998, 29.99);

  54. cout

  55. cout

  56. cout

  57. // Use the constructor again to create another book, again, replacing my book below with one your favorite books, use b2

  58. b2.assign ("C++ - The Complete Reference", "Herbert Schildt", 2003, 52.99);

  59. cout

  60. cout

  61. cout

  62. // use constructor (its called assign) again to create and then print information about book 3, another favorite book of yours ... remember to use b3

  63. // use constructor again to create and then print information about book 4, your fourth favorite book ... remember to use b4

  64. // use constructor again to create and then print information about book 5, your fifth favorite book ... remember to use b5

  65. return (0);

  66. }

Assignment 3 - Using C++ Constructors Like last week's assignment, decide whether to do the minimal assignment or the challenge assignment. You only need to submit one of them for grading, you do not need to hand in both. Of course, stepping up to the challenge allows you to get the most possible points. DO copy and use my template to get started, and make sure you also share your book information in the appropriate week 4 discussion link I've created just for this week. When using IDEOne, make sure the language you select is C+t (any version will work). You can also reference the IDEOne link in the template and click the "fork" link to quickly create your own template to begin. Note: A code template in C++that follows this lecture note will give you all the code and tips you will need to successfully complete this assignment. No worries! Minimum Assignment (80 points) In lecture notes this week, we covered a simple class that described books, and used the constructors in it to create two instances of the book class that used C+Textbooks. Your task this week is to replace the two books I created about C++ with books that are favorites of yours. Additionally I would like you to add three more books for a total of 5 books. If you get stuck and/or don't have personal favorites, just go to Amazon.com (http://www.amazon.com ) Barnes and Nobel you, or maybe even the last 5 you had read.. even if its just a list of textbooks. The minimum information we need to collect about each book is the title, author, copyright year, and price ), or other book web sites and pick 5 books that would interest The point of this assignment is to get you familiar with a Class in C++ and in particular, how to use constructors to create new instances of an object of a class, in this case, a book. All the code is essentially provided for you. you just need to add the information about each of your five books and get it outputted... just like I did for the two books in the lecture notes this week. Important: Please use 5 of your own books.. don't use my two books below and just add three books. I don't want to see C++for Dummies or Ct+ The Complete Reference as two of your books, if you do, it will be a 10 point deduction! Submitting this Assignment I need you to do two things here to get full credit for the minimum assignment (80 points). 1) Submit the IDEOne link for your working program to this Assignment 3 link (so I can grade it) 2) Share the output of your IDEOne C++ program showing the 5 books you selected by posting it to the Week 4 Discussion Board link (see example at the end of this page). Optional Challenge - (up to 100 points) See if you can add two other attributes about a book, an example would be: number of pages. You would need to add them as new data members in the private section within the class and create a "getter" function for each of them Then you will need to add both of them to the constructor function called "assign" as well. Finally, you'll need to pass that information of these two attributes when you call the constructor "assign" in the main function for each of your 5 books. This is really just an extension of the code below Like the minimal assignment, you will need to do two things 1) Submit this assignment for grading (but add and print at least two new additional attributes in your program) 2) Share your 5 books on the Class Discussion Board link to get full credit (up to 100 points) Sample Output to Post to Discussion Board As part of this week's homework assignment, you will need to post the output of your C++ program to the Class Discussion Board. You would find a discussion board thread titled: "Week 4- Share your list of 5 Favorite Books" Simply click on this link and then click the "Create Thread" button to add your five favorite books. When doing this please do the following to keep it in a consistent format

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

Define self-esteem and discuss its impact on your life.

Answered: 1 week ago