class/ strings/ cin errors Help please :^)
Dec 3, 2014 at 3:42am UTC
I'm having a few errors when I try to run my program that I'm not quite sure mean or how to fix it. Here's a screen shoot of the errors
http://i.imgur.com/dWOP33Z.png?1
my only I can't use the set function I creaed with cin/ getline
any help is much appreciated :^)
EDIT: I've fixed all the cin/ getline errors but now I have an error that's related to the linker?
I have no idea how to fixed this one either.. :(
new compilation error imgur.com/wm97Shj.png
Main.cpp
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
// TUAN PHAN
// Employee Management System
#include <iostream>
#include <fstream>
#include "functions.h"
using namespace std;
int main()
{
vector<Employee> Employees (0);
int choice = 0;
while (choice != 9)
{
displayMenu();
cout << "\nPlease select an option: " ;
cin >> choice;
switch (choice) // switch statement for menu choice
{
case 1: displayDirectory(Employees);
break ;
case 2: addEmployee(Employees);
break ;
case 3: displayDirectory(Employees);
updateEmployee(Employees);
break ;
case 4: deleteEmployee(Employees); // add sort after test
break ;
case 5: sortEmployee(Employees);
break ;
case 6: searchEmployee(Employees);
break ;
case 7: readDirectory(Employees);
break ;
case 8: writeDirectory(Employees);
exit(0);
break ;
case 9: exit(0);
break ;
}
}
}
function.h header file
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "employee.h" // test with .h file
using namespace std;
void displayDirectory(vector<Employee>);
void addEmployee(vector<Employee>);
void updateEmployee(vector<Employee>);
void deleteEmployee(vector<Employee>);
void sortEmployee(vector<Employee>);
void searchEmployee(vector<Employee>);
void readDirectory(vector<Employee>);
void writeDirectory(vector<Employee>);
void displayMenu();
void displayMenu()
{
cout << "Tuan's Employee Management\n" ;
cout << "**************************\n" ;
cout << "Please chose one of the options below\n" ;
cout << "1. Display Employee directory\n" ;
cout << "2. Add an Employee\n" ;
cout << "3. Update an Employee\n" ;
cout << "4. Delete the Employee\n" ;
cout << "5. Sort Employee by ID\n" ;
cout << "6. Search directory by email\n" ;
cout << "7. Read directory from file\n" ;
cout << "8. Write direcotry to file and Exit\n" ;
cout << "9. Exit\n" ;
}
// incomplete
void displayDirectory(vector<Employee> staff)
{
cout << "\tEmployee Directory\n" ;
cout << "******************************\n\n" ;
for ( int index = 0; index < 100; index++)
{
cout << "Employee: " << index + 1 << endl;
cout << "Name: " << staff[index].getName() << endl;
cout << "SSN: " << staff[index].getSsn() << endl;
cout << "Email: " << staff[index].getEmail() << endl;
cout << "Year: " << staff[index].getYearOfBirth() << endl;
}
}
// incomplete
void addEmployee(vector<Employee> staff)
{
string name;
string email;
string ssn;
int ID;
int year;
int endVector;
endVector = staff.size();
cout << "Please enter your ID number\n" ;
cin >> ID;
staff[endVector].setID(ID);
cout << "Please enter your name\n" ;
getline(cin, name);
staff[endVector].setName(name);
cout << "Please enter your SSN with the dashes. Example: XXX-XX-XXXX\n" ;
getline(cin,ssn);
staff[endVector].setSsn(ssn);
cout << " Please enter your email with the at sign\n" ;
cin >> email;
staff[endVector].setEmail(email);
cout << "Please enter your birth year\n" ;
cin >> year;
staff[endVector].setYearOfBirth(year);
}
// incomplete
void updateEmployee(vector<Employee> staff)
{
string name;
string email;
string ssn;
int ID;
int year;
int choice;
int index;
cout << "Which employee would you like to update?\n" ;
cin >> index;
cout << "What would you like to update on this employee\n"
<< "1. Name\n"
<< "2. Email\n"
<< "3. SSN\n"
<< "4. Year\n" ;
cin >> choice;
switch (choice)
{
case 1: cout << "Please enter the name of the employee\n" ;
getline(cin, name);
staff[index-1].setName(name);
break ;
case 2: cout << "Please enter your email with the at sign\n" ;
getline(cin, email);
staff[index-1].setEmail(email);
break ;
case 3: cout << "Please enter your SSN with the dashes. Example: XXX-XX-XXXX\n" ;
cin >> ssn;
staff[index-1].setSsn(ssn);
break ;
case 4: cout << "Please enter your year of birth year\n" ;
cin >> year;
staff[index - 1].setYearOfBirth(year);
break ;
}
}
// test
void deleteEmployee(vector<Employee> staff)
{
int index;
int size = staff.size();
cout << "Which employee would you like to delete?\n" ;
cin >> index;
if ( index < size)
{
staff.erase (staff.begin()+(index-1));
cout << "This employee has been deleted\n" ;
}
else
cout << "Employee does not exist in data\n" ;
}
// need testing
void sortEmployee(vector<Employee> staff)
{
bool swap;
int temp;
int temp2;
int size = staff.size();
do
{
swap = false ;
for (int index = 0; index < size ; index++)
{
if ( staff[index].getID() > staff[index+1].getID())
{
temp = staff[index].getID();
temp2 = staff[index+1].getID();
staff[index].setID(temp2);
staff[index].setID(temp);
swap = true ;
}
}
}while (swap);
}
// needs testing
void searchEmployee(vector<Employee> staff)
{
int index = 0;
string tempEmail;
bool found = false ;
cout << "Please enter a the email address of the employee you're looking for\n" ;
getline(cin, tempEmail);
while ( found == false )
{
if ( tempEmail == staff[index].getEmail())
{
found = true ;
}
index++;
}
if ( found == true )
{
cout << "Employee has been found\n" ;
cout << "Employee: " << index << endl;
cout << "Name: " << staff[index - 1].getName() << endl;
cout << "SSN: " << staff[index - 1].getSsn() << endl;
cout << "Email: " << staff[index - 1].getEmail() << endl;
cout << "Year: " << staff[index - 1].getYearOfBirth() << endl;
}
else
cout << "Employee not found\n" ;
}
void readDirectory(vector<Employee> staff)
{
}
void writeDirectory(vector<Employee> staff)
{
}
class implementation
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
#include "employee.h"
#include <iostream>
// get functions // return stuff
int Employee::getID()
{
return ID;
}
string Employee::getName()
{
return name;
}
string Employee::getSsn()
{
return ssn;
}
int Employee::getYearOfBirth()
{
return yearOfBirth;
}
string Employee::getEmail()
{
return emailAddress;
}
// set functions
void Employee::setID(int empl_id)
{
Employee::ID = empl_id;
}
void Employee::setName(string empl_name)
{
Employee::name = empl_name;
}
void Employee::setSsn(string empl_ssn)
{
Employee::ssn = empl_ssn;
}
void Employee::setYearOfBirth(int empl_yearOfBirth)
{
Employee::yearOfBirth = empl_yearOfBirth;
}
void Employee::setEmail(string empl_email)
{
Employee::emailAddress = empl_email;
}
class declaration
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
#include <string>
using namespace std;
class Employee
{
private :
int ID;
string name;
string ssn;
string emailAddress;
int yearOfBirth;
public :
Employee(int ID, string name, string ssn, string emailAddress, int yearOfBirth);
Employee();
int getID();
string getName();
string getSsn();
int getYearOfBirth();
string getEmail();
void setID(int );
void setName(string);
void setSsn(string);
void setYearOfBirth(int );
void setEmail(string);
};
Last edited on Dec 3, 2014 at 5:13am UTC
Dec 3, 2014 at 3:58am UTC
Employee.h line 1...no need for the semicolon at the end of the include.
cin is apart of the std namespace and while your main file uses it your header isn't.
you can simply change the getline statements to
1 2 3
string NameStr;
getline(std::cin,NameStr);
staff[index].setName(NameStr); // Read in data, then send to function
most of your reading in of data is wrong. Instead of
cin >> staff[index].setSsn;
it should be
1 2 3
int tempSsn;
cin >> tempSsn;
staff[index].setSsn(tempSsn);
this way you are reading in data to a variable, then sending that variable to the function to set the Ssn of the record.
Last edited on Dec 3, 2014 at 3:59am UTC
Dec 3, 2014 at 5:13am UTC
I've fixed the cin/ getline error can anyone tell me what these errors are?
imgur.com/wm97Shj.png
Topic archived. No new replies allowed.