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++
![```cpp
#include "car.h"
#include <string>
#include <iostream>
// =================== YOUR CODE HERE ===================
// This implementation file (car.cc) is where you should implement
// the member functions declared in the header (car.h), only
// if you didn't implement them inline within car.h.
//
// Remember to specify the name of the class with :: in this format:
// <return type> MyClassName::MyFunction() {
// ...
// }
// to tell the compiler that each function belongs to the Car class.
// ======================================================
Car::Car()
{
}
Car::Car(Identifier identifier)
{
this->identity_ = identifier;
}
Car::Car(Date date)
{
this->release_date_ = date;
}
Car::Car(Identifier identity, Date date)
{
this->identity_ = identity;
this->release_date_ = date;
}
void Car::set_identity(Identifier identity)
{
this->identity_ = identity;
}
Identifier Car::identity()
{
return this->identity_;
}
Date Car::releasedate()
{
return this->release_date_;
}
void Car::set_releasedate(Date date)
{
this->release_date_ = date;
}
```](/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)
![```cpp
#include <iostream>
#include "car.h"
int main() {
// ================= YOUR CODE HERE ======================
// 1. Create a Car object called `c1` using the default
// constructor.
// Call its Print member function.
// =======================================================
car::c1();
std::cout << "\n";
// ================= YOUR CODE HERE ======================
// 2. Create a `VehicleId` object with the following info:
// Model: Honda, ID: 3, License plate: 7B31X94
// 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.
// =======================================================
std::cout << "\n";
// ================= YOUR CODE HERE ======================
// 3. Create a `Date` object with the following info:
// Day: 4, Month: 11, Year: 2018
// 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.
// =======================================================
std::cout << "\n";
// ================= 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.
// 7. Call the `SetId` member function on `c4` and pass
// in the VehicleId you just created.
// 8. Call the `SetReleaseDate` member function on `c4`
// and pass in the Date you just created.
// 9. Finally, call the print member](/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++ Unit Testing and Error Analysis
## Code Overview
The image displays a C++ code snippet focused on unit testing using Google Test. The purpose of the tests is to verify the functionality and proper behavior of a `Car` class with attributes like `Model`, `LicensePlate`, and `ReleaseDate`.
### Includes and Using Declarations
```cpp
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "car.h"
#include "../cupaudit/gtest_ext.h"
using ::testing::HasSubstr;
```
These lines include necessary headers for Google Mock and Google Test, as well as the custom `car.h` header and a Google Test extension, preparing the environment for unit testing.
### Test Definitions
#### PublicMethodPresent Test
```cpp
TEST(Car, PublicMethodPresent) {
VehicleId your_identifier;
Date your_date;
Car your_car1;
Car your_car2(your_identifier);
Car your_car3(your_date);
Car your_car4(your_identifier, your_date);
your_car1.Id();
your_car1.SetId(your_identifier);
your_car1.ReleaseDate();
your_car1.SetReleaseDate(your_date);
}
```
This test checks if the class `Car` has constructors and methods for setting and getting IDs and release dates.
#### AccessorsAndMutators Test
```cpp
TEST(CarClass, AccessorsAndMutators) {
VehicleId unittest_identity("Ford", "123456");
Date unittest_date(28, 3, 1984);
Car your_car;
your_car.SetId(unittest_identity);
your_car.SetReleaseDate(unittest_date);
ASSERT_EQ(your_car.Id().Model(), unittest_identity.Model());
// Additional assertions...
}
```
This test verifies the proper setting and retrieval of car attributes such as model and VIN, using assertions to compare expected and actual values.
#### DefaultConstructor Test
```cpp
TEST(CarClass, DefaultConstructor) {
Car your_car;
ASSERT_EQ(your_car.Id().Model(), "Tesla");
// More assertions for default values...
}
```
Checks if the default constructor initializes the `Car` object with expected default values.
## Console Output
The console output on the right indicates compilation errors and assertion results:
- **Compilation Errors**:
- Errors in setting and accessing member functions like `SetId` and `Id` in the `Car`](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)