C++ Polymorphism Employee Project - c++

For class I have to adapt a program I wrote last week for polymorphism. Last week it used a specific set of information for the employees but now I have to make it work with polymorphism as well as read/write data from a file, I am completely lost with what I am supposed to be doing, If someone could even point me in the right direction it would be so much help. I can post my current .h and .cpp file for a look at what I have as well as the instructions of what I am supposed to be doing.
.h
#pragma once
#include <string>
using namespace std;
class Employee {
private:
int employeeNumber; // Employee's employee number
string employeeName; //Employee's name
string streetAddress; //Employee's street address
string phoneNumber; //Employee's phone number
double hourlyWage; //Employee's hourly wage
double hoursWorked; //Employee's hours worked
double netPay; //Net pay
double grossPay; //Gross pay
public:
Employee();
Employee(int, string, string, string, double, double);
int getEmployeeNumber();
void setEmployeeNumber(int);
string getEmployeeName();
void setEmployeeName(string);
string getStreetAddress();
void setStreetAddress(string);
string getPhoneNumber();
void setPhoneNumber(string);
double getHourlyWage();
void setHourlyWage(double);
double getHoursWorked();
void setHoursWorked(double);
double calcPay()
{
const int OVER = 40;
double federal = 0.20;
double state = 0.075;
double timeHalf = 1.5;
double grossPay;
double netPay;
if (getHoursWorked() < OVER)
{
grossPay = getHoursWorked() * getHourlyWage();
netPay = grossPay - (grossPay * federal) - (grossPay * state);
}
if (getHoursWorked() >= OVER)
{
grossPay = getHoursWorked() * ((getHourlyWage() * timeHalf));
netPay = grossPay - (grossPay * federal) - (grossPay * state);
}
return netPay;
}
};
.cpp
#include <iostream>
#include <string>
#include <fstream>
#include "Employee.h"
#include <iomanip>
using namespace std;
Employee::Employee()
{
employeeNumber = 0; // Employee's employee number
employeeName = ""; //Employee's name
streetAddress = ""; //Employee's street address
phoneNumber = ""; //Employee's phone number
hourlyWage = 0; //Employee's hourly wage
hoursWorked = 0;
grossPay = 0;
netPay = 0;
}
Employee::Employee(int empNum, string empName, string streetAddress,
string phoneNumber, double hourlyWage, double hoursWorked)
{
employeeNumber = empNum;
employeeName = empName;
this->streetAddress = streetAddress;
this->phoneNumber = phoneNumber;
this->hourlyWage = hourlyWage;
this->hoursWorked = hoursWorked;
grossPay = 0;
netPay = 0;
}
int Employee::getEmployeeNumber()
{
return employeeNumber;
}
void Employee::setEmployeeNumber(int empNum)
{
employeeNumber = empNum;
}
string Employee::getEmployeeName()
{
return employeeName;
}
void Employee::setEmployeeName(string empName)
{
employeeName = empName;
}
string Employee::getStreetAddress()
{
return streetAddress;
}
void Employee::setStreetAddress(string strtAddrs)
{
streetAddress = strtAddrs;
}
string Employee::getPhoneNumber()
{
return phoneNumber;
}
void Employee::setPhoneNumber(string phnNum)
{
phoneNumber = phnNum;
}
double Employee::getHourlyWage()
{
return hourlyWage;
}
void Employee::setHourlyWage(double hrWage)
{
hourlyWage = hrWage;
}
double Employee::getHoursWorked()
{
return hoursWorked;
}
void Employee::setHoursWorked(double hrWorked)
{
hoursWorked = hrWorked;
}
void printCheck(Employee ee)
{
cout << "\n\n--------------------- Fluff Shuffle Electronics -------------------------------- \n";
cout << " Pay to the order of " << ee.getEmployeeName() << "...........................$" << ee.calcPay();
cout << "\n\n United Bank of Eastern Orem \n";
cout << "------------------------------------------------------------------------------- \n";
cout << " Hours Worked: " << ee.getHoursWorked();
cout << "\n Hourly Wage: " << ee.getHourlyWage();
cout << endl << endl;
}//End of function
void read(ifstream &in)
{
Employee employees[10];
int counter = 0;
while (in.read((char *)&employees[counter++], sizeof(Employee)))
for (int i = 0; i<counter; i++)
{
printCheck(employees[i]);
}
in.close();
}
void write(ofstream &out)
{
Instantiate your employees here first, then call their functions.
Employee joe(37, "Joe Brown", "123 Main St.", "123-6788", 10.00,
45.00);
printCheck(joe);
Employee sam(21, "Sam Jones", "45 East State", "661-9000", 12.00,
30.00);
printCheck(sam);
Employee mary(15, "Mary Smith", "12 High Street", "401-8900", 15.00, 40.00);
printCheck(mary);
out.write((char *)(&joe), sizeof(Employee));
out.write((char *)(&sam), sizeof(Employee));
out.write((char *)(&mary), sizeof(Employee));
out.close();
}
//Main function
int main()
{
int choice;
string filename;
while (true)
{
cout << "\nThis program has two options:\n";
cout << "1 - Create a data file, or\n";
cout << "2 - Read data from a file and print paychecks\n";
cout << "\n Press any other key to quit..........\n";
cout << "Please enter <1> to create a file or <2> to print
checks: ";
cin >> choice;
if (choice == 1)
{
cout << "Enter the file name: ";
cin >> filename;
ofstream out(filename);
out.open(filename.c_str(), ios::binary);
write(out);
}
else if (choice == 2)
{
cout << "Enter the file name: ";
cin >> filename;
ifstream in(filename);
in.open(filename.c_str(), ios::binary);
read(in);
}
else break;
//Calls function to displays information
}
}//End of main
These are the instructions for the project.
This is the diagram it refers to

To start: create two classes derived from Employee:
class HourlyEmployee: public Employee
{
};
class SalariedEmployee: public Employee
{
}
and move members related to Hourly working from Employee to HourlyEmployee, then add members related to Salary to SalariedEmployee (WeeklySalary).
This way (removing attributes related to hourly working) you make Employee class more general that can be a base for other kind of employees to (SalariedEmployee).
When you derive HourlyEmployee or SalariedEmployee from Employee, you mean they are kind of Employee, so members that Employee has, they will inherit automatically.

Related

My c++ code gives the following error (error: no matching function for call to ‘Bank::Bank()’) [duplicate]

This question already has answers here:
Default constructor error no matching function for call to
(2 answers)
C++ array of a self-defined class, no matching function call
(3 answers)
no matching function to call for "constructor"
(1 answer)
Closed last year.
I'm a beginner in c++. Though the code is still incomplete, I would like to know why I'm not able to create an array to store my objects from the class. I have to store 5 bank accounts in an array and I was trying to do so by soring the objects but it keeps showing error.
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
class Bank
{
string depositor;
int accno;
char type;
float balance;
public:
Bank(string depositor, int accno, char type, float balance); //to assign initial values
void deposit(); //to deposit amount
float withdraw(); //to withdraw amount
void show(); //to show name and balance
Bank(string depositor, int accno); //constructor function for name and account no.
Bank(float balance, int accno); //constructor function for balance and account no.
Bank(char type, int accno); //constructor function for type and account no.
Bank(const Bank&); //copy constructor
//getter and setter functions for all data members
void setname(string depositor);
void setacc(int accno);
void settype(char type);
void setbal(float balance);
string getname();
int getacc();
char gettype();
float getbal();
};
Bank::Bank(string depos, int acno, char typ, float bal)
{
depositor=depos;
accno = acno;
type = typ;
balance = bal ? bal : 0;
}
void Bank::deposit()
{
float damt1;
cout << "Enter deposit amount: ";
cin >> damt1;
if (damt1 < 0.0) {
cout << "Can't deposit negative amount." << endl;
damt1 = 0.0;
}
balance += damt1;
}
float Bank::withdraw()
{
int amount;
cout << "Enter withdrawal amount: ";
cin >> amount;
if (amount < 0.0) {
cout << "Negative amount can't be withdrawn" << endl;
amount = 0;
}
if (amount > balance - 1000.0) {
cout << "Not enough balance.";
}
balance -= amount;
return amount;
}
Bank::Bank(string name, int no)
{
depositor = name;
accno = no;
}
Bank::Bank(float bal, int no)
{
balance = bal;
accno = no;
}
Bank::Bank(char ty, int no)
{
type = ty;
accno = no;
}
Bank::Bank(const Bank& p)
{
balance = p.balance;
accno = p.accno;
}
void Bank::setname(string name)
{
depositor = name;
}
void Bank::setacc(int n)
{
accno = n;
}
void Bank::settype(char ty)
{
type = ty;
}
void Bank::setbal(float bal)
{
balance = bal?bal:0;
}
string Bank::getname()
{
return depositor;
}
int Bank::getacc()
{
return accno;
}
char Bank::gettype()
{
return type;
}
float Bank::getbal()
{
return balance;
}
void Bank::show()
{
cout << "Name: " << depositor<<endl;
cout << "Account number: " << accno<<endl;
cout << "Type: " << type<<endl;
cout << "Balance: " << balance<<endl;
}
int main()
{
Bank acct[5];//This is the line with error.I am unable to complete the code bcoz of this
int acno,i;
char ty;
string name;
float bal;
for (i=0;i<5;i++){
cout << "Enter details: \n";
cout << "name: ";
cin >> name;
cout << "\nEnter accno: ";
cin >> acno;
cout << "\nEnter type: ";
cin >> ty;
cout << "\nEnter balance: ";
cin >> bal;
Bank b1(name, acno, ty, bal);
}
return 0;
}
Can someone help me with what corrections I should make?

Exception has occured, unknown signal error when using class object again inside each function

I'm trying to write a C++ code for a course I'm enrolled in, where I keep the information of the students enrolled in the course.
I should be able to add a student to the classrrom in the user interface written in main , by calling the function void addNewStudent(int ID, string name, string surname), where I create my object instances, Student, and Course inside the function.
I should also be able to search by given ID by calling the function void showStudent(int ID) in the main, where the function uses the getStudent(ID) method of the object of the classCourse
I did not write all the methods, but when I try to debug this code, I got the error " Exception has occured, unknown signal error."
My questions are:
What is the reason of this error? How can I fix it?
Suppose that the user interface in the main is necessary to use as well as the functions it calls. Do I have to create a class object again inside each function as I wrote?
Can a more effective implementation be made in accordance with the object oriented principles I have defined above?
#include <iostream>
using namespace std;
#define MAX 10
class Student {
private:
int ID;
string name;
string surname;
public:
Student()
{
ID = 0;
string name = "" ;
string surname = "";
}
void setID(int ID_set);
int getID();
void setName(string name_set);
string getName();
void setSurName(string surname_set);
string getSurName();
};
class Course {
private:
Student students[MAX];
int num =0 ; // The current number of students in the course, initially 0.
float weightQ;
float weightHW;
float weightF;
public:
Course()
{
students[num] = {};
weightQ = 0.3;
weightHW = 0.3;
weightF = 0.4;
}
int getNum(); // Returns how many students are in the course
void addNewStudent(Student new_student);
void updateWeights(float weightQ_update, float weightHW_update, float weightF_update);
void getStudent(int ID_given);
};
// Method declerations for the class Student
void Student :: setID(int ID_set){
ID = ID_set;
}
int Student :: getID(){
return ID;
}
void Student :: setName(string name_set){
name = name_set;
}
string Student :: getName(){
return name;
}
void Student :: setSurName(string surname_set){
surname = surname_set;
}
string Student :: getSurName(){
return surname;
}
// Method declerations for the class Course
int Course :: getNum(){
return num;
}
void Course :: addNewStudent(Student new_student){
students[num] = new_student ;
num = num + 1;
}
void Course :: updateWeights(float weightQ_update, float weightHW_update, float weightF_update){
weightQ = weightQ_update;
weightHW = weightHW_update;
weightF = weightF_update;
}
void Course :: getStudent(int ID_given){
for(int i = 0; i<MAX; i++){
if(ID_given == students[i].getID()){
cout << "Student Name & Surname : " << students[i].getName() << " " << students[i].getSurName()<<"\n";
}
}
}
void addNewStudent(int ID, string name, string surname){
Student student;
Course ECE101;
student.setID(ID);
student.setName(name);
student.setSurName(surname);
ECE101.addNewStudent(student);
}
void showStudent(int ID){
Course ECE101;
ECE101.getStudent(ID);
}
int main(){
Course ECE101;
cout << "Welcome to the ECE101 Classroom Interface"<<"\n";
cout << "Choose your option\n";
string option_1 = "1) Add a student ";
string option_2 = "2) Search a student by ID";
cout << "Enter your option: ";
int x;
int ID;
string name, surname;
cin >> x;
if (x == 1)
cout << "Enter the student ID ";
cin >> ID;
cout << endl;
cout << "Enter the student name ";
cin >> name;
cout << endl;
cout << "Enter the student surname " ;
cin >> surname;
addNewStudent(ID, name, surname);
return 0;
}
 To make the menu more interactive you could add a do while statement that would accept 3 options:
