Hi fellas,
This week in class (2nd week), we are learning about classes. Our professor has asked us just to complete one simple class with separate files. My problem is when I go to compile, I get errors stating my variables aren't "declared in this scope." As far as I understand declarations, I thought I declared them in my salary.cpp file.
Can you help me out in uncovering what the compiler is needing? Everything looks declared to me.
SALARY.H
#ifndef salary_h
#define salary_h
#include <iostream>
#include <string>
using namespace std;
class EmployeeSalary
{
private:
string employeeName;
float hrlyWage;
public:
EmployeeSalary(string name, float hrlyWage);
string getName() const;
float gethrlyWage() const;
float paycheck(float hrsWorked) const;
};
#endif
SALARY.CPP
#include "salary.h"
#include <iostream>
#include <string>
EmployeeSalary::EmployeeSalary(string name, float hrlyWage)
{
wholeName = name;
wage = hrlywage;
}
string EmployeeSalary::getName() const
{
return wholeName;
}
float EmployeeSalary::getPayRate() const
{
return wage;
}
float EmployeeSalary::paycheck(float hrsWorked) const
{
return hrsWorked * hrlyWage;
}
MAIN.CPP
#include "salary.h"
#include <iostream>
using namespace std;
void purpose()
{
cout <<" " <<endl;
cout <<"==============================================================================" <<endl;
cout <<"\t\t\tPersonal Notes:" <<endl;
cout<<"\n\n\nThis *class* exercise is to illustrate the mechanics of using a class in OOP." <<endl;
cout <<"Header File (salary.h): contains the class definition, class properties & methods:" <<endl;
cout <<"\n\nPublic - makes class variables & methods accessible to any part of the program." <<endl;
cout <<"Private - variables and functions can only be accessed from within the class itself." <<endl;
cout <<"\n\n Source File (salary.cpp): this is where write your method implementations and return values." <<endl;
cout <<"Main File (main.cpp): contains all classes and methods used to initiate program." <<endl;
cout <<"\n==============================================================================" <<endl;
}
int main()
{
float hrsWorked;
string wholeName;
float wage;
cout <<"Please enter your name: "
cin >> wholeName
EmployeeSalary::getName();
cout <<"\nPlease enter your hourly rate: "
cin >> wage
EmployeeSalary::getPayRate(wage);
cout <<"Please enter how many hours you worked this week: "
cin >> hrsWorked;
cout <<"You will be paid " <<EmployeeSalary::paycheck(float hrsWorked) "this week."
cin.get()
return 0;
}
Forgive me if the code looks illogical...I am trying to wrap my head around class mechanics.
Thanks!