Free Web Hosting by Netfirms
Web Hosting by Netfirms | Free Domain Names by Netfirms


Quiz 4



Test 1
Name: DatabaseTime: 1-3 hrs
Now you are required to create an employee database. It should include each employee's Name, Address, Age, Years worked for the company, and salary. It should be able to hold up to 20 employee's. The user should be able to read, edit and add to the database. This database does not have to be saved. The salary is calculated from a base of $30,000. For every year an employee has worked for the company, he/she recives a 10% pay rise.
Hints: use an array of structures, view the previous quiz and the function clrscr(); clears the screen.





Answers
Drag the cursor over the white space to highlight the answer, or rightclick - select all
Test 1Database Program , Source code


#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;
}




Back Home Next