SlideShare a Scribd company logo
1 of 8
Download to read offline
I am trying to change this code from STRUCTS to CLASSES, the members have to be private.
Well, I think I did a semi-ok job; the code doesn't run and I have no idea why. Can you please
help. Platform: C++
========== C++ CODE ============
#include
#include
#include
#include
#include //must have to use system ("pause" );
//#include "personType.h"
using namespace std;
const int MAX_EMPLOYEES = 50;
//----------------------------------
class employeeType{ //:public personType
private:
long empID;
string first;
string last;
char gender;
double payrate;
string jobRole;
int years;
public:
virtual void programmer_info() const=0;
//Function to output employee's data
virtual double cutBacks(employeeType let[], int listsize) const=0;
//Function to calculate and return the wages.
//Postcondition: Pay is calculated and returned
void yourFired(employeeType let[], int& listsize , long id); //int& cuz we are restando
cantidades de la lista.
//Function to set the salary. /Postcondition: personId = id
long seqSearch(employeeType let[], int listLength, int searchItem)const;
//Function to retrieve the id. /Postcondition: returns personID
employeeType (long id = 0, string first = "", string last = "", char gender = "",
double payrate = 0, string jobRole = "",int years = 0);
//Ibefore it was: userinput();
//Constructor with parameters //Sets the first name, last name, payRate, and
//hoursWorked according to the parameters. If no value is specified, the default
//values are assumed. //Postcondition: firstName = first;
///==============================================================
void getData(ifstream& inFile, class employeeType let[], int& listSize);
void printOne ( employeeType one);
void hireOne(employeeType let[], int& listsize); //int& cuz we are adding or restyando
cantidades de la lista.
void selectionSort( employeeType let[], int length);
void printList(employeeType let[], int listSize);
employeeType getOne ( ifstream& dataIn );
};
///===============================================================
void employeeType::yourFired(long id)
{
empID = id;
}
long employeeType::seqSearch() const
{
return empID;
}
employeeType::employeeType(long id, string first, string last, char gender,
double, string jobRole,int years)
: personType(first, last)
{
empID = id;
}
//----------------------------------
int main ()
{
int number; // number of employees in the file
int id;
char choice;
class employeeType [MAX_EMPLOYEES], newrecord;
ifstream dataFile;
dataFile.open ( "newEmployees.txt");
if (!dataFile){
cout << " Error with input file!!  ";
//system ("pause"); // must #include
return 1;
}
getData (dataFile, employeeType, number);
cout < to be used
/// TASK 3 =======================================================
for(int i =0; i<3 ; i++){ //calling hireOne 3 times, you can insert 3 new employees on a roll
hireOne(employeeType, number); // the list increases by up to 3 new records each time
}
cout << "After hiring employees, new list:  "<> id;
yourFired(employeeType, number, id);
cout << " The new employee list after firing employee ID:  "
<> one.first >> one.last >> one.gender
>> one.id >> one.payrate >> one.jobRole >> one.years;
printOne(one);
return one;
}
//----------------------------------------------
void printOne ( employeeType one){ //printOne is keep on a loop, use in the structure on the
array printList.
//print out one menuItemType struct
cout << fixed << showpoint << setprecision (2);
cout << "Emp ID Num: " <> data.id;
cout<< " Enter employee First and Last Name: "<> data.first>>data.last;
cout << " Enter employee gender: "<> data.gender;
cout << " Enter employee Job role: "<> data.jobRole;/// TASK 3
=======================================================
cout << " Enter employee Pay rate: "<> data.payrate;
cout << " Enter employee years: "<> data.years;
cout << " ";
//data.blabla .... the diff variables after the 'dot' get consolidated into 'data'
return data; //consolidates all (name, last payrate, gender,etc) together into 'data' as a whole
pack of info.
}
/// TASK 3
void hireOne(employeeType let[], int& listsize){
int location;
employeeType newrecord;
cout <<" Enter the location of the new employee should be inserted"<>location;
if(location >= 0 && location < listsize){
newrecord = userinput(); //calling userinput to read/store the newrecord values
for( int i = listsize -1 ; i>= location ; i--)
let[i+1] = let [i];
let[location] = newrecord;
listsize++; //adding a new element to the list, the size of the array increases
} //end of if
else
cout <<" You entered a wrong location"<
Solution
Hii,
I am replying late because the correction took a long time. The major problem with your code
was accessing the private members of employee class by functions which were global. So I had
to modify some lines for the function and the structure of the program accordingly.
Just see if its serving your purpose of what you intended. One good thing it would be if the
employee data are also written to the file before closing the program, thats a good practice of
writing program. That implementation will make the program better, although not necessary
now.
Also make a new text file called "newEmployees.txt" under the same directory where the
program resides and paste these lines. Remember don't press enter after the last line:
Jason Bourne M 8088 81.30 Cyber-Security 2
Bob Beezer M 1234 12.91 ComputerScience 3
Ron Cook M 7841 30.23 Web-Design 4
Alex Musk M 4561 56.15 Electronics 3
The edited program is here(you can copy paste it directly). Please comment if there are any
issues.
#include
#include
#include
#include
#include //must have to use system ("pause" );
//#include "personType.h"
using namespace std;
const int MAX_EMPLOYEES = 50;
// class definition
// class employeeType is misleading, just employee is better
class employee{
private:
long emp_id;
string first_name;
string last_name;
char gender;
double payrate;
string jobrole;
int years;
public:
// constructor with default arguments
employee(long id = 0, string f_name = "", string l_name = "", char gen = ' ',double rate = 0,
string role = "",int yr = 0)
{
emp_id = id;
first_name = f_name;
last_name = l_name;
gender = gen;
payrate = rate;
jobrole = role;
years = yr;
}
// class methods that are required to access the private members
void print_emp();
void askinput();
double get_payrate();
void modify_payrate(double);
long get_emp_id();
};
// global function declaration i.e., these doesn't come under class employee as was in the given
program
// global functions can't access employee private members
void cutBacks(employee let[], int listsize);
void selectionSort( employee e[], int length);
void hireOne(employee e[], int& listsize);
employee userinput();
void printOne(employee one);
void printList(employee e[],int n);
employee getOne(ifstream& dataIn);
void getData(ifstream& inFile, employee e[], int* listSize);
void yourFired(employee e_list[], int& listsize , int id);
int seqSearch(employee e[], int listLength, int searchItem);
void programmer_info();
// class function definitions
double employee::get_payrate(){
return payrate;
}
void employee::modify_payrate(double m_factor){
payrate = payrate * m_factor;
return;
}
long employee::get_emp_id(){
return emp_id;
}
void employee::print_emp(){
// This will print the information of one employee data
cout << fixed << showpoint << setprecision (2);
cout << " Emp ID Num: " <> emp_id;
cout<< " Enter employee First and Last Name: "<> first_name>>last_name;
cout << " Enter employee gender (M or F): "<> gender;
cout << " Enter employee Job role: "<> jobrole;
cout << " Enter employee Pay rate: "<> payrate;
cout << " Enter employee years: "<> years;
cout << " ";
return;
}
int main ()
{
int number; // number of employees in the file
int id;
char choice;
employee emp_list[MAX_EMPLOYEES], newrecord; // declaring two variables of class
employee, one is array and other is a variable
ifstream dataFile;
dataFile.open("newEmployees.txt");
if (!dataFile){
cout << " Error with input file!!  ";
return 1;
}
getData(dataFile, emp_list, &number);
printList(emp_list, number);
cout < to be used
// TASK 3 =======================================================
for(int i =0; i<1 ; i++){ //calling hireOne 3 times, you can insert 3 new employees on a roll
hireOne(emp_list, number); // the list increases by up to 3 new records each time
}
cout << "After hiring employees, new list:  "<> id;
yourFired(emp_list, number, id);
cout << " The new employee list after firing employee ID "<>location;
if(location > 0 && location < listsize){
newrecord = userinput(); //calling userinput to read/store the newrecord values
for( int i = listsize-1 ; i>= location-1 ; i--)
e[i+1] = e[i];
e[location-1] = newrecord;
listsize++; //adding a new element to the list, the size of the array increases
} //end of if
else
cout <<" You entered a wrong location"<> f_name >> l_name >> gen >> id >> rate >> role
>> yr;
employee e(id, f_name, l_name, gen, rate, role, yr);
//e.print_emp();
return e;
}
void getData(ifstream& inFile, employee e[], int* listSize){
// Input employees from the input file
employee item ;
*listSize = 0;
while (!inFile.eof() && (*listSize < MAX_EMPLOYEES))
{
item = getOne(inFile);
e[*listSize] = item ;
(*listSize)++;
cout <<" Current Size = "<< *listSize <

More Related Content

Similar to I am trying to change this code from STRUCTS to CLASSES, the members.pdf

Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdffeelingspaldi
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdffashionscollect
 
All you need to know about JavaScript Functions
All you need to know about JavaScript FunctionsAll you need to know about JavaScript Functions
All you need to know about JavaScript FunctionsOluwaleke Fakorede
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfadityastores21
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Thuan Nguyen
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handoutsjhe04
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Thuan Nguyen
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfARORACOCKERY2111
 
Write a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfWrite a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfarihantgiftgallery
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdfUsing C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdffashionfolionr
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applicationsJoe Jiang
 
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
from datetime import datetime def CreateUsers()-     print('##### Crea.pdffrom datetime import datetime def CreateUsers()-     print('##### Crea.pdf
from datetime import datetime def CreateUsers()- print('##### Crea.pdfatozworkwear
 
So basically I worked really hard on this code in my CS150 class and.pdf
So basically I worked really hard on this code in my CS150 class and.pdfSo basically I worked really hard on this code in my CS150 class and.pdf
So basically I worked really hard on this code in my CS150 class and.pdfeyewaregallery
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairMark
 

Similar to I am trying to change this code from STRUCTS to CLASSES, the members.pdf (20)

Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
Clean code
Clean codeClean code
Clean code
 
Should be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdfShould be in JavaInterface Worker should extend Serializable from .pdf
Should be in JavaInterface Worker should extend Serializable from .pdf
 
All you need to know about JavaScript Functions
All you need to know about JavaScript FunctionsAll you need to know about JavaScript Functions
All you need to know about JavaScript Functions
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Make sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdfMake sure to make a copy of the Google Doc for this lab into.pdf
Make sure to make a copy of the Google Doc for this lab into.pdf
 
Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09Oracle - Program with PL/SQL - Lession 09
Oracle - Program with PL/SQL - Lession 09
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05Oracle - Program with PL/SQL - Lession 05
Oracle - Program with PL/SQL - Lession 05
 
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdfSummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
SummaryHW6 Account ManagementIn HW4, you kept track of multiple.pdf
 
Write a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdfWrite a C++ program with a function defined to give the person a .pdf
Write a C++ program with a function defined to give the person a .pdf
 
Using C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdfUsing C++...Hints- Use binary file readwrite to store employee .pdf
Using C++...Hints- Use binary file readwrite to store employee .pdf
 
Whats New In C# 3.0
Whats New In C# 3.0Whats New In C# 3.0
Whats New In C# 3.0
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
 
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
from datetime import datetime def CreateUsers()-     print('##### Crea.pdffrom datetime import datetime def CreateUsers()-     print('##### Crea.pdf
from datetime import datetime def CreateUsers()- print('##### Crea.pdf
 
So basically I worked really hard on this code in my CS150 class and.pdf
So basically I worked really hard on this code in my CS150 class and.pdfSo basically I worked really hard on this code in my CS150 class and.pdf
So basically I worked really hard on this code in my CS150 class and.pdf
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
 

More from petercoiffeur18

John, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfJohn, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfpetercoiffeur18
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfpetercoiffeur18
 
In what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfIn what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfpetercoiffeur18
 
i need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfi need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfpetercoiffeur18
 
how internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfhow internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfpetercoiffeur18
 
For an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfFor an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfpetercoiffeur18
 
Exercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfExercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfpetercoiffeur18
 
Discuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfDiscuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfpetercoiffeur18
 
C++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfC++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfpetercoiffeur18
 
any idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfany idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfpetercoiffeur18
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfpetercoiffeur18
 
A radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfA radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfpetercoiffeur18
 
21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdfpetercoiffeur18
 
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfCase 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfpetercoiffeur18
 
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfx , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfpetercoiffeur18
 
Why would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfWhy would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfpetercoiffeur18
 
When discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfWhen discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfpetercoiffeur18
 
What relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfWhat relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfpetercoiffeur18
 
what is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfwhat is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfpetercoiffeur18
 
What are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfWhat are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfpetercoiffeur18
 

More from petercoiffeur18 (20)

John, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdfJohn, a sociologist, will be focusing on how larger societal institu.pdf
John, a sociologist, will be focusing on how larger societal institu.pdf
 
Implement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdfImplement the ListArray ADT-Implement the following operations.pdf
Implement the ListArray ADT-Implement the following operations.pdf
 
In what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdfIn what ways do humans effect the environment Explain in 200 words.pdf
In what ways do humans effect the environment Explain in 200 words.pdf
 
i need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdfi need a taking turn method for a player vs computer battleship game.pdf
i need a taking turn method for a player vs computer battleship game.pdf
 
how internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdfhow internal resources and capabilities can be a source of sustainab.pdf
how internal resources and capabilities can be a source of sustainab.pdf
 
For an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdfFor an organism that is growing using glucose as the electron donor, .pdf
For an organism that is growing using glucose as the electron donor, .pdf
 
Exercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdfExercise 5.6.28. For each of the following descriptions of a function.pdf
Exercise 5.6.28. For each of the following descriptions of a function.pdf
 
Discuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdfDiscuss concepts associated with mercantilism demonstrating key poli.pdf
Discuss concepts associated with mercantilism demonstrating key poli.pdf
 
C++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdfC++ Caesar Cipher project. Write your codes for the following functi.pdf
C++ Caesar Cipher project. Write your codes for the following functi.pdf
 
any idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdfany idea#includeiostream using stdcout; using stdendl; .pdf
any idea#includeiostream using stdcout; using stdendl; .pdf
 
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdfa) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
a) Use Newton’s Polynomials for Evenly Spaced data to derive the O(h.pdf
 
A radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdfA radio station has a power output of 200 watts. What is the intensit.pdf
A radio station has a power output of 200 watts. What is the intensit.pdf
 
21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf21) What are the fundamental particles of lepton and quarks How man.pdf
21) What are the fundamental particles of lepton and quarks How man.pdf
 
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdfCase 1-A Transition to SupervisorTristan came in on the ground fl.pdf
Case 1-A Transition to SupervisorTristan came in on the ground fl.pdf
 
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdfx , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
x , y Midterm Exsm-201840x Exam C httpsbb-montgomerycollege.blac.pdf
 
Why would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdfWhy would a cell want to express genes in an operon Why notSol.pdf
Why would a cell want to express genes in an operon Why notSol.pdf
 
When discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdfWhen discussing the epidemiology of virus infections, the CDC often .pdf
When discussing the epidemiology of virus infections, the CDC often .pdf
 
What relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdfWhat relationship is there between gobalization and development.pdf
What relationship is there between gobalization and development.pdf
 
what is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdfwhat is the number between 4.5 and 4.75 on the number linew.pdf
what is the number between 4.5 and 4.75 on the number linew.pdf
 
What are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdfWhat are the five main goals for Operations Managers, and how do the.pdf
What are the five main goals for Operations Managers, and how do the.pdf
 

Recently uploaded

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 

I am trying to change this code from STRUCTS to CLASSES, the members.pdf

  • 1. I am trying to change this code from STRUCTS to CLASSES, the members have to be private. Well, I think I did a semi-ok job; the code doesn't run and I have no idea why. Can you please help. Platform: C++ ========== C++ CODE ============ #include #include #include #include #include //must have to use system ("pause" ); //#include "personType.h" using namespace std; const int MAX_EMPLOYEES = 50; //---------------------------------- class employeeType{ //:public personType private: long empID; string first; string last; char gender; double payrate; string jobRole; int years; public: virtual void programmer_info() const=0; //Function to output employee's data virtual double cutBacks(employeeType let[], int listsize) const=0; //Function to calculate and return the wages. //Postcondition: Pay is calculated and returned void yourFired(employeeType let[], int& listsize , long id); //int& cuz we are restando cantidades de la lista. //Function to set the salary. /Postcondition: personId = id long seqSearch(employeeType let[], int listLength, int searchItem)const; //Function to retrieve the id. /Postcondition: returns personID employeeType (long id = 0, string first = "", string last = "", char gender = "",
  • 2. double payrate = 0, string jobRole = "",int years = 0); //Ibefore it was: userinput(); //Constructor with parameters //Sets the first name, last name, payRate, and //hoursWorked according to the parameters. If no value is specified, the default //values are assumed. //Postcondition: firstName = first; ///============================================================== void getData(ifstream& inFile, class employeeType let[], int& listSize); void printOne ( employeeType one); void hireOne(employeeType let[], int& listsize); //int& cuz we are adding or restyando cantidades de la lista. void selectionSort( employeeType let[], int length); void printList(employeeType let[], int listSize); employeeType getOne ( ifstream& dataIn ); }; ///=============================================================== void employeeType::yourFired(long id) { empID = id; } long employeeType::seqSearch() const { return empID; } employeeType::employeeType(long id, string first, string last, char gender, double, string jobRole,int years) : personType(first, last) { empID = id; } //---------------------------------- int main () { int number; // number of employees in the file int id; char choice; class employeeType [MAX_EMPLOYEES], newrecord;
  • 3. ifstream dataFile; dataFile.open ( "newEmployees.txt"); if (!dataFile){ cout << " Error with input file!! "; //system ("pause"); // must #include return 1; } getData (dataFile, employeeType, number); cout < to be used /// TASK 3 ======================================================= for(int i =0; i<3 ; i++){ //calling hireOne 3 times, you can insert 3 new employees on a roll hireOne(employeeType, number); // the list increases by up to 3 new records each time } cout << "After hiring employees, new list: "<> id; yourFired(employeeType, number, id); cout << " The new employee list after firing employee ID: " <> one.first >> one.last >> one.gender >> one.id >> one.payrate >> one.jobRole >> one.years; printOne(one); return one; } //---------------------------------------------- void printOne ( employeeType one){ //printOne is keep on a loop, use in the structure on the array printList. //print out one menuItemType struct cout << fixed << showpoint << setprecision (2); cout << "Emp ID Num: " <> data.id; cout<< " Enter employee First and Last Name: "<> data.first>>data.last; cout << " Enter employee gender: "<> data.gender; cout << " Enter employee Job role: "<> data.jobRole;/// TASK 3 ======================================================= cout << " Enter employee Pay rate: "<> data.payrate; cout << " Enter employee years: "<> data.years; cout << " "; //data.blabla .... the diff variables after the 'dot' get consolidated into 'data'
  • 4. return data; //consolidates all (name, last payrate, gender,etc) together into 'data' as a whole pack of info. } /// TASK 3 void hireOne(employeeType let[], int& listsize){ int location; employeeType newrecord; cout <<" Enter the location of the new employee should be inserted"<>location; if(location >= 0 && location < listsize){ newrecord = userinput(); //calling userinput to read/store the newrecord values for( int i = listsize -1 ; i>= location ; i--) let[i+1] = let [i]; let[location] = newrecord; listsize++; //adding a new element to the list, the size of the array increases } //end of if else cout <<" You entered a wrong location"< Solution Hii, I am replying late because the correction took a long time. The major problem with your code was accessing the private members of employee class by functions which were global. So I had to modify some lines for the function and the structure of the program accordingly. Just see if its serving your purpose of what you intended. One good thing it would be if the employee data are also written to the file before closing the program, thats a good practice of writing program. That implementation will make the program better, although not necessary now. Also make a new text file called "newEmployees.txt" under the same directory where the program resides and paste these lines. Remember don't press enter after the last line: Jason Bourne M 8088 81.30 Cyber-Security 2 Bob Beezer M 1234 12.91 ComputerScience 3 Ron Cook M 7841 30.23 Web-Design 4 Alex Musk M 4561 56.15 Electronics 3 The edited program is here(you can copy paste it directly). Please comment if there are any issues. #include
  • 5. #include #include #include #include //must have to use system ("pause" ); //#include "personType.h" using namespace std; const int MAX_EMPLOYEES = 50; // class definition // class employeeType is misleading, just employee is better class employee{ private: long emp_id; string first_name; string last_name; char gender; double payrate; string jobrole; int years; public: // constructor with default arguments employee(long id = 0, string f_name = "", string l_name = "", char gen = ' ',double rate = 0, string role = "",int yr = 0) { emp_id = id; first_name = f_name; last_name = l_name; gender = gen; payrate = rate; jobrole = role; years = yr; } // class methods that are required to access the private members void print_emp(); void askinput(); double get_payrate(); void modify_payrate(double);
  • 6. long get_emp_id(); }; // global function declaration i.e., these doesn't come under class employee as was in the given program // global functions can't access employee private members void cutBacks(employee let[], int listsize); void selectionSort( employee e[], int length); void hireOne(employee e[], int& listsize); employee userinput(); void printOne(employee one); void printList(employee e[],int n); employee getOne(ifstream& dataIn); void getData(ifstream& inFile, employee e[], int* listSize); void yourFired(employee e_list[], int& listsize , int id); int seqSearch(employee e[], int listLength, int searchItem); void programmer_info(); // class function definitions double employee::get_payrate(){ return payrate; } void employee::modify_payrate(double m_factor){ payrate = payrate * m_factor; return; } long employee::get_emp_id(){ return emp_id; } void employee::print_emp(){ // This will print the information of one employee data cout << fixed << showpoint << setprecision (2); cout << " Emp ID Num: " <> emp_id; cout<< " Enter employee First and Last Name: "<> first_name>>last_name; cout << " Enter employee gender (M or F): "<> gender; cout << " Enter employee Job role: "<> jobrole; cout << " Enter employee Pay rate: "<> payrate;
  • 7. cout << " Enter employee years: "<> years; cout << " "; return; } int main () { int number; // number of employees in the file int id; char choice; employee emp_list[MAX_EMPLOYEES], newrecord; // declaring two variables of class employee, one is array and other is a variable ifstream dataFile; dataFile.open("newEmployees.txt"); if (!dataFile){ cout << " Error with input file!! "; return 1; } getData(dataFile, emp_list, &number); printList(emp_list, number); cout < to be used // TASK 3 ======================================================= for(int i =0; i<1 ; i++){ //calling hireOne 3 times, you can insert 3 new employees on a roll hireOne(emp_list, number); // the list increases by up to 3 new records each time } cout << "After hiring employees, new list: "<> id; yourFired(emp_list, number, id); cout << " The new employee list after firing employee ID "<>location; if(location > 0 && location < listsize){ newrecord = userinput(); //calling userinput to read/store the newrecord values for( int i = listsize-1 ; i>= location-1 ; i--) e[i+1] = e[i]; e[location-1] = newrecord; listsize++; //adding a new element to the list, the size of the array increases } //end of if else
  • 8. cout <<" You entered a wrong location"<> f_name >> l_name >> gen >> id >> rate >> role >> yr; employee e(id, f_name, l_name, gen, rate, role, yr); //e.print_emp(); return e; } void getData(ifstream& inFile, employee e[], int* listSize){ // Input employees from the input file employee item ; *listSize = 0; while (!inFile.eof() && (*listSize < MAX_EMPLOYEES)) { item = getOne(inFile); e[*listSize] = item ; (*listSize)++; cout <<" Current Size = "<< *listSize <