Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Challenge activity 7

Challenge activity 7

Computer Science

Challenge activity 7.5.1: Basic constructor definition.

Define a constructor as indicated. Sample output for below program:

Year: 0, VIN: -1
Year: 2009, VIN: 444555666

#include <iostream>
using namespace std;

class CarRecord {
public:
void SetYearMade(int originalYear);
void SetVehicleIdNum(int vehIdNum);
void Print() const;
CarRecord();
private:
int yearMade;
int vehicleIdNum;
};

// FIXME: Write constructor, initialize year to 0, vehicle ID num to -1.

/* Your solution goes here */

void CarRecord::SetYearMade(int originalYear) {
yearMade = originalYear;
return;
}

void CarRecord::SetVehicleIdNum(int vehIdNum) {
vehicleIdNum = vehIdNum;
return;
}

void CarRecord::Print() const {
cout << "Year: " << yearMade << ", VIN: " << vehicleIdNum << endl;
return;
}

int main() {
CarRecord familyCar;

familyCar.Print();
familyCar.SetYearMade(2009);
familyCar.SetVehicleIdNum(444555666);
familyCar.Print();

return 0;
}

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Answer Preview

The basic constructor definition according to the required details is as follows:


CarRecord::CarRecord(void)
{
vehicleIdNum=-1;       //assigning -1 to the variable vehicleIdNum
yearMade=0;           //assigning 0 to the variable yearMade
}