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
};
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:
c++ Error after oveloading, please help? LAB #8- CLASSES REVISITED && Lab #8.5 … Jayasinghe...
This is assignment and code from this site but it will not compile....can you help? home / study / engineering / computer science / computer science questions and answers / c++ this assignment requires several classes which interact with each other. two class aggregations ... Question: C++ This assignment requires several classes which interact with each other. Two class aggregatio... (1 bookmark) C++ This assignment requires several classes which interact with each other. Two class aggregations are formed. The program...
USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...
I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...
You are given a partial implementation of two classes. GroceryItem is a class that holds the information for each grocery item. GroceryInventory is a class that holds an internal listing of GroceryItems as well as the tax rate for the store. Your inventory could be 100 items it could be 9000 items. You won’t know until your program gets the shipment at runtime. For this you should use the vector class from the C++ standard library. I've completed the GroceryItem.h...
C++ -- Vector of Bank Accounts (15 pts) Please help! :( Use csegrid or Clion for this part Add on to the lab12a solution(THIS IS PROVIDED BELOW). You will add an overload operator function to the operator << and a sort function (in functions.h and functions.cpp) Print out the customer’s name, address, account number and balance using whatever formatting you would like Sort on account balance (hint: you can overload the < operator and use sort from the...
using C++ language!! please help me out with this homework In this exercise, you will have to create from scratch and utilize a class called Student1430. Student 1430 has 4 private member attributes: lastName (string) firstName (string) exams (an integer array of fixed size of 4) average (double) Student1430 also has the following member functions: 1. A default constructor, which sets firstName and lastName to empty strings, and all exams and average to 0. 2. A constructor with 3 parameters:...
C++ problem: Make a program that the user enter the degree and coefficients of a polynomial. Use the overload operators mentioned in the class below: #include <iostream> #include <stdlib.h> using namespace std; class Polynomial{ public: Polynomial(); //Default constructor: it creates an Polynomial of degree 99 Polynomial(int dg); //Special constructor: it creates an Polynomial of degree dg Polynomial(const Polynomial &Original); //Copy Constructor ~Polynomial(); //Destructor: deallocate memory void readPolynomial(); //readPolynomial Method: Reads all positions of the Polynomial void printPolynomial(); //printPolynomial Method:...
C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node { ItemType value; Node *next; }; class LinkedList { private: Node *head; // You may add whatever private data members or private member functions you want to this class. void printReverseRecursiveHelper(Node *temp) const; public: // default constructor LinkedList() : head(nullptr) { } // copy constructor LinkedList(const LinkedList& rhs); // Destroys all the dynamically allocated memory //...
hello there. can you please help me to complete this code. thank you. Lab #3 - Classes/Constructors Part I - Fill in the missing parts of this code #include<iostream> #include<string> #include<fstream> using namespace std; class classGrades { public: void printlist() const; void inputGrades(ifstream &); double returnAvg() const; void setName(string); void setNumStudents(int); classGrades(); classGrades(int); private: int gradeList[30]; int numStudents; string name; }; int main() { ...
SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...