New problem. I dont understand how to convert a char/int to string
Nov 6, 2011 at 11:04pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
#include <iostream>
#include<string>
#include<stdlib.h>
#include<cstdlib>
#include<iomanip>
using namespace std;
class employee
{
private :
string fname;
string lname;
string input;
char gender;
int depend;
double ansal;
public :
employee();
employee(string, string, char , int , double );
void setfname(string);
void setlname(string);
void setgender(char );
void setdepend(int );
void setansal(double );
string getfname();
string getlname();
char getgender();
int getdepend();
double getansal();
double calculatePay(double );
void DisplayEmployee();
};
employee::employee()
{
fname ="unkown" ;
lname ="unkown" ;
gender= 'U' ;
depend= 0;
ansal = 20000;
};
employee::employee(string firstname, string lastname, char genderr, int depends, double annsal)
{
fname = firstname;
lname = lastname;
gender =genderr;
depend =depends;
ansal =annsal;
};
void employee::setfname(string newfName)
{
fname = newfName;
};
void employee::setlname(string newlName)
{
lname =newlName;
};
void employee::setgender(char newGender)
{
gender =newGender;
};
void employee::setdepend(int newDepend)
{
depend =newDepend;
};
void employee::setansal(double newAnsal)
{
ansal = newAnsal;
};
string employee::getfname()
{
return fname;
};
string employee::getlname()
{
return lname;
};
char employee::getgender()
{
return gender;
};
int employee::getdepend()
{
return depend;
};
double employee::getansal()
{
return ansal;
};
double employee::calculatePay(double )
{
return ansal/52;
};
void employee::DisplayEmployee()
{
cout <<"======================Employee Information========================" << endl;
cout << "Employee Name:\t" << fname << " " <<lname <<endl;
cout << "Employee Gender:\t" << gender << endl;
cout << "Employee Dependents:\t" << depend << endl;
cout << "Employee Annual Salary:\t" <<
setprecision(2)<<showpoint<<fixed<<ansal<< "\n" ;
cout << "Employee Weekly Pay:\t" << ansal/52<< endl;
};
void DisplayApplicationInformation()
{
cout<<"Welcome to your first Object Oriented Program--Employee Class"
<<"CIS247C, Week 2 Lab"
<<"Name: Jeremy Zavala" ;
};
void DisplayDivider(string message)
{cout<<"\n*************** " + message + " *********************\n" ;
};
string GetInput( string message)
{ string mystring;
cout<<"Please enter your " <<message<<": " ;
getline(cin, mystring);
return mystring;
};
void TerminateApplication()
{ cout<<"\nThe end of the CIS247C Week2 iLab.\n" ;
};
int main ()
{
DisplayApplicationInformation();
DisplayDivider("Employee 1" );
employee employeeone;
string fname = GetInput("First Name" );
employeeone.setfname(fname);
string lname =GetInput("Last Name" );
employeeone.setlname(lname);
//char gender =GetInput("Gender");
//gender = employeeone.setgender.at(0);
//int depend = GetInput("Dependents");
//depend = atoi( depend.c_str());
//employeeone.setdepend(depend);
employeeone.DisplayEmployee();
TerminateApplication();
system("pause" );
return 0;
}
Lines 171 -176 are giving me problems. I dont know if im going about it all wrong. I read my book and it said to use the conversion functions that i tried using. They are not working as i intended and im sure it is because i have them being used wrong. Wondering if i could get some help on these issues?
Topic archived. No new replies allowed.