346,762 views
19 votes
19 votes
(10 POINTS) in C ++ Define the missing function. licenseNum is created as: (100000 * customID) + licenseYear, where customID is a function parameter.

Sample output with inputs 2014 777:
Dog license: 77702014
#include
using namespace std;
class DogLicense {
public:
void SetYear(int yearRegistered);
void CreateLicenseNum(int customID);
int GetLicenseNum() const;
private:
int licenseYear;
int licenseNum;
};
void DogLicense::SetYear(int yearRegistered) {
licenseYear = yearRegistered;
}
// FIXME: Write CreateLicenseNum()
/* Your solution goes here */
int DogLicense::GetLicenseNum() const {
return licenseNum;
}
int main() {
DogLicense dog1;
int userYear;
int userId;
cin >> userYear;
cin >> userId;
dog1.SetYear(userYear);
dog1.CreateLicenseNum(userId);
cout << "Dog license: " << dog1.GetLicenseNum() << endl;
return 0;
}

User Pieter Van Ginkel
by
3.2k points

1 Answer

16 votes
16 votes

Answer:

To define the missing function, you can implement the CreateLicenseNum() function as follows:

void DogLicense::CreateLicenseNum(int customID) {

licenseNum = (100000 * customID) + licenseYear;

}

Once the CreateLicenseNum() function has been defined, the program can be run to generate a license number for a dog using the specified year and custom ID. For example, if the inputs 2014 and 777 are provided, the program would output the following:

Dog license: 77702014

Step-by-step explanation:

In summary, to define the missing function, you can implement the CreateLicenseNum() function as shown above. This function calculates the license number by multiplying the custom ID by 100000 and adding the year of registration to the result. This allows the program to generate a unique license number for each dog based on its custom ID and the year in which it was registered.

User ConnorU
by
3.2k points