I was wondering if anyone could help me out with something I am trying to get a program to work where I have an array of employee objects, and through the program you can go make a selection to add an employee and then it asks you for certain data to put into the object. My problem is is that it seems to be working fine but when I try to display the objects data the data is in the wrong place. like instead of name next to name it is next to address, it skips the first data member name any help would be great thanks
//************************************************
/
//
//employeeMenu.cpp
//class implementation file for the employeeMenu class
//************************************************
#include <stdio.h>
#include <iostream.h>
#include <ios.h>
#include <iomanip.h>
#include <fstream.h>
#include <conio.h>
#include "employeeMenu.h"
#include "employee.h"
#include "student.h"
const int MAX = 5;
int E;
employee Emp[MAX];
employeeMenu::employeeMenu()
{
choiceText[0] = " Display student information";
choiceText[1] = " Add Employee";
choiceText[2] = " Display Employee";
choiceText[3] = " Quit";
numChoices = 4;
}
void employeeMenu::run()
{
bool dontQuit = true;
while (dontQuit)
{
displayMenu();
cin >> choice;
switch (choice)
{
case 1:
pStudentInfo();
break;
case 2:
cin.ignore (80, '\n');
addEmployeeInfo();
break;
case 3:
displayEmployeeInfo();
break;
case 4:
dontQuit = false;
break;
default:
cout << "Invalid selection please try again\n";
}
}
}
void employeeMenu::displayMenu()
{
clrscr();
cout << "-----------------------------------------------------------\n";
cout << " Please choose from the following selections \n";
cout << "-----------------------------------------------------------\n";
for ( int i = 0; i < numChoices; i++)
{
cout << " " << (i+1) << ": " << choiceText[ i ] << "\n";
}
cout << "<";
}
void employeeMenu:StudentInfo()
{
clrscr();
Student student(4);
cout << "-----------------------------------------------------------\n";
cout << " Student Info \n";
cout << "-----------------------------------------------------------\n";
student.showInfo();
cout << "\n\nPress any key to continue...";
getch();
clrscr();
}
void employeeMenu::addEmployeeInfo()
{
int E;
string name1;
string address1;
string phoneNum1;
char n [80];
char a [80];
char p [80];
/*string n;
string a;
string p;*/
cout << "Which employee would you like to add (1-" << MAX << ": ";
cin >> E;
clrscr();
cout << "Please input employees name (Last, First): ";
cin.getline (n, 80, '\n');
name1 = n;
cout << "\nPlease input employees address (address, city, state, zip): ";
cin.getline (a, 80, '\n');
address1 = a;
cout << "\nPlease input employee phone number (xxx-xxx-xxxx): ";
cin.getline (p, 80, '\n');
phoneNum1 = p;
cin.ignore (80, '\n');
Emp[E-1].setName(name1);
Emp[E-1].setAddress(address1);
Emp[E-1].setPhoneNum(phoneNum1);
}
void employeeMenu::displayEmployeeInfo()
{
int E;
cout << "Which employee would you like to see info for (1-" << MAX << ": ";
cin >> E;
Emp[E-1].showInfo();
}
//************************************************
/
//
//employeeMenu.cpp
//class implementation file for the employeeMenu class
//************************************************
#include <stdio.h>
#include <iostream.h>
#include <ios.h>
#include <iomanip.h>
#include <fstream.h>
#include <conio.h>
#include "employeeMenu.h"
#include "employee.h"
#include "student.h"
const int MAX = 5;
int E;
employee Emp[MAX];
employeeMenu::employeeMenu()
{
choiceText[0] = " Display student information";
choiceText[1] = " Add Employee";
choiceText[2] = " Display Employee";
choiceText[3] = " Quit";
numChoices = 4;
}
void employeeMenu::run()
{
bool dontQuit = true;
while (dontQuit)
{
displayMenu();
cin >> choice;
switch (choice)
{
case 1:
pStudentInfo();
break;
case 2:
cin.ignore (80, '\n');
addEmployeeInfo();
break;
case 3:
displayEmployeeInfo();
break;
case 4:
dontQuit = false;
break;
default:
cout << "Invalid selection please try again\n";
}
}
}
void employeeMenu::displayMenu()
{
clrscr();
cout << "-----------------------------------------------------------\n";
cout << " Please choose from the following selections \n";
cout << "-----------------------------------------------------------\n";
for ( int i = 0; i < numChoices; i++)
{
cout << " " << (i+1) << ": " << choiceText[ i ] << "\n";
}
cout << "<";
}
void employeeMenu:StudentInfo()
{
clrscr();
Student student(4);
cout << "-----------------------------------------------------------\n";
cout << " Student Info \n";
cout << "-----------------------------------------------------------\n";
student.showInfo();
cout << "\n\nPress any key to continue...";
getch();
clrscr();
}
void employeeMenu::addEmployeeInfo()
{
int E;
string name1;
string address1;
string phoneNum1;
char n [80];
char a [80];
char p [80];
/*string n;
string a;
string p;*/
cout << "Which employee would you like to add (1-" << MAX << ": ";
cin >> E;
clrscr();
cout << "Please input employees name (Last, First): ";
cin.getline (n, 80, '\n');
name1 = n;
cout << "\nPlease input employees address (address, city, state, zip): ";
cin.getline (a, 80, '\n');
address1 = a;
cout << "\nPlease input employee phone number (xxx-xxx-xxxx): ";
cin.getline (p, 80, '\n');
phoneNum1 = p;
cin.ignore (80, '\n');
Emp[E-1].setName(name1);
Emp[E-1].setAddress(address1);
Emp[E-1].setPhoneNum(phoneNum1);
}
void employeeMenu::displayEmployeeInfo()
{
int E;
cout << "Which employee would you like to see info for (1-" << MAX << ": ";
cin >> E;
Emp[E-1].showInfo();
}