register
show data
exit
int main(){
Course ECE101;
int x;
int ID;
string name, surname;
string option_1 = "1) Add a student\n";
string option_2 = "2) Search a student by ID\n";
cout << "Welcome to the ECE101 Classroom Interface\n";
cout << "Choose your option\n";
cout << option_1 << option_2;
cin >> x;
do {
if (x == 1) {
cout << "Enter the student ID ";
cin >> ID;
cout << endl;
cout << "Enter the student name ";
cin >> name;
cout << endl;
cout << "Enter the student surname " ;
cin >> surname;
addNewStudent(ID, name, surname, ECE101);
}
else {
cout << "Enter the student ID\n";
cin >> ID;
showStudent(ID, ECE101);
}
cout << "Choose your option\n";
cin >> x;
} while(x != 3);
return 0;
}
addnewStudent() and showStudent() methods now accepts an instance of Course as an argument to be able to add students.
void addNewStudent(int ID, string name, string surname, Course &course) {
Student student;
student.setID(ID);
student.setName(name);
student.setSurName(surname);
course.addNewStudent(student);
}
void showStudent(int ID, Course &course) {
course.getStudent(ID, course);
}
the function is modified from the same class as well.
void Course::getStudent(int ID_given, Course &course) {
for(int i = 0; i<MAX; i++){
if(ID_given == students[i].getID()){
cout << "Student Name & Surname : " << students[i].getName() << " " << students[i].getSurName()<<"\n";
}
}
}
Demo
Your addNewStudent function creates a new course everytime it is called. You could pass a reference to the course as a parameter into the function and call Course.addNewStudent(student). You'll want to make sure you specify it's a reference though when you define your function or you'll just create a copy of the course.

How to get my CSV File reader to read different types in C++?

