CHALLENGE ACTIVITY 10.6.2: Basic constructor definition. Define a constructor as indicated. Sample output for below prog

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

CHALLENGE ACTIVITY 10.6.2: Basic constructor definition. Define a constructor as indicated. Sample output for below prog

Post by answerhappygod »

Challenge Activity 10 6 2 Basic Constructor Definition Define A Constructor As Indicated Sample Output For Below Prog 1
Challenge Activity 10 6 2 Basic Constructor Definition Define A Constructor As Indicated Sample Output For Below Prog 1 (62.01 KiB) Viewed 14 times
#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;}
void CarRecord::SetVehicleIdNum(int vehIdNum) { vehicleIdNum = vehIdNum;}
void CarRecord::Print() const { cout << "Year: " << yearMade << ", VIN: " << vehicleIdNum << endl;}
int main() { CarRecord familyCar;
familyCar.Print(); familyCar.SetYearMade(2009); familyCar.SetVehicleIdNum(444555666); familyCar.Print();
return 0;}
CHALLENGE ACTIVITY 10.6.2: Basic constructor definition. Define a constructor as indicated. Sample output for below program: Year: 0, VIN: -1 Year: 2009, VIN: 444555666 397756.2392630.qx3zqy7 1 #include <iostream> 2 using namespace std; 4 class CarRecord { public: 5 N34 in 67 899 void SetYearMade (int original Year); void SetVehicleIdNum(int vehIdNum); void Print() const; CarRecord(); private: int int 10 11 12 13 }; 14 15 // FIXME: Write constructor, initialize year to 0, vehicle ID num to -1. 16 yearMade; vehicleIdNum; 17/* Your solution goes here */ 18 | 0 1 tast All tests passed
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply