1 answer

C++ Error after oveloading, please help? LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe...

Question:

c++ Error after oveloading, please help?

LAB #8- CLASSES REVISITED &&    Lab #8.5 …      Jayasinghe De Silva

Design and Implement a Program that will allow all aspects of the Class BookType to work properly as defined below:

class bookType

{

public:

   void setBookTitle(string s);

           //sets the bookTitle to s

   void setBookISBN(string ISBN);

           //sets the private member bookISBN to the parameter

   void setBookPrice(double cost);

           //sets the private member bookPrice to cost

   void setCopiesInStock(int noOfCopies);

           //sets the private member copiesInStock to noOfCopies

    void printInfo() const;

           //prints the bookTitle, bookISBN, the bookPrice and the       //copiesInStock

   string getBookISBN() const;

           //returns the bookISBN

    double getBookPrice() const;

           //returns the bookPrice

    int showQuantityInStock() const;

           //returns the quantity in stock

    void updateQuantity(int addBooks);

           // adds addBooks to the quantityInStock, so that the quantity //in stock now has it original

       // value plus the parameter sent to this function

private:

   string bookName;

   string bookISBN;

   double price;

   int quantity;

};

You MUST ALSO add TWO CONSTRUCTORS for the class above.

(1)    One is the DEFAULT CONSTRUCTOR

(2)    The other (#2) is a Constructor that takes four parameters and sets the INITIAL values for the bookName, bookISBN, price, and quantity parameters.

LAB # 8.5

ADD AN OPERATOR OVERLOADING >= TO COMPARE quantity (the private data member in the bookType Class.

#include <iostream>

#include <cstring>

using namespace std;

class bookType

{

private:

string bookName;

string bookISBN;

double price;

int quantity;

public:

bookType() {                       //Default const

cout << "Default Constructor Called" << endl;

}

//Four Parameter Const bellow

bookType(string bookName, string bookISBN, double price, int quantity) {

this -> bookName = bookName;

this -> bookISBN = bookISBN;

this -> price = price;

this -> quantity = quantity;

}

void setBookTitle(string s) {

bookName = s;

}

//sets the bookTitle to s

void setBookISBN(string ISBN) {

bookISBN = ISBN;

}

//sets the private member bookISBN to the parameter

void setBookPrice(double cost) {

this->price = cost;

}

//sets the private member bookPrice to cost

void setCopiesInStock(int noOfCopies) {

this->quantity = noOfCopies;

}

//sets the private member copiesInStock to noOfCopies

void printInfo() {

cout << "Book Name " << bookName << endl;

cout << "Book ISBN " << bookISBN << endl;

cout << "Price " << price << endl;

cout << "Quantity " << quantity << endl;

}

//prints the bookTitle, bookISBN, the bookPrice and the //copiesInStock

string getBookISBN() {

return this->bookISBN;

}

//returns the bookISBN

double getBookPrice() {

return price;

}

//returns the bookPrice

int showQuantityInStock() {

return quantity;

}

//returns the quantity in stock

void updateQuantity(int addBooks) {

quantity += addBooks;

}

// adds addBooks to the quantityInStock, so that the quantity //in stock now has it original

// value plus the parameter sent to this function

string operator <(const bookType& bk) {

if(quantity < bk.quantity) return "Second Object quanity is greater than first one";

else if(bk.quantity < quantity) return "First Object quantity is greater than second one";

else return "Both quantity are equal";

}

// Comparison operator overloading

};

87 88 Comparison operator overloading 89 itors are website. く 90 001. BON input Compilation failed due to following error(s) main.cpp:86:1: error: expected at end of input main.cpp:86:1: error: expected unqualified-id at end of input

87 88 Comparison operator overloading 89 itors are website. く 90 001. BON input Compilation failed due to following error(s) main.cpp:86:1: error: expected ' at end of input main.cpp:86:1: error: expected unqualified-id at end of input

Answers

Code:

#include <iostream>

#include <cstring>

using namespace std;

class bookType

{

private:

string bookName;

string bookISBN;

double price;

int quantity;

public:

bookType()

{ //Default const

cout << "Default Constructor Called" << endl;

}

//Four Parameter Const bellow

bookType(string bookName, string bookISBN, double price, int quantity)

{

this -> bookName = bookName;

this -> bookISBN = bookISBN;

this -> price = price;

this -> quantity = quantity;

}

void setBookTitle(string s)

{

bookName = s;

}

//sets the bookTitle to s

void setBookISBN(string ISBN) {

bookISBN = ISBN;

}

//sets the private member bookISBN to the parameter

void setBookPrice(double cost) {

this->price = cost;

}

//sets the private member bookPrice to cost

void setCopiesInStock(int noOfCopies) {

this->quantity = noOfCopies;

}

//sets the private member copiesInStock to noOfCopies

void printInfo() {

cout << "Book Name " << bookName << endl;

cout << "Book ISBN " << bookISBN << endl;

cout << "Price " << price << endl;

cout << "Quantity " << quantity << endl;

}

//prints the bookTitle, bookISBN, the bookPrice and the //copiesInStock

string getBookISBN() {

return this->bookISBN;

}

//returns the bookISBN

double getBookPrice() {

return price;

}

//returns the bookPrice

int showQuantityInStock() {

return quantity;

}

//returns the quantity in stock

void updateQuantity(int addBooks) {

quantity += addBooks;

}

// adds addBooks to the quantityInStock, so that the quantity //in stock now has it original

// value plus the parameter sent to this function

int operator >=(const bookType& bk) {

if(quantity >= bk.quantity) return 1;

else if(bk.quantity >= quantity) return -1;

else return 0;

}

// Comparison operator overloading

//integer can be returned to the main function

};

int main()

{

bookType b1; //default constructor

int result;

bookType b2("harry potter","jp123",250,5); //parameterized constructor

b1.setBookTitle("Half Girlfriend");

b1.setBookISBN("hg123");

b1.setBookPrice(280);

b1.setCopiesInStock(12);

cout<<endl;

cout<<"First book details:"<<endl;

b1.printInfo();

cout<<endl;

cout<<"Second book details:"<<endl;

cout<<"Book ISBN "<<b2.getBookISBN()<<endl;

cout<<"Price "<<b2.getBookPrice()<<endl;

cout<<"Quantity "<<b2.showQuantityInStock()<<endl;

b2.updateQuantity(10); //updating quantity of second book i.e. adding 10 more books

cout<<endl<<"After Updating Second Book....."<<endl<<endl;

b2.printInfo();

cout<<endl;

result=b1>=b2; //int result stores the value from the operator overloaded function

if(result>0) //result is checked and accordingly the statement is printed

{

cout<<"First Book Quantity is more";

}

else if(result<0)

{

cout<<"Second Book Quantity is more";

}

else

{

cout<<"Both Books have same Quantity";

}

return 0;

}

Output:

Default ConstructorCalled First book details: Book Name Half Girlfriend Book ISBN hg123 Price 280 uantity 12 Second book details: Book ISBN jp123 Price 250 uantity 5 Book Name harry potter Book ISBN jp123 Price 250 uantity 15 Second Book Quantity is more

.

Similar Solved Questions

1 answer
Lupo Corporation uses a job-order costing system with a single plantwide predetermined overhead rate based on...
Lupo Corporation uses a job-order costing system with a single plantwide predetermined overhead rate based on machine-hours. The company based its predetermined overhead rate for the current year on the following data: Total machine-hours Total fixed manufacturing overhead cost Variable manufacturin...
1 answer
Determine the odd primes p for which −26 is a square mod p
Determine the odd primes p for which −26 is a square mod p...
1 answer
Howeys candy company manufactures five different types of tasty candies that start with a base of...
howeys candy company manufactures five different types of tasty candies that start with a base of sugar milk and butter. Howeys processes these three raw materials together in the adding, mixing, and heating phases of making the candies. Once the mixture is prepared, it is separated into the proper ...
1 answer
Please choose the right answer Question 21 What do both gymnosperms and angiosperms have in common...
please choose the right answer Question 21 What do both gymnosperms and angiosperms have in common that is not true about other plant groups? a. they have only xylem and no phloem. b. they have a gametophyte generation. c. their gametes do not require water for fertilization to occur. d. they hav...
1 answer
12. A positive point charge qí = 8.0 nC s on x the axis at x-1...
12. A positive point charge qí = 8.0 nC s on x the axis at x-1 m and a second positive point charge q2 12nC is on x the axis at x -3m. Find the net electric field (a) at point A on the x axis at x-6m and (b) at point B on the x axis at x-2nm...
1 answer
Marly Bird Cosmetics Company allows independent sales consultants ……
Marly Bird Cosmetics Company allows independent sales consultants to sell cosmetics to their own clients via a network-and-sell scheme. They manufacture their own lipsticks and supply them to the Sales Consultants in their network. They need to identify what the optimal production lot size would be ...
1 answer
Explain at least 2 difference methods that can be used to pay employees. You are also...
Explain at least 2 difference methods that can be used to pay employees. You are also required to describe where to find information about payments in an organisation and the records that correspond to different payment methods. (simple and original answer please)...
1 answer
ASIA Co. has 30 million shares outstanding, trading for $60, with an EPS of $2.50 and...
ASIA Co. has 30 million shares outstanding, trading for $60, with an EPS of $2.50 and a P/E multiple of 24. The company earns net income of $200 million for the year and pays out an annual dividend of $1.50 per share. The board of directors is considering a 3-for-2 stock split. a) What is the compan...
1 answer
Problem 4. The median of a PDF fx(x) is defined as the number a for which...
Problem 4. The median of a PDF fx(x) is defined as the number a for which P(X s a)-P(X > a)-1/2. Find the median of a Gaussian PDF N(μ; σ2)....
1 answer
Metallic sodium can be made by the electrolysis of molten NaCl. (a) What mass of Na...
Metallic sodium can be made by the electrolysis of molten NaCl. (a) What mass of Na is formed by passing a current of 9.02 A through molten NaCl for 1.60 days? The unbalanced chemical reaction representing this electrolysis is shown below. NaCl Na + Cl2 g of Na is formed by this electrolysis. (b) Ho...
1 answer
In Exercises 1-6, locate the bifurcation values for the one-parameter family and draw the phase lines...
In Exercises 1-6, locate the bifurcation values for the one-parameter family and draw the phase lines for values of the parameter slightly smaller than, slightly larger than, and at the bifurcation values. dy α-ly 6. dt...
1 answer
A 3.00-kg object has an initial velocity (6i - 2j)m/s. Find the total work done on...
A 3.00-kg object has an initial velocity (6i - 2j)m/s. Find the total work done on the object as its velocity changes to (8i + 4j) m/s . (Note: From the definition of the scalar product, v2 = v . v) Select the correct one: - Imposible to predict because the displacement its not given - 72 Joules -60...
1 answer
26. The value of "U" in the chart below is: Quantity FC VC TC MC AVC...
26. The value of "U" in the chart below is: Quantity FC VC TC MC AVC ATC U 24 - 14 12 A) 0 B) 8 C) 12 D) 24 1 e 0 27. (Table) Based on the table, suppose the coffee plant experiences fixed costs of $35. At two units of production, the firm would have total costs of: VC $25 1 $40 2 $55 3 $70 ...
1 answer
[20] #6. For the circuit shown below, write three loop rule equations and a useful junction...
[20] #6. For the circuit shown below, write three loop rule equations and a useful junction rule equation involving is, is, and is. 9.0 V 7.0 22 Loop Loop 9.00 16.00 WEW 3.0V Loop Junction...
1 answer
D. Assume that you have a one-year coupon bond with a face value of $1,000 and...
d. Assume that you have a one-year coupon bond with a face value of $1,000 and a coupon payment of $50. What is the price of the bond if the yield to maturity is 6%? e. Assume that you have the same bond is in part d, except instead of paying one annual payment of $50, the bond pays two semi-annual ...
1 answer
0.0055 mol of gas undergoes the process 1 rightarrow 2 rightarrow 3 shown in the figure(Figure...
0.0055 mol of gas undergoes the process 1 rightarrow 2 rightarrow 3 shown in the figure(Figure 1). What is temperature T_1? Express your answer as an integer and include the appropriate units. What is pressure p_2? Express your answer to two significant figures and include the appropriate units....
1 answer
Ra Nat Formula Sheet Previous Quest Free fall means that an object is falling freely with...
ra Nat Formula Sheet Previous Quest Free fall means that an object is falling freely with no forces acting upon it except gravity. The distance the object falls, or height, h, is half the product of gravity and the square of the time falling Which of the following represents the equation in terms of...
1 answer
1.Construct a term that means failure of one or both testes to descend and select the...
1.Construct a term that means failure of one or both testes to descend and select the answer that correctly breaks the word down into its basic elements. a. epi/spad/ias b. hypo/spad/ias c. crypt/orch/ism d. orchio/pexy 2. Construct a term that means procedure performed through the urethra and sele...