Question
Implement the Computer class as shown in class and add the missing Accessors/Mutators -- main.cpp --- #include #include #include Car.h // Included Car class file
Implement the Computer class as shown in class and add the missing Accessors/Mutators
-- main.cpp ---
#include #include #include "Car.h" // Included Car class file
using namespace std;
void test(const Car &c){ cout << c.setYear() << endl; cout << c.getYear() << endl; } Car test2(){ Car c; c.setYear(2020); c.getYear(){return year;} return c; } int main(){ Car c0 = test2(); cout << c0.getYear() << endl; return 0; }
-- Car.cpp --
#include "Car.h"
void Car::setYear(int y){ year = y; }
Car::Car() : Car(-1,""){} Car::Car(int y, string m) : Car(y, m, ""){} Car::Car(int y, string m, string p){ setYear(y); model = m; purpose = p; } int Car::getYear() const{ return year; } Car::~Car(){ cout << "Removed from memory..." << endl; }
-- Car.h --
#include #include
#ifndef CAR_H #define CAR_H
using namespace std;
class Car{ private: int year; string model, purpose; public: // Construct and instance using default values Car(); Car(int y, string m); Car(int y, string m, string p); void setYear(int y); int getYear() const; ~Car(); // Cleanup memory }; #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started