QuestionQuestion

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 PreviewSolution 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);...

By purchasing this solution you'll be able to access the following files:
Solution.cpp.

$20.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats