SlideShare a Scribd company logo
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.pdf
feelingspaldi
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
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
fashionscollect
 
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
Oluwaleke 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 Melayi
Muhammed 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.pdf
adityastores21
 
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
Thuan Nguyen
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
piyush Kumar Sharma
 
Basic Sql Handouts
Basic Sql HandoutsBasic Sql Handouts
Basic Sql Handouts
jhe04
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
Information Technology
 
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
Thuan 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.pdf
ARORACOCKERY2111
 
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
arihantgiftgallery
 
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
fashionfolionr
 
Whats New In C# 3.0
Whats New In C# 3.0Whats New In C# 3.0
Whats New In C# 3.0
Clint Edmonson
 
Chapter 2
Chapter 2Chapter 2
perl usage at database applications
perl usage at database applicationsperl usage at database applications
perl usage at database applications
Joe 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.pdf
atozworkwear
 
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
eyewaregallery
 
CoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love AffairCoffeeScript - A Rubyist's Love Affair
CoffeeScript - A Rubyist's Love Affair
Mark
 

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.pdf
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 
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
petercoiffeur18
 

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

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
sayalidalavi006
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5Community pharmacy- Social and preventive pharmacy UNIT 5
Community pharmacy- Social and preventive pharmacy UNIT 5
 

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 <