#include <conio.h>
#include <iostream.h>
void New(int count);
void Open(int count);
void Edit(int count);
struct Profiles
{
char Name[30];
int Age,Years,Salary;
};
Profiles Emp[20]; //Create 20 Employee profiles
void main()
{
int count=0,Item=1; //count is employee number
char Key;
bool quit=false,Menu=false;
cout << "New <\n"
<< "Open \n"
<< "Edit \n"
<< "Exit ";
gotoxy(6,1);
Key = getch();
while(quit==false) //While selection is not exit
{
if(Menu==true)
{
clrscr();
Item=1;
cout << "New <\n"
<< "Open \n"
<< "Edit \n"
<< "Exit ";
gotoxy(6,1);
Menu=false;
}
if(((Key=='e')||(Key=='E'))&&(Item==1))
{
New(count);
if(count<=20) //Dont exceed the array number!
{
count++; //Next employee
}
Menu=true;
}
else if(((Key=='e')||(Key=='E'))&&(Item==2))
{
Open(count);
Menu=true;
}
else if(((Key=='e')||(Key=='E'))&&(Item==3))
{
Edit(count);
Menu=true;
}
else if(((Key=='e')||(Key=='E'))&&(Item==4))
{
quit=true;
}
else if(((Key=='s')||(Key=='S'))&&(Item<=3)) //Go down
{
gotoxy(5,Item);
cout << " "; //Clear selection
Item++;
gotoxy(5,Item);
cout << "<"; //Put new selection
}
else if(((Key=='w')||(Key=='W'))&&(Item>=2)) //Go up
{
gotoxy(5,Item);
cout << " ";
Item--;
gotoxy(5,Item);
cout << "<";
}
else if(((Key=='w')||(Key=='W'))&&(Item<=1)) //Skip from top to bottom
{
gotoxy(5,Item);
cout << " ";
Item=4;
gotoxy(5,Item);
cout << "<";
}
else if(((Key=='s')||(Key=='S'))&&(Item>=4)) //Skip from bottom to top
{
gotoxy(5,Item);
cout << " ";
Item=1;
gotoxy(5,Item);
cout << "<";
}
Key = getch();
}
}
void New(int count)
{
clrscr();
if(count<20)
{
cout << "Please enter employee " << (count+1) << " name: ";
cin >> Emp[count].Name;
cout << "Please enter employee " << (count+1) << " age: ";
cin >> Emp[count].Age;
cout << "How many years has employee " << (count+1) << " worked for: ";
cin >> Emp[count].Years;
Emp[count].Salary=30000*(1+(0.1*Emp[count].Years)); //Calculate new salary
cout << "\n\nThankyou.";
getch();
}
else
{
cout << "Database is full sorry!"; //Array number exceeded
getch();
}
return;
}
void Open(int count)
{
int Person=0,i;
clrscr();
while(Person<count) //Output a list of names
{
cout << (Person+1) << " - " << Emp[Person].Name << endl;
Person++;
}
for(i=1;i<25;i++)
{
gotoxy(10,i);cout << "|"; //Verticle line
}
gotoxy(30,2);
cout << "Type in the employee number: ";
cin >> Person;
while(Person>count) //Validate user input
{
cout << "Error: no file exits." << endl;
cout << "Please enter employee number: ";
cin >> Person;
}
Person--;
clrscr();
cout << "Name : " << Emp[Person].Name << endl;
cout << "Age : " << Emp[Person].Age << endl;
cout << "Years : " << Emp[Person].Years << endl;
cout << "Salary : " << Emp[Person].Salary << endl << endl;
cout << "Press any key to continue.";
getch();
return;
}
void Edit(int count)
{
int Person=0,i;
clrscr();
while(Person<count)
{
cout << (Person+1) << " - " << Emp[Person].Name << endl;
Person++;
}
for(i=1;i<25;i++)
{
gotoxy(10,i);cout << "|";
}
gotoxy(30,2);
cout << "Type in the employee number: ";
cin >> Person;
while(Person>count)
{
cout << "Error: no file exits." << endl;
cout << "Please enter employee number: ";
}
Person--;
clrscr();
cout << "Name : " << Emp[Person].Name << endl; //Show old data
cout << "Age : " << Emp[Person].Age << endl;
cout << "Years : " << Emp[Person].Years << endl;
cout << "Salary : " << Emp[Person].Salary << endl << endl;
cout << "Please enter employee's Name: "; //Get new data
cin >> Emp[Person].Name;
cout << "Please enter employee's age: ";
cin >> Emp[Person].Age;
cout << "How many years worked: ";
cin >> Emp[Person].Years;
Emp[count].Salary=30000*(1+(0.1*Emp[count].Years));
cout << "\n\nPress any key to continue.";
getch();
return;
}
|