URGENT: Staff payroll with fstream function

Joined
Aug 18, 2009
Messages
1
Reaction score
0
i need help with my program in visual.. it doesn't seem to able to save the commission and Gross Salary in the .txt...

CODE:

#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>

using namespace std;

class ABC
{
protected:
string name, ID, d_type;
double commission, Allowance, d_sales, d_GrossSalary;

public:

void computecommission(double sales);

void showcommission(void);
void SetSalesRegion(string SalesRegion);
void computeGrossSalary(double GrossSalary);

string type, Region;
};

void ABC::computecommission(double sales)
{

d_sales = sales;

if (type == "Local" || type == "local")
{
commission = sales * 0.05;
}
else if(type == "Regional" || type == "regional")
{
commission = sales * 0.1;
}
}

void ABC::showcommission()
{
cout<<"Commission: $"<<fixed<<setprecision(2)<<commission<<endl;
}

void ABC::SetSalesRegion(string SalesRegion)
{
Region = SalesRegion;

if (Region == "Thailand" || Region == "thailand")
{
Allowance = 250;
cout<< "Allowance = 250";
}
else if (Region == "Malaysia" || Region == "malaysia")
{
Allowance = 150;
cout<< "Allowance = 150";
}
else if (Region == "Indonesia" || Region == "indonesia")
{
Allowance = 200;
cout<< "Allowance = 200";
}
else if (Region == "Vietnam" || Region == "vietnam")
{
Allowance = 300;
cout<< "Allowance = 300";
}
}

void ABC::computeGrossSalary(double GrossSalary)
{
GrossSalary = d_GrossSalary;
float BaseSalary;

if (type == "Counter" || type == "counter")
{
BaseSalary = 800;
cout<<"Base Salary = $800"; // 800~1200
d_GrossSalary = BaseSalary;
}
else if (type == "Local" || type == "local")
{
BaseSalary = 400;
cout<<"Base Salary = $400"; // 400~800
d_GrossSalary = BaseSalary + commission;
}
else if (type == "Regional" || type == "regional")
{
BaseSalary = 800;
cout<<"Base Salary = $800"; // 800~2000
d_GrossSalary = BaseSalary + commission + Allowance;
}


cout<<"\nGross Salary: $"<<d_GrossSalary<<endl;

}


int main()
{


ofstream outFile;
outFile.open("data.txt", ios::app);

string name, ID;
double commission, d_GrossSalary;

ABC myinfo;


cout<<"Enter Name: ";
getline(cin, name);


cout<<"Enter ID: ";
getline(cin, ID);

cout << "Enter Type: ";
cin >> myinfo.type;

cout<<"Enter Sales Amount: $";
float sales;
cin>>sales;
myinfo.computecommission(sales);

cout<< endl;

if (myinfo.type == "Regional" || myinfo.type == "regional")
{
cout << "Enter Sales Region: ";
string SalesRegion;
cin >> SalesRegion;
cout<<"\n";

cout<< endl;

cout<<"Name: "<<name<<endl;
outFile<<"\nName: "<<name<<endl;


cout<<"ID: "<<ID<<endl;
outFile<<"ID: "<<ID<<endl;


cout<<"Type: "<<myinfo.type<<endl;
outFile<<"Type: "<<myinfo.type<<endl;


cout << "Sales Amount: $"<<sales<<endl;
outFile << "Sales Amount: $"<<sales<<endl;


myinfo.showcommission();
outFile<<"Commission: $"<<fixed<<setprecision(2)<<commission<<endl;

myinfo.SetSalesRegion(SalesRegion);
outFile<<"Region: "<<SalesRegion<<endl;

myinfo.computeGrossSalary(0);
outFile<<"Gross Salary: $"<<fixed<<setprecision(2)<<d_GrossSalary<<endl;

}
else if (myinfo.type == "Local" || myinfo.type =="local")
{

cout<<"Name: "<<name<<endl;
outFile<<"\nName: "<<name<<endl;


cout<<"ID: "<<ID<<endl;
outFile<<"ID: "<<ID<<endl;


cout<<"Type: "<<myinfo.type<<endl;
outFile<<"Type: "<<myinfo.type<<endl;

cout << "Sales Amount: $"<<sales<<endl;
outFile << "Sales Amount: $"<<sales<<endl;


myinfo.showcommission();
outFile<<"Commission: $"<<fixed<<setprecision(2)<<commission<<endl;

myinfo.computeGrossSalary(0);
outFile<<"Gross Salary: $"<<fixed<<setprecision(2)<<d_GrossSalary<<endl;
}

outFile.close();
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top