Hello id like the implementation for this please thank you i

Hello, i\'d like the implementation for this please thank you.

#ifndef GROCERY_ITEM
#define GROCERY_ITEM

#include <iostream>
#include <string>

using namespace std;
class GroceryItem
{
public:
// constructors
GroceryItem(string, string, float);
GroceryItem();
// copy constructor
GroceryItem(const GroceryItem&);
// mutators
void setItemName(string);
void setItemCode(string);
void setItemPrice(float);
// accessors
string getItemName() const;
string getItemCode() const;
float getItemPrice() const;
void print() const;
private:
string itemName;
string itemCode;
float itemPrice;
};
#endif
bool operator<(const GroceryItem& left, const GroceryItem& right);
bool operator>(const GroceryItem& left, const GroceryItem& right);
ostream& operator<<(ostream& out, const GroceryItem& value);
istream& operator>>(istream& in, GroceryItem& r);

Solution

Hi, Please find my implementation

Please let me know in case of any issue.

######### GroceryItem.h ###########

#ifndef GROCERY_ITEM
#define GROCERY_ITEM
#include <iostream>
#include <string>
using namespace std;
class GroceryItem
{
public:
// constructors
GroceryItem(string, string, float);
GroceryItem();
// copy constructor
GroceryItem(const GroceryItem&);
// mutators
void setItemName(string);
void setItemCode(string);
void setItemPrice(float);
// accessors
string getItemName() const;
string getItemCode() const;
float getItemPrice() const;
void print() const;
private:
string itemName;
string itemCode;
float itemPrice;
};
#endif
bool operator<(const GroceryItem& left, const GroceryItem& right);
bool operator>(const GroceryItem& left, const GroceryItem& right);
ostream& operator<<(ostream& out, const GroceryItem& value);
istream& operator>>(istream& in, GroceryItem& r);

########### GroceryItem.cpp ###############

#include <iostream>
#include \"GroceryItem.h\"

using namespace std;

// constructors
GroceryItem::GroceryItem(string name, string code, float price){
    itemName = name;
    itemCode = code;
    itemPrice = price;
}

GroceryItem::GroceryItem(){
    itemName = \"\";
    itemCode = \"\";
    itemPrice = 0;
}

// copy constructor
GroceryItem::GroceryItem(const GroceryItem& other){
    itemName = other.itemName;
    itemCode = other.itemCode;
    itemPrice = other.itemPrice;
}
// mutators
void GroceryItem::setItemName(string name){
    itemName = name;
}
void GroceryItem::setItemCode(string code){
    itemCode = code;
}
void GroceryItem::setItemPrice(float price){
    itemPrice = price;
}
// accessors
string GroceryItem::getItemName() const{
    return itemName;
}
string GroceryItem::getItemCode() const{
    return itemCode;
}
float GroceryItem::getItemPrice() const{
    return itemPrice;
}
void GroceryItem::print() const{
    cout<<\"Item Name: \"<<itemName<<endl;
    cout<<\"Item Code: \"<<itemCode<<endl;
    cout<<\"Item Price: \"<<itemPrice<<endl;
}

bool operator<(const GroceryItem& left, const GroceryItem& right){

   if(left.getItemName().compare(right.getItemName()) < 0){
       if(left.getItemCode().compare(right.getItemCode()) < 0){
           if(left.getItemPrice() < right.getItemPrice())
               return true;
           else
               return false;
       }else{
           return false;
       }
   }else{
       return false;
   }

}
bool operator>(const GroceryItem& left, const GroceryItem& right){

   if(left.getItemName().compare(right.getItemName()) > 0){
       if(left.getItemCode().compare(right.getItemCode()) > 0){
           if(left.getItemPrice() > right.getItemPrice())
               return true;
           else
               return false;
       }else{
           return false;
       }
   }else{
       return false;
   }
}
ostream& operator<<(ostream& out, const GroceryItem& value){

   out<<\"Item Name: \"<<value.getItemName()<<\", Item Code: \"<<value.getItemCode()
       <<\", and Item Price: \"<<value.getItemPrice()<<endl;

   return out;
}
istream& operator>>(istream& in, GroceryItem& r){

   string name, code;
   float price;

   cout<<\"Enter Item Name: \";
   in>>name;
   r.setItemName(name);

   cout<<\"Enter Item Code: \";
   in>>code;
   r.setItemCode(code);

   cout<<\"Enter Item Price: \";
   in>>price;
   r.setItemPrice(price);

   return in;
}

########## TestGroceryItem.cpp ##############

#include <iostream>
#include \"GroceryItem.h\"

using namespace std;

int main(){

   GroceryItem item;

   item.print();

   cin>>item;

   cout<<item;


   return 0;
}

Hello, i\'d like the implementation for this please thank you. #ifndef GROCERY_ITEM #define GROCERY_ITEM #include <iostream> #include <string> using
Hello, i\'d like the implementation for this please thank you. #ifndef GROCERY_ITEM #define GROCERY_ITEM #include <iostream> #include <string> using
Hello, i\'d like the implementation for this please thank you. #ifndef GROCERY_ITEM #define GROCERY_ITEM #include <iostream> #include <string> using
Hello, i\'d like the implementation for this please thank you. #ifndef GROCERY_ITEM #define GROCERY_ITEM #include <iostream> #include <string> using

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site