Well I have this 2nd year course for C++ where I have to write programs depending on the explanation and objectives of what the program should do. But i am having trouble to write them...
I was wondering if anyone would tell me how to start of a program that you will write and all you know is what the program must do.
say I need to write a program where there are 2 classes and a main funtion. One Employee class and one staff class..
Code:class Employee { private: char * name; // Employee's name double hourlyRate; // Hourly pay rate double hours; // Hours worked this week double taxRate (); public: Employee (); ~Employee (); void setName (char * _name); void setHourlyRate (double _hourlyRate); void setHours (double _hours); void printPayroll (); };Now I need to write the definition of each member functionCode:class Staff { private: int totalEmployees; Employee employees[MAX_EMPLOYEES]; public: Staff (); ~Staff (); void addEmployee (char * _name, double _hourlyRate, double _hours); int getTotalEmployees (); void printPayroll (); };
this is what I got for employee
What am i doing wrong?Code:# include <iostream> # include "Employee.h" using namespace std; Employee::Employee() { name = new char [200]; hourlyRate = 0; hours = 0; } Employee::~Employee() { delete[] name; } double Employee::taxRate () { int anual_Income = hourlyRate * 40 * 52; if (anual_Income < 20000) { return 15;} else if (anual_Income < 30000) return 0.20; else if (anual_Income < 40000) return 0.25; else if (anual_Income < 50000) return 0.30; else if (anual_Income < 60000) return 0.35; else if (anual_Income < 70000) return 0.40; else return 0.45; } char* Employee::setName (char *_name) { name = _name; } double Employee::setHourlyRate (double _hourlyRate) { hourlyRate = _hourlyRate; } double Employee::setHours (double _hours) { hours = _hours; } void Employee::printPayroll () { double overTime = 0, hours40 = hours; if (hours > 40) { overTime == hours - 40; hours40 = 40;} double weeklyPay = hours40 * hourlyRate + overtime * hourlyRate * 1.5; double tax = taxRate() * weeklyPay; cout << *name << ": " << weeklyPay << " - " << tax << " = " << weeklyPay - tax; }



LinkBack URL
About LinkBacks



I used to be an adventurer like you... then I took an arrow to the knee.