Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Redo lab 3 and change the Computer class to a struct. 1. Keep the default and non-default constructors 2. Your struct does not need the

Redo lab 3 and change the Computer class to a struct. 1. Keep the default and non-default constructors 2. Your struct does not need the accessors and mutators since all variables are public by default. 3. Write a main(): - Create an instance of type Computer using the default constructor. - Set the values for year, model, and purpose using any values you'd like. - Print the values of year, model, and purpose to the standard output. - Prompt the user to enter a value for year, model, and purpose - Create a new instance of type Computer using the non-default constructor. - Print the values of year, model, and purpose.

-------------------------

main.cpp

#include #include #include "Car.h" // Included Car class file

using namespace std;

Car test2(){ Car c; c.setYear(2020); 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 #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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions