How to Define the Missing Function in a Dog License Number Program?

  • Context: C/C++ 
  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
Click For Summary
SUMMARY

The forum discussion centers on implementing the missing function CreateLicenseNum in a C++ program for generating a dog license number. The correct implementation involves using the formula (100000 * customID) + licenseYear to assign the calculated value to the class member licenseNum. The final solution provided is void DogLicense::CreateLicenseNum(int customID) { licenseNum = (100000 * customID) + licenseYear; }, which resolves compilation issues by correctly utilizing the class's data member.

PREREQUISITES
  • Understanding of C++ class structures and member functions
  • Familiarity with variable scope and data member initialization
  • Knowledge of basic arithmetic operations in programming
  • Experience with compiling and debugging C++ code
NEXT STEPS
  • Study C++ class member functions and their scope
  • Learn about variable initialization and scope resolution in C++
  • Explore arithmetic operations and their implementation in C++
  • Practice debugging compilation errors in C++ programs
USEFUL FOR

C++ developers, students learning object-oriented programming, and anyone interested in understanding class member functions and variable scope in C++.

ineedhelpnow
Messages
649
Reaction score
0
i have another question i need help with :o
Define the missing function. licenseNumber is created as: (100000 * customID) + licenseYear. Sample output:

Dog license: 77702014
Sample program:
Code:
#include <iostream>
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;
   return;
}

// FIXME: Write CreateLicenseNum()
<STUDENT CODE> 

int DogLicense::GetLicenseNum() const {
   return licenseNum;
}

int main() {
   DogLicense dog1;
  
   dog1.SetYear(2014);
   dog1.CreateLicenseNum(777);
   cout << "Dog license: " << dog1.GetLicenseNum() << endl;

   return 0;
}

Below, do not type an entire program. Only type the portion indicated by the above instructions (and if a sample program is shown above, only type the <STUDENT CODE> portion.)

normally if i look at something long enough I am able to figure it out but this one just isn't clicking. how do i do it? :confused:
 
Technology news on Phys.org
ineedhelpnow said:
normally if i look at something long enough I am able to figure it out but this one just isn't clicking. how do i do it? :confused:

Hey! (Smile)

For CreateLicenseNum() we need to the same thing as is already there for SetYear().
But instead of simply copying the parameter, we need to calculate with the given formula what to store. (Thinking)
 
:confused: so something like this?
Code:
void DogLicense::CreateLicenseNum(int licenseNumber) {
   licenseNumber =  (100000 * customID) + licenseYear;
   return;
}
 
ineedhelpnow said:
:confused: so something like this?
Code:
void DogLicense::CreateLicenseNum(int licenseNumber) {
   licenseNumber =  (100000 * customID) + licenseYear;
   return;
}

Yep. Something like that. (Smile)
It's just that the parameter should be customID instead.
Just like it says in the class definition.
Otherwise it won't compile. (Worried)
 
you mean like this
Code:
void DogLicense::CreateLicenseNum(int customID) {
  int licenseNumber =  (100000 * customID) + licenseYear;
   return;
}
 
ineedhelpnow said:
you mean like this
Code:
void DogLicense::CreateLicenseNum(int customID) {
  int licenseNumber =  (100000 * customID) + licenseYear;
   return;
}

Yep. (Smile)

Except that you've introduced an 'int' that shouldn't be there.
 
but if i don't put int i get the message that 'licenseNumber’ was not declared in this scope. don't i have to use int to introduce the variable?
 
ineedhelpnow said:
but if i don't put int i get the message that 'licenseNumber’ was not declared in this scope. don't i have to use int to introduce the variable?

The class contains a data member named [m]licenseNum[/m], which is the one that needs to be initialized.
Perhaps you can change 'licenseNumber' into 'licenseNum'? (Wondering)
 
it finally worked!
Code:
void DogLicense::CreateLicenseNum(int customID) {
  licenseNum =  (100000 * customID) + licenseYear;
   return;
}

blowing-kiss-thank-you-smiley-emoticon.gif
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
8K
  • · Replies 35 ·
2
Replies
35
Views
4K
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K
Replies
4
Views
5K
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
12K
Replies
2
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K