0

Hey guys

How can I input a data field into a class
Is it with the use of (int)?

Here is the question

Design a job class with three data fields--Job number, time in hours to complete the Job, and rate per hour charged for the Job.


#include<iostream.h>
#include<conio.h>
class Job
{
private:
int JobNum;
int Hours;
double Rate;
};

Would this be correct?

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by HelpMeImLost
0

There are lots of ways to do it, here is just one of them. The class will need public access to the private variables only if something outside the class needs access to those variables, and that's the purpose of the Get() and Set() methods.

#include<iostream>
using namespace std;

class Job
{
public:
  Job() 
  {
     JobNum = Hours = 0;
     Rate = 0;
  }
  int GetJobNum() {return JobNum;}
  int GetHours() {return Hours;}
  double GetRate() {return Rate;}
  void SetJobNum(int jn) {JobNum = jn;}
  void SetHours(int h) {Hours = h;}
  void SetRate(double r) {Rate = r;}
private:
 int JobNum;
 int Hours;
 double Rate;
};
0

There are lots of ways to do it, here is just one of them. The class will need public access to the private variables only if something outside the class needs access to those variables, and that's the purpose of the Get() and Set() methods.

#include<iostream>
using namespace std;

class Job
{
public:
  Job() 
  {
     JobNum = Hours = 0;
     Rate = 0;
  }
  int GetJobNum() {return JobNum;}
  int GetHours() {return Hours;}
  double GetRate() {return Rate;}
  void SetJobNum(int jn) {JobNum = jn;}
  void SetHours(int h) {Hours = h;}
  void SetRate(double r) {Rate = r;}
private:
 int JobNum;
 int Hours;
 double Rate;
};

I was looking into doing it like that, but I didn't want to confuse myself, being that i'm new to this.

Thank You :-)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.