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

Discussion Overview

The discussion revolves around defining a missing function, CreateLicenseNum, in a Dog License Number program. Participants explore how to implement this function correctly within the context of a class structure in C++ programming.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses difficulty in understanding how to implement the CreateLicenseNum function.
  • Another participant suggests that the function should calculate the license number using the provided formula, indicating a need for a calculation rather than a simple assignment.
  • A proposed implementation incorrectly uses a parameter name that does not match the class definition, leading to a compilation issue.
  • Participants discuss the need to use the class member variable licenseNum instead of introducing a new local variable.
  • Ultimately, a participant successfully implements the function by correctly assigning the calculated value to the class member licenseNum.

Areas of Agreement / Disagreement

Participants generally agree on the need to calculate the license number using the given formula, but there are disagreements regarding variable scope and naming conventions. The discussion reflects multiple iterations and corrections without a single definitive solution until the final implementation is accepted.

Contextual Notes

There are limitations regarding variable scope and member variable usage that are addressed through participant feedback. The discussion highlights the importance of understanding class member variables 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