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?

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;
};

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 :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.