Question
The purpose of this assignment is to:
• Implement copy assignment and copy constructor methods to ‘complete’ the class
• Utilize the destructor for resource management
• Implement a child class
• Test workings of inheritance

Requirements
• Include the comment template at the top of your program. Use 232 Coding Standards when writing your code.
• Use only C++ language features discussed in class or presented in the book up to the date the assignment is due. Submit only what is requested.
• Modify Vehicle class with the following:
1.1. ‘Complete’ your class
1.1.1. Add copy constructor
1.1.2. Add copy assignment - use new keyword
1.1.3. Modify destructor with delete
1.1.4. Add cout’s to all constructors and destructor to show when they are called
1.1.5. Add code to test all the above
1.2. Add a child class to Vehicle
1.2.1. Put some fields in protected, keep some in private
1.2.2. Pick one method in both classes - use virtual keyword in parent
1.2.3. Create at least one parent and one child variable
1.2.4. Call the method in 1.2.2 with both object to confirm virtual is working
1.2.5. Test access to a parent private field from a child method

Here is the code:
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::ostream;
using std::string;

// Class Vehicle declaration
class Vehicle {
public:
    Vehicle(); //Default constructor
    Vehicle(string make, string model, int year, bool manual); //make, model, year, manual constructor
   
    ~Vehicle(); //destructor
   
    /*
    // Getters
    string readMake();
    string readModel();
    int readYear();
    bool readManual();
    */
   
    // Setters
    //void setInfo(string sMake, string sModel, int sYear, bool sManual);
   
    //bool operator== (const Vehicle& rhs) const;
   
    // For << overload; both must be friends for access to private class fields.
    friend ostream& operator <<(ostream& out, Vehicle& v);
    //Class fields
private:
    string make;
    string model;
    int year;
    bool manual;
};


/*
Class Vehicle - Definitions (methods)
*/
// Default Constructor; fields must *all* be initialized.
Vehicle::Vehicle() {
    make = "";
    model = "";
    year = 0;
    manual = true;
}

// 'Vehicle' constructor; fields must *all* be initialized.
Vehicle::Vehicle (string aMake, string aModel, int aYear, bool aManual) {
    make = aMake;
    model = aModel;
    year = aYear;
    manual = aManual;
}

//Destructor
Vehicle::~Vehicle(){ }

/*
void Vehicle::setInfo(string sMake, string sModel, int sYear, bool sManual){
year += sYear;
make += sMake;
model += sModel;
manual += sManual;
}

string Vehicle::readMake(){return make;}

string Vehicle::readModel(){return model;}

int Vehicle::readYear(){return year;}
*/

/* << overload. Print minimum necessary here. Specfically, don't
print any \n and endl or you might mess up formatting that
the user wants.

Friend functions have access to private members of
the class. So we can use v.make directly instead of
v.readMake() to get value of x. */
ostream& operator<<(ostream& ost, Vehicle& v) {
    cout << "Make: " << v.make << "," << " Model: " << v.model << "," << " Year: " << v.year << "," << " Manual? " << std::boolalpha << v.manual << ", ";
    return ost;
}
/* END << OVLERLOAD */


int main(){
    Vehicle v; //Calls default constructor
    Vehicle car("Dodge Ram", "1500", 2001, true); //Calls vehicle construtor
    Vehicle c;

    cout << "Your vehicle: " << car; //Prints vehicle info
}
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::ostream;
using std::string;

// Class Vehicle declaration
class Vehicle {
public:
    Vehicle(); //Default constructor
    Vehicle(string make, string model, int year, bool manual); //make, model, year, manual constructor
    Vehicle(const Vehicle &o); //Copy constructor
    ~Vehicle(); //destructor
   
    Vehicle& operator=(const Vehicle &o);
      
    // Getters
    string readMake();
    string readModel();
    int readYear();
    bool readManual();
   
    // Setters
    void setInfo(string sMake, string sModel, int sYear, bool sManual);
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.cpp
Purchase Solution
$20.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,806+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,696+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,467+ sessions)
2 hours avg response

Similar Homework Solutions