need help with Array coding
Oct 12, 2016 at 9:56pm UTC
Hello everybody, I wrote a program to output the name, ID, department, position using Class, Array, and object. my professor give me a hint by using Pointer for object, but i don't know how to fix that, Hope that somebody can help me, thank you everyone. ( The output having some Errors when running , please help me fix that, thank u )
This is my CODE:
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
#include <iostream>
#include <string>
#include <ctime>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <cstdlib>
#include <limits>
#include <cctype>
#include<Windows.h>
using namespace std;
class Employee
{
private :
string name;
int idNumber;
string department;
string position;
public :
string getname()const ;
int getidNumber()const ;
string getdepartment()const ;
string getposition()const ;
void setidNumber(int );
void setname(string);
void setdepartment(string);
void setposition(string);
Employee();
Employee(string, int , string, string);
};
int main()
{
Employee E;
string a, b, c, total;
int d;
const int SIZE = 3;
Employee employee[SIZE];
for (int i = 0; i < SIZE; i++)
{
cout << "Please enter the Employee's name:\n" ;
cin >> a;
E.setname(a);
cout << "Please enter the Employee's ID number:\n " ;
cin >> d;
E.setidNumber(d);
cout << "Please enter the Employee's Deparment:\n " ;
cin >> c;
E.setdepartment(c);
cout << "Please enter the Employee's position:\n " ;
cin >> b;
E.setdepartment(b);
employee[i] = E;
}
cin.ignore();
cout << left << "Name" << "\t\t" << "ID Number" << "\t"
<< "\t" << "Department" << "\t" << "Position\n" ;
cout << "-------------------------------------\n" ;
for (int i = 0; i < SIZE; i++)
{
cout << setw(8) << employee[i].getname();
cout << setw(8) << employee[i].getidNumber();
cout << setw(8) << employee[i].getdepartment();
cout << setw(8) << employee[i].getposition() << endl;
}
return 0;
}
void Employee::setname(string NA)
{
name = NA;
}
void Employee::setidNumber(int ID)
{
idNumber = ID;
}
void Employee::setdepartment(string DEP)
{
department = DEP;
}
void Employee::setposition(string POS)
{
position = POS;
}
string Employee::getname() const
{
return name;
}
int Employee::getidNumber() const
{
return idNumber;
}
string Employee::getdepartment() const
{
return department;
}
string Employee::getposition() const
{
return position;
}
//default constructor
Employee::Employee()
{
name = " " ;
idNumber = 0;
department = " " ;
position = " " ;
}
//constructor
Employee::Employee(string q, int w, string e, string r)
{
name = q;
idNumber = w;
department = e;
position = r;
}
Last edited on Oct 13, 2016 at 6:40am UTC
Oct 13, 2016 at 3:46am UTC
Please sir, use the code prefixes or atleast indent or no one will want to read this.
Oct 13, 2016 at 6:42am UTC
TinyTertle, i have learned how to prefixes my code . i apologize about that, I'm a new one here . thank you.
Topic archived. No new replies allowed.