C
cantide5ga
I am a student beginning C++ (also new to Newsgroups as well) and am
having a hell of a time understanding everything. My experience in OO
and UML from a prior class provide an understanding of what C++ COULD
do, but I can't seem to get past the coding aspect.
The program below is one of my assignments that is the beginning of an
Employee DB. It does what is asked, but not how it was asked:
//
**********************************************************************************************************************************
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
class EmployeeData
{
public:
const static int number = 100;
void getEmployee()
{
getStaffNumber();
for (int n = 1; n <= staffNumber; n++)
{
cout << "Input data for EMPLOYEE #" << n << endl;
arrayData = n;
getStaffName();
getStaffTitle();
getStaffWage();
getStaffHours();
cin.ignore( 1, '\n' );
}
}
void putEmployee()
{
for (int n = 1; n <= staffNumber; n++)
{
cout << "Data for EMPLOYEE #" << n << endl;
if (staffWage[n] > 20)
staffName[n] = staffName[n] + "*";
if (staffWage[n] * staffHours[n] > 800)
staffName[n] = staffName[n] + "*";
cout << "\nNAME\t: " << staffName[n];
cout << "\nTITLE\t: " << staffTitle[n];
cout << "\nPAY\t: $" << staffWage[n] * staffHours[n];
}
}
private:
string staffName[number];
string staffTitle[number];
double staffWage[number];
double staffHours[number];
int arrayData;
int staffNumber;
int getStaffNumber()
{
int number;
cout << "Please enter number of employees (max. 100): ";
cin >> number;
staffNumber = number;
cin.ignore( 1, '\n' );
return staffNumber;
}
string getStaffName()
{
string name;
cout << "Employee NAME\t: ";
getline(cin, name);
staffName[arrayData] = name;
return staffName[arrayData];
}
string getStaffTitle()
{
string title;
cout << "Employee TITLE\t: ";
getline(cin, title);
staffTitle[arrayData] = title;
return staffTitle[arrayData];
}
double getStaffWage()
{
double wage;
cout << "Employee WAGE\t: ";
cin >> wage;
staffWage[arrayData] = wage;
return staffWage[arrayData];
}
double getStaffHours()
{
double hours;
cout << "Employee HOURS\t: ";
cin >> hours;
staffHours[arrayData] = hours;
return staffHours[arrayData];
}
};
int main()
{
EmployeeData id0;
id0.getEmployee();
id0.putEmployee();
return 0;
}
//
**********************************************************************************************************************************
I *think* I should be able to somehow invoke a constructor to create
an object for each employee (with relative name, title, wage, and
hours data) but I can't wrap my head around the concept. The main
obstacle here is having a unique object name created for each
employee. After melting my brain for hours, I decided to just go with
my default idea and have one object containing a user defined amount
of arrays.
According to the assignment:
-Create and use a GetEmployee function that returns an employee
object. This function will prompt the user to enter data, store that
data in an object, and return the object to the calling function.
-Create and use a function that displays a list of employees and their
pay. This function will take an array of employee object as an
argument.
It sounds to me like I do indeed need to have an object for each
employee, because the display function will take it as an argument!
Oh man... any advice would be appreciated.
having a hell of a time understanding everything. My experience in OO
and UML from a prior class provide an understanding of what C++ COULD
do, but I can't seem to get past the coding aspect.
The program below is one of my assignments that is the beginning of an
Employee DB. It does what is asked, but not how it was asked:
//
**********************************************************************************************************************************
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
class EmployeeData
{
public:
const static int number = 100;
void getEmployee()
{
getStaffNumber();
for (int n = 1; n <= staffNumber; n++)
{
cout << "Input data for EMPLOYEE #" << n << endl;
arrayData = n;
getStaffName();
getStaffTitle();
getStaffWage();
getStaffHours();
cin.ignore( 1, '\n' );
}
}
void putEmployee()
{
for (int n = 1; n <= staffNumber; n++)
{
cout << "Data for EMPLOYEE #" << n << endl;
if (staffWage[n] > 20)
staffName[n] = staffName[n] + "*";
if (staffWage[n] * staffHours[n] > 800)
staffName[n] = staffName[n] + "*";
cout << "\nNAME\t: " << staffName[n];
cout << "\nTITLE\t: " << staffTitle[n];
cout << "\nPAY\t: $" << staffWage[n] * staffHours[n];
}
}
private:
string staffName[number];
string staffTitle[number];
double staffWage[number];
double staffHours[number];
int arrayData;
int staffNumber;
int getStaffNumber()
{
int number;
cout << "Please enter number of employees (max. 100): ";
cin >> number;
staffNumber = number;
cin.ignore( 1, '\n' );
return staffNumber;
}
string getStaffName()
{
string name;
cout << "Employee NAME\t: ";
getline(cin, name);
staffName[arrayData] = name;
return staffName[arrayData];
}
string getStaffTitle()
{
string title;
cout << "Employee TITLE\t: ";
getline(cin, title);
staffTitle[arrayData] = title;
return staffTitle[arrayData];
}
double getStaffWage()
{
double wage;
cout << "Employee WAGE\t: ";
cin >> wage;
staffWage[arrayData] = wage;
return staffWage[arrayData];
}
double getStaffHours()
{
double hours;
cout << "Employee HOURS\t: ";
cin >> hours;
staffHours[arrayData] = hours;
return staffHours[arrayData];
}
};
int main()
{
EmployeeData id0;
id0.getEmployee();
id0.putEmployee();
return 0;
}
//
**********************************************************************************************************************************
I *think* I should be able to somehow invoke a constructor to create
an object for each employee (with relative name, title, wage, and
hours data) but I can't wrap my head around the concept. The main
obstacle here is having a unique object name created for each
employee. After melting my brain for hours, I decided to just go with
my default idea and have one object containing a user defined amount
of arrays.
According to the assignment:
-Create and use a GetEmployee function that returns an employee
object. This function will prompt the user to enter data, store that
data in an object, and return the object to the calling function.
-Create and use a function that displays a list of employees and their
pay. This function will take an array of employee object as an
argument.
It sounds to me like I do indeed need to have an object for each
employee, because the display function will take it as an argument!
Oh man... any advice would be appreciated.