I need help completeting the following Code please someone help this assignment
ID: 3814927 • Letter: I
Question
I need help completeting the following Code please someone help this assignment is due at the end of the day! Problem 1. Complete a program that manages book orders. The objective of this program is to get you familiar with operator overloading, this pointer, destructor, assignment operator overloading, and copy constructor. The requirement of each method is described in the file. After a successful implementation, your program should display: The orders of cr1 and cr2 are different The orders of cr1 and cr4 are same Code: #include <iostream> #include <string> using namespace std; //do not make change to this class definition class book_order { private: string book_title; string customer_first_name; string customer_last_name; double * cost; public: book_order(string, string, string, double); book_order(book_order &); // copy constructor book_order & operator =(book_order &); // operator (=) overloading ~book_order(); string get_book_title(); string get_customer_name(); double get_cost(); }; book_order::book_order(string book_title, string first_name, string last_name, double cost) // do not make change to this line { // constructor // initialize the object attributes // Your code goes here. } book_order::book_order(book_order & b) { //copy contructor //your code goes here } book_order & book_order::operator =(book_order & b) { //assignment operator overliading //your code goes here } string book_order::get_book_title() { // return the book title // Your code goes here. } string book_order::get_customer_name() { // return the customer name: first name followed by a space which is followed by last name string full_name = this->customer_first_name + " " + this->customer_last_name; return full_name; } double book_order::get_cost() { // return the book price // Your code goes here. } book_order::~book_order() { // descructor // deallocate space for dynamically created variable // do not make change to this function delete this->cost; } bool operator ==( book_order &, book_order &); int main() { book_order cr1("About Paris", "Janet", "Smith", 109.99); book_order cr2("Gone with the Wind", "Kelly", "Adam", 55.99); if(cr1==cr2) { cout << "The oders of cr1 and cr2 are same "; } else { cout << "The orders of cr1 and cr2 are different "; } book_order cr4 = cr2; // copy constructor is called here cr1 = cr2; // overloaded assignment operator is called here if(cr1==cr4) { cout << "The orders of cr1 and cr4 are same "; } else { cout << "The orders of cr1 and cr4 are different "; } return 1; } bool operator ==(book_order & cr1, book_order & cr2) { // Test if the book title and book price of two oders are same. // If both of these two fields are same, return true, else return false. // Your code goes here. } /* after a successful implementation, the program should disply: The orders of cr1 and cr2 are different The orders of cr1 and cr4 are same */
Explanation / Answer
Here is the code for you:
#include <iostream>
#include <string>
using namespace std;
//do not make change to this class definition
class book_order
{
private:
string book_title;
string customer_first_name;
string customer_last_name;
double *cost;
public:
book_order(string, string, string, double);
book_order(book_order &); // copy constructor
book_order & operator =(book_order &); // operator (=) overloading
~book_order();
string get_book_title();
string get_customer_name();
double get_cost();
};
book_order::book_order(string book_title, string first_name, string last_name, double cost) // do not make change to this line
{
// constructor
// initialize the object attributes
// Your code goes here.
this->book_title = book_title;
customer_first_name = first_name;
customer_last_name = last_name;
this->cost = new double(cost);
//this->cost = &cost;
}
book_order::book_order(book_order & b)
{
//copy constructor
//your code goes here
book_title = b.book_title;
customer_first_name = b.customer_first_name;
customer_last_name = b.customer_last_name;
cost = b.cost;
}
book_order & book_order::operator =(book_order & b)
{
//assignment operator overloading
//your code goes here
book_title = b.book_title;
customer_first_name = b.customer_first_name;
customer_last_name = b.customer_last_name;
cost = b.cost;
return *this;
}
string book_order::get_book_title()
{
// return the book title
// Your code goes here.
return book_title;
}
string book_order::get_customer_name()
{
// return the customer name: first name followed by a space which is followed by last name
string full_name = this->customer_first_name + " " + this->customer_last_name;
return full_name;
}
double book_order::get_cost()
{
// return the book price
// Your code goes here.
return *cost;
}
book_order::~book_order()
{
// descructor
// deallocate space for dynamically created variable
// do not make change to this function
delete this->cost;
}
bool operator ==( book_order &, book_order &);
int main()
{
book_order cr1("About Paris", "Janet", "Smith", 109.99);
book_order cr2("Gone with the Wind", "Kelly", "Adam", 55.99);
if(cr1==cr2)
{
cout << "The oders of cr1 and cr2 are same ";
}
else
{
cout << "The orders of cr1 and cr2 are different ";
}
book_order cr4 = cr2; // copy constructor is called here
cr1 = cr2; // overloaded assignment operator is called here
if(cr1==cr4)
{
cout << "The orders of cr1 and cr4 are same ";
}
else
{
cout << "The orders of cr1 and cr4 are different ";
}
return 1;
}
bool operator ==(book_order & cr1, book_order & cr2)
{
// Test if the book title and book price of two oders are same.
// If both of these two fields are same, return true, else return false.
// Your code goes here.
if(cr1.get_book_title().compare(cr2.get_book_title()) != 0)
return false;
if(cr1.get_cost() != cr2.get_cost())
return false;
return true;
}
/*
after a successful implementation, the program should disply:
The orders of cr1 and cr2 are different
The orders of cr1 and cr4 are same
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.