1. Refactor your bookType ADT that you created in Module 1B. You will need to update the implementation of your ADT by: Making the authors attribute a dynamic array and ensuring any affected code is updated to handle the new type. Adding a destructor 2. Be sure to avoid multiple inclusion of your header file (.h file) by adding the appropriate preprocessor commands in the header file itself. Example: #ifndef H_test #define H_test //Your interface file code goes here #endif moudule 1B code #include #include using namespace std; class bookType { private: string title; string authors[4]; string publisher; string ISBN; double price; int numCopies; int numAuthors; public: // constructors bookType() { title = ""; authors[0] = ""; authors[1] = ""; authors[2] = ""; authors[3] = ""; publisher = ""; ISBN = ""; price = 0.0; numCopies = 0; numAuthors = 0; } bookType(string t, string a[], int na, string p, string i, double pr, int nc) { title = t; numAuthors = na; for (int j = 0; j < na; j++) authors[j] = a[j]; publisher = p; ISBN = i; price = pr; numCopies = nc; } // accessors string getTitle() { return title; } string getAuthor(int index) { return authors[index]; } string getPublisher() { return publisher; } string getISBN() { return ISBN; } double getPrice() { return price; } int getNumCopies() { return numCopies; } int getNumAuthors() { return numAuthors; } // mutators void setTitle(string t) { title = t; } void setAuthor(int index, string a) { authors[index] = a; } void setPublisher(string p) { publisher = p; } void setISBN(string i) { ISBN = i; } void setPrice(double pr) { price = pr; } void setNumCopies(int nc) { numCopies = nc; } void setNumAuthors(int na) { numAuthors = na; } // other functions bool isTitle(string t) { return (title == t); } bool isISBN(string i) { return (ISBN == i); } void updateNumCopies(int n) { numCopies += n; } void printInfo() { cout << "Title: " << title << endl; cout << "Authors: "; for (int j = 0; j < numAuthors; j++) cout << authors[j] << ", "; cout << endl; cout << "Publisher: " << publisher << endl; cout << "ISBN: " << ISBN << endl; cout << "Price: $" << price << endl; cout << "Number of Copies: " << numCopies << endl; } ~bookType() { // destructor } }; #ifndef H_BOOKTYPE #define H_BOOKTYPE #endif
1. Refactor your bookType ADT that you created in Module 1B. You will need to update the implementation of your ADT by:
- Making the authors attribute a dynamic array and ensuring any affected code is updated to handle the new type.
- Adding a destructor
2. Be sure to avoid multiple inclusion of your header file (.h file) by adding the appropriate preprocessor commands in the header file itself. Example:
#ifndef H_test
#define H_test
//Your interface file code goes here
#endif
moudule 1B code
#include <iostream>
#include <string>
using namespace std;
class bookType {
private:
string title;
string authors[4];
string publisher;
string ISBN;
double price;
int numCopies;
int numAuthors;
public:
// constructors
bookType() {
title = "";
authors[0] = "";
authors[1] = "";
authors[2] = "";
authors[3] = "";
publisher = "";
ISBN = "";
price = 0.0;
numCopies = 0;
numAuthors = 0;
}
bookType(string t, string a[], int na, string p, string i, double pr, int nc) {
title = t;
numAuthors = na;
for (int j = 0; j < na; j++)
authors[j] = a[j];
publisher = p;
ISBN = i;
price = pr;
numCopies = nc;
}
// accessors
string getTitle() {
return title;
}
string getAuthor(int index) {
return authors[index];
}
string getPublisher() {
return publisher;
}
string getISBN() {
return ISBN;
}
double getPrice() {
return price;
}
int getNumCopies() {
return numCopies;
}
int getNumAuthors() {
return numAuthors;
}
// mutators
void setTitle(string t) {
title = t;
}
void setAuthor(int index, string a) {
authors[index] = a;
}
void setPublisher(string p) {
publisher = p;
}
void setISBN(string i) {
ISBN = i;
}
void setPrice(double pr) {
price = pr;
}
void setNumCopies(int nc) {
numCopies = nc;
}
void setNumAuthors(int na) {
numAuthors = na;
}
// other functions
bool isTitle(string t) {
return (title == t);
}
bool isISBN(string i) {
return (ISBN == i);
}
void updateNumCopies(int n) {
numCopies += n;
}
void printInfo() {
cout << "Title: " << title << endl;
cout << "Authors: ";
for (int j = 0; j < numAuthors; j++)
cout << authors[j] << ", ";
cout << endl;
cout << "Publisher: " << publisher << endl;
cout << "ISBN: " << ISBN << endl;
cout << "Price: $" << price << endl;
cout << "Number of Copies: " << numCopies << endl;
}
~bookType() {
// destructor
}
};
#ifndef H_BOOKTYPE
#define H_BOOKTYPE
#endif
Step by step
Solved in 2 steps