Assignment Document

Class and Data Abstraction

Pages:

Preview:


  • "Programming Assignment.Class and Data Abstraction Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year ofpublication. Design a class bookType that defines the book as an ADT. 1. Each object of the class bo..

Preview Container:


  • "Programming Assignment.Class and Data Abstraction Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year ofpublication. Design a class bookType that defines the book as an ADT. 1. Each object of the class bookType can hold the following information about a book: title,up to four authors, publisher, ISBN, price, and number of copies in stock. To keep trackof the number of authors, add another data member.2. Include the member functions to perform the various operations on objects of the typebookType. For example, the usual operations that can be performed on the title are toshow the title, and check whether a title is the same as the actual title of the book.Similarly, the typical operations that can be performed on the number of copies in stockare to show the number of copies in stock, set the number of copies in stock, update thenumber of copies in stock, and return the number of copies in stock. Add similaroperations for the publisher, ISBN, book price, and author. Add the appropriateconstructors and a destructor ( if one is needed).3. Write the definitions of the member functions of the class bookType.Write a program that uses the class bookType and test the various operations on theobjects of class bookType. Declare an array of 100 components of the type bookType. Set to5 components. Display the output. Solution.book.cpp// book.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include <iostream>#include <string>#include <iomanip>using namespace std;classbookType { private: string title; string authors[4]; int n_authors; string ISBN; string publisher; int year; double price; int copies; public: bookType(); ~bookType(); voidset_title(string str); stringget_title(); voidclear_authors(); voidadd_author(string str); stringget_author(int number); voidset_ISBN(string str); stringget_ISBN(); voidset_publisher(string str); stringget_publisher(); voidset_year(int n); intget_year(); voidset_price(double n); doubleget_price(); voidset_copies(int n); intget_copies(); voidupdate_copies(int n); voidshow_title(); voidshow_copies(); voidshow_ISBN(); voidshow_publisher(); voidshow_price(); voidshow_authors(); voidshow_year();intcompare_title(string str);};bookType::bookType() { title = ""; authors[0] = ""; authors[1] = ""; authors[2] = ""; authors[3] = ""; n_authors = 0; ISBN = ""; publisher = ""; year = 0; price = 0; copies = 0;}bookType::~bookType() {}voidbookType::set_title(string str) { title = str;}stringbookType::get_title() { return title;}voidbookType::clear_authors() { n_authors = 0;}voidbookType::add_author(string str) { if (n_authors< 4) {authors[n_authors] = str;n_authors++; }}stringbookType::get_author(int number) { if (n_authors< number){return authors[number - 1]; } Else{return ""; } }voidbookType::set_ISBN(string str) { ISBN = str;}stringbookType::get_ISBN() { return ISBN;}voidbookType::set_publisher(string str) { publisher = str;}stringbookType::get_publisher() { return publisher;}voidbookType::set_year(int n) { year = n;}intbookType::get_year() { return year;}voidbookType::set_copies(int n) { if (n >= 0) copies = n;}intbookType::get_copies() {return copies;}voidbookType::set_price(double n) { if (n >= 0) price = n;}doublebookType::get_price() { return price;}voidbookType::update_copies(int n) { if (n >= 0) copies += n;}voidbookType::show_title() { cout<< "Title:" << title <<endl;}voidbookType::show_copies() { cout<< "Copies in stock:" << copies<<endl;}voidbookType::show_ISBN() { cout<< "ISBN:" << ISBN <<endl;}voidbookType::show_publisher() { cout<< "Publisher:" << publisher <<endl;}voidbookType::show_price() { cout<< "Price:"<<setprecision(2)<< fixed<< price<<endl;} voidbookType::show_year() { cout<< "Year of publish:" << year<<endl;}voidbookType::show_authors() {int i = 0; cout<< "Author(s):" <<n_authors<<endl; for(i = 0;i <n_authors; i++) {cout<< authors[i] << " "; } cout<<endl;}intbookType::compare_title(string str) { int x = (str == title); return x;}voidmain(){bookType a[100]; int i; for(i = 0; i < 5; i++){a[i].add_author("Newton");a[i].add_author("Kepler");a[i].set_copies(100-i);a[i].set_ISBN("123-123-123");a[i].set_price(100.01+i*i);a[i].set_publisher("Piter");a[i].set_title("Star moving");a[i].set_year(1660+i); } "

Related Documents

Start searching more documents, lectures and notes - A complete study guide!
More than 25,19,89,788+ documents are uploaded!

Why US?

Because we aim to spread high-quality education or digital products, thus our services are used worldwide.
Few Reasons to Build Trust with Students.

128+

Countries

24x7

Hours of Working

89.2 %

Customer Retention

9521+

Experts Team

7+

Years of Business

9,67,789 +

Solved Problems

Search Solved Classroom Assignments & Textbook Solutions

A huge collection of quality study resources. More than 18,98,789 solved problems, classroom assignments, textbooks solutions.

Scroll to Top