Question

In: Computer Science

Write the code in C++. Write a program to implement Employee Directory. The main purpose of...

Write the code in C++.

Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it
into a file, perform some operations and display data.
For the purpose mentioned above, you should write a template class Directory for storing the data
empID(template),
empFirstName(string),
empLastName(string),
empContactNumber(string)
and
empAddress(string) of each Employee in a file EmployeeDirectory.txt.
1. Write a function Add to write the above mentioned contact details of the employee into
EmployeeDirectory.txt. The record of each employee should be written in one line having tab '\t' character
among the attributes. Consider the file below as example for EmployeeDirectory.txt

2. Write a template function SearchByID - SearchByID receives empID of type template and 4 references
(firstname, lastname, contactno, address) of type string. The return type of the function should be bool,
which should return either true or false. If the record is found, return true and copy the details of the
record into the passed references for the caller to use.
3. Also write a void function printDetails which must read the file completely and print the record stored
in EmployeeDirectory.txt.

Solutions

Expert Solution

#include <bits/stdc++.h>

using namespace std;
template<class empID, class empFirstName, class empLastName, class empContactNumber, class empAddress>
class Add
{
empID id;
empFirstName fname;
empLastName lname;
empContactNumber contact;
empAddress eaddress;

string empdata;

public:
Add(empID x, empFirstName y, empLastName z,empContactNumber a,empAddress b)
{
id=x;
fname=y;
lname=z;
contact=a;
eaddress=b;
empdata= x+ '\t'+ y+'\t'+z+'\t'+a+'\t'+b;
  
}
void AddData()
{
ofstream fileOUT("EmployeeDirectory.txt", ios::app);
fileOUT<<empdata<<endl;
fileOUT.close();
}
void printDetails()
{
char s[1000000];
   ifstream ifile;
   ifile.open("EmployeeDirectory.txt");
   if(!ifile)
   {
       cout<<"Error in opening file..!!";
       exit(0);
   }
   while(ifile.eof()==0)
   {
ifile>>s;
cout<<s<<" ";
   }
   cout<<endl;
   ifile.close();
}
};
  
int main()
{
string name="EmployeeDirectory.txt";
ifstream file(name);
if(!file)
{
fstream file;
file.open("EmployeeDirectory.txt",ios::out);

if(!file)
{
cout<<"Error in creating file!!!";
return 0;
}
  
cout<<"File created successfully.";

file.close();
}
  
string empid, empfname,emplname,empadd,empcon;
cout << "Enter a employee ID : ";
getline (cin, empid);
cout << "Enter a employee First Name : ";
getline (cin, empfname);
cout << "Enter a employee Last Name : ";
getline (cin, emplname);
cout << "Enter a employee address : ";
getline (cin, empadd);
cout << "Enter a employee Contact Number : ";
getline (cin, empcon);

Add <string, string, string,string,string> EmployeeDirectory1 (empid, empfname,emplname,empcon,empadd);

EmployeeDirectory1.AddData();
  
EmployeeDirectory1.printDetails();
return 0;
  
}


Related Solutions

Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of...
Write a program in c++ that maintains a telephone directory. The Telephone directory keeps records of people’s names and the corresponding phone numbers. The program should read a transaction file and report the result into an output file. The transaction file can include commands such as “Add”, “Delete”, “Display”, and “Update”, and “Search”. Each command is written in one line with a few other information. The “Display” Command should simply display everyone in the directory on the screen The “Add”...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise...
CODE IN C++ PLEASE Write a program to implement the algorithm that you designed in Exercise 19 of Chapter 1. Your program should allow the user to buy as many items as the user desires. Instructions for Exercise 19 of Chapter 1 have been posted below for your convenience. Exercise 19 Jason typically uses the Internet to buy various items. If the total cost of the items ordered, at one time, is $200 or more, then the shipping and handling...
Write a C code program to implement the comparisons of three integer numbers, using only conditional...
Write a C code program to implement the comparisons of three integer numbers, using only conditional operators (no if statements). Please ask the user to input random three integers. Then display the minimum, middle, and maximum number in one line. Also, please calculate and display the sum and the average value (save two digits after decimal point) of these three integers. Please write the comments line by line.
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for...
Write a program to implement and analyzing the Bubble Sort. a. Write a C++ function for Bubble Sort b. Use a dynamic array of integers in a variable size of n. c. Display the following information: 1) Total counts of comparisons 2) Total counts of shifts / moves / swaps, whichever applies d. Write a main() function to test a best, and an average cases in terms of time efficiency i. Fill out the array with random numbers for an...
Write Algoritm , code and output. In Operating Systems , . Implement a program for page...
Write Algoritm , code and output. In Operating Systems , . Implement a program for page replacement using the following a.FIFO b.LRU c.OPTIMAL
write C program to implement the priority queue with the operation insert
write C program to implement the priority queue with the operation insert
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Using the code below from “LStack.h” file, write the code for a main program that takes...
Using the code below from “LStack.h” file, write the code for a main program that takes as input an arithmetic expression. The program outputs whether the expression contains matching grouping symbols. For example, the arithmetic expressions { 25 + ( 3 – 6 ) * 8 } and 7 + 8 * 2 contains matching grouping symbols. However, the expression 5 + { ( 13 + 7 ) / 8 - 2 * 9 does not contain matching grouping symbols....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT