Car Class Composition Create a class called `Car` that will utilize other objects. ## Car ### Car member variables Create two data members that are: (1) an instance of the `VehicleId` class called `id_` and (2) an instance of the `Date` class called `release_date_`. *NOTE*: `VehicleId` and `Date` are classes that have been provided to you. You **DO NOT** need to create them. ### Default Constructor The default constructor will be **EMPTY**, so you do not have to initialize anything. `VehicleId` and `Date`'s respective constructors will initialize their default values. ### Non-Default Constructors 1. Create a non-default constructor that takes in a `VehicleId` object. This will assign the parameter to the `id_` member variable. 2. Create a non-default constructor that takes in a `Date` object. This will assign the parameter to the `release_date_` member variable. 3. Create a non-default constructor that takes in a `VehicleId` and a `Date` object (in this order). This will assign the parameters to the `id_` and `release_date_` parameters correspondingly. ### Accessors and Mutators Create accessors and mutators for `id_` and `release_date_`, following the naming conventions covered in class. e.g. for id_, name the accessor `Id`, and the mutator `SetId`. ### Other Member Functions Create a `void` member function called `Print` that takes in no parameters. `Print` should print the model, vehicle id (VIN), license plate, and release date of the car. The release date should follow the format **mm/dd/yyyy**. See the output below as a reference. ## Other instructions Complete the `main` function as described. Place your class in `car.h`. Member functions that take more than ten lines or use complex constructs should have their function prototype in `car.h` and implementation in `car.cc`. Your program does not need to account for the correct dates or license plates. For example: 13/41/1 will be acceptable for your program, even though it is not an acceptable date, and "1111111111111111" will be acceptable in your program, even though it is not a valid license plate number. ## Sample output ``` The model of the car is: Tesla The VIN of the car is: 121 The license plate of the car is: TUFFY121L The release date of the car is: 1/1/2022 The model of the car is: Honda The VIN of the car is: 3 The license plate of the car is: 7B319X4 The release date of the car is: 1/1/2022 The model of the car is: Ford The VIN of the car is: 1 The license plate of the car is: 123456 The release date of the car is: 11/4/2018 The model of the car is: Honda The VIN of the car is: 3 The license plate of the car is: 7B319X4 The release date of the car is: 11/4/2018 The model of the car is: Tesla The VIN of the car is: 121 The license plate of the car is: TUFFY121L The release date of the car is: 1/1/2022
# Car Class Composition
Create a class called `Car` that will utilize other objects.
## Car
### Car member variables
Create two data members that are: (1) an instance of the `VehicleId` class called `id_` and (2) an instance of the `Date` class called `release_date_`.
*NOTE*: `VehicleId` and `Date` are classes that have been provided to you. You **DO NOT** need to create them.
### Default Constructor
The default constructor will be **EMPTY**, so you do not have to initialize anything. `VehicleId` and `Date`'s respective constructors will initialize their default values.
### Non-Default Constructors
1. Create a non-default constructor that takes in a `VehicleId` object. This will assign the parameter to the `id_` member variable.
2. Create a non-default constructor that takes in a `Date` object. This will assign the parameter to the `release_date_` member variable.
3. Create a non-default constructor that takes in a `VehicleId` and a `Date` object (in this order). This will assign the parameters to the `id_` and `release_date_` parameters correspondingly.
### Accessors and Mutators
Create accessors and mutators for `id_` and `release_date_`, following the naming conventions covered in class. e.g. for id_, name the accessor `Id`, and the mutator `SetId`.
### Other Member Functions
Create a `void` member function called `Print` that takes in no parameters. `Print` should print the model, vehicle id (VIN), license plate, and release date of the car. The release date should follow the format **mm/dd/yyyy**. See the output below as a reference.
## Other instructions
Complete the `main` function as described. Place your class in `car.h`. Member functions that take more than ten lines or use complex constructs should have their function prototype in `car.h` and implementation in `car.cc`.
Your program does not need to account for the correct dates or license plates. For example: 13/41/1 will be acceptable for your program, even though it is not an acceptable date, and "1111111111111111" will be acceptable in your program, even though it is not a valid license plate number.
## Sample output
```
The model of the car is: Tesla
The VIN of the car is: 121
The license plate of the car is: TUFFY121L
The release date of the car is: 1/1/2022
The model of the car is: Honda
The VIN of the car is: 3
The license plate of the car is: 7B319X4
The release date of the car is: 1/1/2022
The model of the car is: Ford
The VIN of the car is: 1
The license plate of the car is: 123456
The release date of the car is: 11/4/2018
The model of the car is: Honda
The VIN of the car is: 3
The license plate of the car is: 7B319X4
The release date of the car is: 11/4/2018
The model of the car is: Tesla
The VIN of the car is: 121
The license plate of the car is: TUFFY121L
The release date of the car is: 1/1/2022
car.h:
#include "date.h"
#include "vehicleid.h"
#include <string>
#include <iomanip>
#include <iostream>
class Car{
private:
Identifier identity_;
Date release_date_;
public:
Car() {}
Car(Identifier identifier);
Car(Date date);
Car(Identifier identity, Date date);
void set_identity(Identifier identity);
Identifier identity();
Date releasedate();
void set_releasedate(Date date);
void print();
};
data.h:
class Date {
public:
Date() : Date(1, 1, 2022) {}
Date(int day, int month, int year) : day_(day), month_(month), year_(year) {}
int Day() const { return day_; }
void SetDay(int day) { day_ = day; }
int Month() const { return month_; }
void SetMonth(int month) { month_ = month; }
int Year() const { return year_; }
void SetYear(int year) { year_ = year; }
private:
int day_;
int month_;
int year_;
};
vehicleld.h:
#include <string>
class VehicleId {
public:
VehicleId() : VehicleId("Tesla", 121, "TUFFY121L") {}
VehicleId(const std::string &model, int vin, const std::string &license_plate)
: model_(model), vin_(vin), license_plate_(license_plate) {}
int Vin() const { return vin_; }
void SetVin(int vin) { vin_ = vin; }
std::string Model() const { return model_; }
void SetModel(const std::string &model) { model_ = model; }
std::string LicensePlate() const { return license_plate_; }
void SetLicensePlate(const std::string &license_plate) {
license_plate_ = license_plate;
}
private:
// A vehicle identification number (VIN)
int vin_;
std::string model_;
std::string license_plate_;
};
do car.cc and main.cc in C++
![1 #include "car.h"
2 #include <string>
3 #include <iostream>
4
5
// ====
//
====YOUR CODE HERE
// This implementation file (car.cc) is where you should implement
6 // the member functions declared in the header (car.h), only
7 // if you didn't implement them inline within car.h.
8
//
9
// Remember to specify the name of the class with :: in this format:
<return type> MyClassName::MyFunction() {
10
11
//
12
//
}
13 // to tell the compiler that each function belongs to the Car class.
14
// =====
15 ▼ Car:: Car() {
16
17 }
18
19 Car::Car(Identifier identifier)
20 ▼ {
21 this->identity_ = identifier;
22
23
24 Car::Car(Date date)
25 ▼ {
26 this->release_date_ = date;
27 }
28
}
29
30 ▼ {
Car::Car(Identifier identity, Date date)
31 this->identity_ = identity;
32
this->release_date= date;
33 }
34
35 void Car::set_identity (Identifier identity)
36 ▼ {
37 this->identity_ = identity;
38
39
40 Identifier Car::identity()
41 ▼ {
42
}
return this->identity_;
43 }
44
45 Date Car::releasedate()
46 ▼ {
47 return this->release_date_;
48 }
49
50 void Car::set_releasedate(Date date)
51 ▼ {
52 this rolonco data. - data.
Line 3: Col 20
History](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2216a831-152e-4ce3-9ac2-b23e19574410%2F949a88e0-2486-4e8e-ae88-26c59ecabd47%2F06s0zuj_processed.png&w=3840&q=75)
![1 #include <iostream>
2 #include "car.h"
3 int main() {
4
5
6
7
8
//========
9
car::c1();
10 std::cout << "\n";
11
// ===
YOUR CODE HERE
12
// 2. Create a `VehicleId` object with the following info:
Model: Honda, ID: 3, License plate: 7B319X4
13
//
14
//
15
16
17
18
19
20
21
22
23
24
25
26
27
28 std::cout << "\n";
29 30 31 32 33 34 35 36 37 38 39 40 41 2 3 4 5
42
43
44
// =====
====== YOUR CODE HERE
// 1. Create a Car object called 'c1 using the default
//
constructor.
// Call its Print member function.
45
//
//
// ===
std::cout << "\n";l
//===
Create a Car object c2 using the constructor that
accepts a 'VehicleId` and pass in the VehicleId
object you just made.
Call its Print member function.
// ======
===YOUR CODE HERE ====
// 3. Create a 'Date object with the following info:
11, Year: 2018
//
Day: 4, Month:
//
//
Create a Car object `c3` using the constructor that
accepts a Date object and pass in the Date object
you just made.
//
//
Call its Print member function.
// ==========
=========== YOUR CODE HERE =====
// 4. Create a `Car` object `c4` using the constructor that
// accepts a VehicleId and `Date object and pass in
// the 'VehicleId and 'Date objects you created in
// steps 2 and 3 above.
// Call its Print member function.
//=======
std::cout << "\n";
=============
// 5. Create an instance of
VehicleId using the default constructor.
// 6. Create an instance of Date using the default constructor.
46
47
48
49
50
51
52 1
Line 19: Col 21
=======
=============
// 7. Call the `SetId` member function on `c4` and pass
// in the VehicleId you just created.
return 0;
// 8. Call the `SetRelease Date` member function on `c4`
// and pass in the Date you just created.
// 9. Finally, call the print member function for 'c4`.
History Ⓒ](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2216a831-152e-4ce3-9ac2-b23e19574410%2F949a88e0-2486-4e8e-ae88-26c59ecabd47%2Fk50v1l_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
i fixed some problems, but i do not know how to fix this, it wants Id in car.h instead of id, and SetId instead of set_identity
![C unittest.cc x C car.h x +
1 #include <gmock/gmock.h>
2 #include <gtest/gtest.h>
3 #include "../../car.h"
4 #include "../cppaudit/gtest_ext.h"
5
6 using ::testing::HasSubstr;
7
8▼ TEST(Car, PublicMethodPresent) {
9 VehicleId your_identifier;
10 Date your date;
11 Car your_car1;
12
Car your_car2(your_identifier);
13
Car your_car3(your_date);
14 Car your car4(your_identifier, your_date);
15 your_car1.Id();
16 your_car1.SetId(your_identifier);
17 your_car1. ReleaseDate();
18 your_car1.SetRelease Date(your_date);
19 }
20
21 ▼ TEST(CarClass, AccessorsAndMutators) {
22 VehicleId unittest_identity("Ford", 1, "123456");
23
24
25 your_car.SetId(unittest_identity);
26 your_car.SetRelease Date(unittest_date);
27
28 ASSERT_EQ((your_car.Id()). Model(), unittest_identity. Model())
29
<< "The car's VehicleId model should be Ford";
30 ASSERT_EQ((your_car.Id()). Vin(), unittest_identity. Vin())
31
<< "The car's VehicleId VIN should be 1";
Date unittest_date(28, 3, 1984);
Car your_car;
32 ASSERT_EQ((your_car.Id()). LicensePlate(),
33
34
35
36
37
38
39
40
41 }
42
unittest_identity. LicensePlate())
<< "The car's VehicleId license plate should be 123456";
ASSERT_EQ((your_car. Release Date()).Day(), unittest_date.Day())
<< "The car's release date day should be 28";
ASSERT_EQ((your_car. Release Date()).Month(), unittest_date.Month())
<< "The car's release date month should be 3";
ASSERT_EQ((your_car. Release Date()). Year(), unittest_date.Year())
<< "The car's release date year should be 1984";
43 ▼ TEST(CarClass, Default Constructor) {
44
Car your_car;
45
46
47 ASSERT_EQ((your_car.Id()). Vin(), 121)
48
49
50
51
52
53
54
Line 15: Col 14
ASSERT_EQ((your_car.Id()). Model(), "Tesla")
<< "The car's VehicleId model should be Tesla";
<< "The car's VehicleId VIN should be 121";
ASSERT_EQ((your_car.Id()). LicensePlate(), "TUFFY121L")
<< "The car's VehicleId license plate should be TUFFY121L";
ASSERT_EQ((your_car. Release Date()).Day(), 1)
<< "The car's release date day should be 1";
ASSERT_EQ((your_car. Release Date()). Month(), 1)
<< "The car's release date month should be 1";
History
⠀
> Console x +
The VIN of the car is: 121
The license plate of the car is: TUFFY121L
The release date of the car is: 1/1/2022
prob01 finished running. Would you like to run make commands?
T: make test
S: make stylecheck
F: make formatcheck
Press any other key to exit.
Selection:
a
Done!
> cd prob01
> make test
make[1]: Entering directory '/home/runner/lab09-tianranlu/prob@1/tools/cppaudit'
../settings/unittest.cc:15:13: error: no member named 'Id' in 'Car'
your_car1.Id();
../settings/unittest.cc:16:13: error: no member named 'SetId' in 'Car'
your_car1.SetId(your_identifier);
../settings/unittest.cc:25:12: error: no member named 'SetId' in 'Car'
your_car.SetId(unittest_identity);
../settings/unittest.cc:28:23: error: no member named 'Id' in 'Car'
ASSERT_EQ((your_car.Id()).Model(), unittest_identity.Model())
note: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest.h:2073:48:
E
Q Û
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest.h:2057:63:
note: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing:: internal::EqHelper::Compare, val1, val2)
/nix/store/f4w1mb7c7q22z6lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:168:36: note: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:149:39: note: expanded from macro 'GTEST_PRED_FORMAT2_'
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:77:52: note: expanded from macro 'GTEST ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
note: expanded from macro 'ASSERT_EQ'
#define ASSERT_EQ(val1, val2) GTEST_ASSERT_EQ(val1, val2)
../settings/unittest.cc:30:23: error: no member named 'Id' in 'Car'
ASSERT_EQ((your_car.Id()).Vin(), unittest_identity. Vin())
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest.h:2073:48:
^NNN
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest.h:2057:63:
note: expanded from macro 'GTEST_ASSERT_EQ'
ASSERT_PRED_FORMAT2(::testing:: internal::EqHelper::Compare, val1, val2)
^NNN
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:168:36: note: expanded from macro 'ASSERT_PRED_FORMAT2'
GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_)
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:149:39: note: expanded from macro 'GTEST_PRED_FORMAT2_
GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), \
/nix/store/f4w1mb7c7q22z6Lnwzgv0yf4f678p2j7-gtest-1.11.0-dev/include/gtest/gtest_pred_impl.
h:77:52: note: expanded from macro 'GTEST_ASSERT_'
if (const ::testing::AssertionResult gtest_ar = (expression)) \
^NNNNNNNNN
../settings/unittest.cc:32:23: error: no member named 'Id' in 'Car'
ASSERT_EQ((your_car.Id()). LicensePlate(),](https://content.bartleby.com/qna-images/question/2216a831-152e-4ce3-9ac2-b23e19574410/9799405a-32df-48c0-812f-d079b9f6e4ae/e8j03pb_thumbnail.png)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)