For my project, my program has to read a file that looks like this: "Mary", "000111222", "Junior", 12, 4.0
In my main code it can read it, but only as strings only. I want it to read it as string,string, string, float, float. The getLine() method only works with strings. I tried other ways but it did not work. Any suggestions? The fields I want to be a float is gpa and credit. Any advice is appreciated! Thank you!
#include <iostream>
#include <string>
#include <iterator>
#include <iomanip>
#include <fstream>
#include <vector>
include <sstream>
#include <algorithm>
using namespace std;
class Student {
//declare local variables
protected:
string name; //people with names longer than 21 characters will just have
to make do
string ssn; // Social Secturity Number.
string gpa; //Most up to date gpa for the student
string credits; //Number of student's credit hours
//build public methods
public:
//Default Constructor
Student() {}
//Student constructor. Besides the character arrays, everything else is
passed by reference.
Student(const string n, const string s, string sGPA, string sCredits) {
name = n;
ssn = s;
gpa = sGPA;
credits = sCredits;
}
string getName() {
return name;
}
string getSSN() {
return ssn;
}
string getGPA() {
return gpa;
}
string getCredit() {
return credits;
}
//a function that is expected to be implemented and overridden by subclasses
virtual void print() const {
cout << '\n' << endl;
cout << "Student's name: " << name << endl;
cout << "Student SSN: " << ssn << endl;
cout << "Student's current GPA: " << gpa << endl;
cout << "Student's credit hours: " << credits << endl;
}
// a pure virtual function for implementation later. Makes whole class
Abstract
virtual float tuition() const = 0;
};
class Undergrad : public Student {
//declare local variables
protected:
float undergrad_rate = 380.0;
string year;
//build public methods
public:
//Default Constructor
Undergrad() {}
//Undergrad Constructor
Undergrad(const string n, const string s, string uGPA, string uCredits,
string y) :
Student(n, s, uGPA, uCredits), year(y) {}
//Display the contents of undergrad
void print() const {
Student::print();
cout << "Undergrad Rate: " << undergrad_rate << endl;
cout << "Year: " << year << endl;
}
//Display undergrad's current year
string get_year() {
return year;
}
//Display the undergrad's current rate
float get_rate() {
return undergrad_rate;
}
//Set a undergrad's current year
void set_year(string y) {
year = y;
}
//Display the cost for an undergrad to attend university
float tuition() const {
return 1000000;
}
};
int main() {
ifstream ip("data.txt");
if (!ip.is_open()) std::cout << "ERROR: File not found" << '/n';
string name;
string ssn;
string year;
string credit;
string gpa;
vector<Undergrad> file;
//Undergrad g(name, ssn, year, credit, gpa);
while (ip.good()) {
getline(ip, name, ',');
getline(ip, ssn, ',');
getline(ip, gpa, ',');
getline(ip, credit, ',');
getline(ip, year, '\n');
// float number = stoi(gpa);
//float number1 = stoi(credit);
Undergrad g(name, ssn, year, credit, gpa);
file.push_back(g);
}
ip.close();
Undergrad g = file.back();
file.pop_back();
file.insert(file.begin(),g);
for (int i = 0; i < file.size(); i++) {
cout << "Name: " << file[i].getName() << endl;
cout << "SSN: " << file[i].getSSN() << endl;
cout << "Year: " << file[i].get_year() << endl;
cout << "Credit: " << file[i].getCredit() << endl;
cout << "GPA " << file[i].getGPA() << endl;
cout << " " << endl;
}
system("pause");
return 0;
}
You can cast the string to a float using atof. See reference here. Be sure to include <cstdlib>. Your constructor would look like:
Student(const string n, const string s, string sGPA, string sCredits) {
name = n;
ssn = s;
gpa = (float)atof(sGPA.c_str());
credits = (float)atof(sCredits.c_str());
}

Function call error with my class

This program is supposed to prompt the user for two different employees and print their name, last name, ssn, payrate, and total pay for the week. Also it should determine if the worker worked any over time hours and recalculate their pay if they do.
I keep getting this error message:
No matching function call to Employee::Employee()
I will mark the lines which this message appears with a // *****.
The message appears 3 times. Please review my issues and help me fix them, and also explain what you did to fix them.
#include <cstdlib>
#include <iostream>
#include <math.h>
/*
Name: Employee2
Author: --------
Date: 20/10/14 20:36
Description: A program that prints workers info using classes
*/
using namespace std;
class Employee
{
private:
string firstname, lastname, ssn;
int payRate, hours;
public:
//A Four Parameter Constructor
Employee (string newFirst, string newLast, string newSsn, int newpayRate, int newHours)
{
firstname = newFirst;
lastname = newLast;
ssn = newSsn;
payRate = newpayRate;
hours = newHours;
}
//Setter or Mutator Functions
void setnewFirst(string newFirst)
{
firstname = newFirst;
}
void setnewLast(string newLast)
{
lastname = newLast;
}
void setnewSsn(string newSsn)
{
ssn = newSsn;
}
void setnewpayRate(int newpayRate)
{
payRate = newpayRate;
}
void setnewHours(int newHours)
{
hours = newHours;
}
void setEmployee(string newFirst, string newLast, string newSsn, int newpayRate, int newHours)
{
firstname = newFirst;
lastname = newLast;
ssn = newSsn;
payRate = newpayRate;
hours = newHours;
}
//Accessor Functions
string getfirstname ()
{
return firstname;
}
string getlastname ()
{
return lastname;
}
string getssn ()
{
return ssn;
}
int getpayRate ()
{
return payRate;
}
int gethours ()
{
return hours;
}
//Output Functions
void printEmployee ()
{
cout << firstname << " " << lastname << endl << ssn << endl << payRate << endl << hours << endl;
}
//Functions to use employee info
Employee newEmployee ()
{
Employee e1; //**************
string newFirst;
string newLast;
string newSsn;
int newpayRate;
int newHours;
cout << "Enter First Name: " ;
cin >> newFirst;
cout << "Enter Last Name: " ;
cin >> newLast;
cout << "Enter SSN: " ;
cin >> newSsn;
cout << "Enter Payrate: " ;
cin >> newpayRate;
cout << "Enter Hours Worked: " ;
cin >> newHours;
e1.setnewFirst(newFirst);
e1.setnewLast(newLast);
e1.setnewSsn(newSsn);
e1.setnewpayRate(newpayRate);
e1.setnewHours(newHours);
return e1;
}
//Function to Calculate Weekly Pay
int calculatePay (int hours)
{
double result;
if ( hours > 40 )
{
result = (hours - 40) * (payRate * 1.5) + (40 * payRate);
}
else
{
result = (hours * payRate);
}
}
};
Employee newEmployee();
//Main
int main(int argc, char *argv[])
{
Employee firstEmployee; // *********************
Employee secondEmployee; // *********************
double result;
firstEmployee = firstEmployee.newEmployee();
secondEmployee = secondEmployee.newEmployee();
cout << "First Employee Pay: " ;
firstEmployee.printEmployee();
cout << endl;
cout << "Secnod Employee Pay: " ;
secondEmployee.printEmployee();
system("PAUSE");
return EXIT_SUCCESS;
}
A constructor is intended to operate on the space in which the new object is being created. This means you don't need to complicate things by creating the additional object e1. Remove the problematic line:
Employee e1; //**************
Remove all e1 references from your code; for example change
e1.setnewFirst(newFirst);
e1.setnewLast(newLast);
e1.setnewSsn(newSsn);
e1.setnewpayRate(newpayRate);
e1.setnewHours(newHours);
to:
setnewFirst(newFirst);
setnewLast(newLast);
setnewSsn(newSsn);
setnewpayRate(newpayRate);
setnewHours(newHours);
Constructors do not return values; remove:
return e1;
Compile, test, debug, rinse, and repeat.

How to pass variables to a class

I have been working on this code for quite some time now and I had posted it before but then after fixing that problem another problem arose so I created a new post with the name of this problem. Ok the problem is that I am obviously not passing the variables to the Administrator class the right way. I have tried two ways which is all my book shows and both have given me an error that says error C2512: 'SalariedEmployee' : no appropriate default constructor available". I have tried
//Lynette Wilkins
//Week 12
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;
class SalariedEmployee
{
private:
double wageRate;
int hours;
protected:
string name;
string ssn;
double netPay;
string department;
public:
SalariedEmployee(string n, string s, double np, double w, int h, string d);
~SalariedEmployee() {cout<<endl;}
string Getname(); //returns name
string Getssn(); // returns social security number
double GetnetPay(); //returns netPay
string Getdepartment(); // returns department
double GetwageRate(); //returns wage rate
int Gethours(); //returns hours
void Setname(string); //sets name
void Setssn(string); //sets ssn
void SetnetPay(double); //sets net pay
void Setdepartment(string); //sets department
void SetwageRate(double); //sets wage rate
void Sethours(int); //sets hours
};
SalariedEmployee::SalariedEmployee(string n, string s, double np, double w, int h, string d) : name(n),
ssn(s),
netPay(np),
wageRate(w),
hours(h),
department(d)
{}
string SalariedEmployee::Getname()
{
return name;
}
string SalariedEmployee::Getssn()
{
return ssn;
}
double SalariedEmployee::GetnetPay()
{
return netPay;
}
double SalariedEmployee::GetwageRate()
{
return wageRate;
}
int SalariedEmployee::Gethours()
{
return hours;
}
void SalariedEmployee::Setname(string n)
{
name = n;
}
void SalariedEmployee::Setssn(string s)
{
ssn = s;
}
void SalariedEmployee::SetnetPay(double np)
{
netPay = np;
}
void SalariedEmployee::Setdepartment(string d)
{
department = d;
}
void SalariedEmployee::SetwageRate(double w)
{
wageRate = w;
}
void SalariedEmployee::Sethours(int h)
{
hours = h;
}
class Administrator : public SalariedEmployee
{
protected:
string title;
string responsi;
string super;
double salary;
public:
Administrator(string t, string r, string s, double sa);
~Administrator();
string Gettitle();
string Getresponsi();
string Getsuper();
double Getsalary();
void Settitle(string);
void Setresponsi(string);
void Setsuper(string);
void Setsalary(double);
void print();
};
Administrator::Administrator(string t, string r, string s, double sa) : title(t), responsi(r), super(s), salary(sa)
{
}
Administrator::~Administrator()
{
cout<<endl;
}
string Administrator::Gettitle()
{
return title;
}
string Administrator::Getresponsi()
{
return responsi;
}
string Administrator::Getsuper()
{
return super;
}
double Administrator::Getsalary()
{
return salary;
}
void Administrator::Settitle(string ti)
{
title = ti;
}
void Administrator::Setresponsi(string re)
{
responsi = re;
}
void Administrator::Setsuper(string su)
{
super=su;
}
void Administrator::Setsalary(double sa)
{
salary= sa;
}
void Administrator::print( )
{
cout << "\n_______________________________________________\n";
cout << "Pay to the order of " << name<< endl;
cout << "The sum of " << netPay << " Dollars\n";
cout << "_________________________________________________\n";
cout <<endl<<endl;
cout << "Employee Number: " << ssn << endl;
cout << "Salaried Employee. Regular Pay: "
<< salary << endl;
cout << "_________________________________________________\n";
}
int main()
{
string name;
string soc;
double net = 0;
double wage = 0;
int hrs = 0;
string dept;
string admtitle;
string resp;
string sup;
double sal = 0;
int response = 0;
string date = "January 12, 2013";
cout<<setprecision(2)
<<setiosflags(ios::fixed)
<<setiosflags(ios::showpoint);
SalariedEmployee emp1(name, soc,net, wage, hrs, dept);
Administrator adm1(admtitle, resp, sup, sal);
while(response != 4){
cout<<"Employee and Administrator Salary Program "<<endl;
cout<<"(You will have to enter data first before you do anything else)"<<endl<<endl;
cout<<"Enter Employee Data, Enter 1"<<endl;
cout<<"Change data, Enter 2"<<endl;
cout<<"Print Check, Enter 3"<<endl;
cout<<"End Program, Enter 4"<<endl<<endl;
cout<<"Please make your selection"<<endl;
cin>> response;
switch (response)
{
case 1:
cout <<"The employee's data will be entered here: "<<endl<<endl;
cout<<"Enter the employees name: ";
cin.ignore();
getline(cin, name);
cout<<"Enter the employees social security number: ";
cin.ignore();
getline(cin, soc);
cout<<"Enter the employees net pay: ";
cin>>net;
cout<<"Enter the employees wage rate: ";
cin>>wage;
cout<<"Enter the number of hours the employer worked: ";
cin>>hrs;
cout<<"Enter the employees title: ";
cin.ignore();
getline(cin,admtitle);
cout<<"Enter the employees area responsibility: ";
cin.ignore();
getline(cin, resp);
cout<<"Enter the employees salary: ";
cin>>sal;
cout<<endl<<endl<<endl;
break;
case 2:
cout<<"Please change the data you entered previously here. " <<endl<<endl;
cout<<"Enter the employees name: ";
cin.ignore();
getline(cin, name);
cout<<"Enter the employees social security number: ";
cin.ignore();
getline(cin, soc);
cout<<"Enter the employees net pay: ";
cin>>net;
cout<<"Enter the employees wage rate: ";
cin>>wage;
cout<<"Enter the number of hours the employer worked: ";
cin>>hrs;
cout<<"Enter the employees title: ";
cin.ignore();
getline(cin,admtitle);
cout<<"Enter the employees area responsibility: ";
cin.ignore();
getline(cin, resp);
cout<<"Enter the employees salary: ";
cin>>sal;
cout<<endl<<endl<<endl;
break;
case 3:
cout <<"Information Printed"<<endl<<endl;
cout<<"_____________________________"<<date<<endl;
&Administrator::print;
break;
default:
cout<<endl<<endl
<<"Invalid Selection! Try Again"<<endl;
exit(1);
}
}
system("PAUSE");
return 0;
}
Administrator(string t, string r, string s, double sa); will attempt to call the default constructor of the base class if you don't specify another. (a default constructor is one that can be called without any arguments)
The base class doesn't have a default constructor, ergo the error.
To call another constructor of the base class:
Administrator::Administrator(string t, string r, string s, double sa) :
SalariedEmployee(<args>), //base constructor call
title(t), responsi(r), super(s), salary(sa) //members
{
}