ABC Company deals with import and export textiles. The company has few department and about 50 employees. The company has requested you to write a C++ program for file based database for employee in code blocks.
The system must also be able to add employee when new employee joined the company. The system must also be able to edit the record, search for employee record. When Employee leaves the company it must allow them
to delete the record.
You must use C++ program to create file based system to add, view, search, edit, delete the records and we should be able to exit the program
Your program must include necessary validation to accept the correct input for adding and editing record.
Sample screen design of each function is shown below:
You will need to create functions for each of the 5 menu options. Entering the number will call the correct function.
I have done the add, view, delete and exit the program. I just need program for search and edit and validation of the full program.
My program:
#include<iostream>
#include<string>
#include<iomanip>
#include<fstream>
#include<stdlib.h>
#include<string.h>
using namespace std;
void add_rec();//function declaration
void view_rec();
void edit_rec();
void search_rec();
void delete_rec();
void quit();
struct info
{
char ID[4];
char name[21];
char address[36];
int age;
double salary;
};
void add_rec()
{
system(“CLS”);
cout<<“add function.\n”<<endl;
info emp;//to hold info about stock
char answer;//to hold Y or N
//open a file for binary output.
fstream info(“employee.dat”, ios::app | ios::out | ios::binary);
do
{
//get data about a person.
cout<<“Enter the following employee data :\n”;
cin.ignore();
cout<<“Employee ID: “;
cin.getline(emp.ID,4);
cout<<“Employee name: “;
cin.getline(emp.name,21);
cout<<“Address : “;
cin.getline(emp.address,31);
cout<<” Age : “;
cin>>emp.age;
cout<<“salary: “;
cin>>emp.salary;
cin.ignore();//skip over the remaining newline.
//write the content of the info structure to the file.
info.write(reinterpret_cast<char *>(&emp), sizeof(emp));
//determine whether the user wants to write another record.
cout<<“Do you want to enter another stock record? [Y/N] : “;
cin>>answer;
cin.ignore();//skip over the remaining newline.
}while (answer == ‘Y’ || answer == ‘y’);
}
int main()
{
int choice;
cout<<“Welcome to the employee administration”<<endl;
cout<<“==========================================”<<endl;
cout<<“1. Add employee record.”<<endl;
cout<<“2. view employee record”<<endl;
cout<<“3. search employee record”<<endl;
cout<<“4. edit employee record”<<endl;
cout<<“5. Delete employee record”<<endl;
cout<<“6. exit application.”<<endl;
cout<<“==========================================\n”<<endl;
cout<<“enter your choice : “;
cin>>choice;
while(choice != 6)
{
switch(choice)
{
case 1:
add_rec();
break;
case 2:
view_rec();
break;
case 3:
search_rec();
break;
case 4:
edit_rec();
break;
case 5:
delete_rec();
break;
default:
cout<<“\n Invalid Choice”<<endl;
cout<<” you can choose between 1 to 6 numbers only.”<<endl;
break;
}
cout<<“===================================”<<endl;
cout<<“1. Add employee record.”<<endl;
cout<<“2. view employee record”<<endl;
cout<<“3. search employee record”<<endl;
cout<<“4. edit employee record”<<endl;
cout<<“5. Delete employee record”<<endl;
cout<<“6. exit application.”<<endl;
cout<<“===================================”<<endl;
cout<<” Enter Your Choice : “;
cin>>choice;
}
quit();
return 0;
}
void quit()
{
cout<<“————————————–“<<endl;
cout<<” Quiting The Application “<<endl;
cout<<“Thank You For Using The System.”<<endl;
cout<<“Bye!!Bye!!”<<endl;
//exit(0);
}
void view_rec()
{
system(“CLS”);
cout<<“View function.\n”<<endl;
info emp;
char again;
fstream info;
info.open(“employee.dat”,ios::in | ios::binary);
//test for error.
if(!info)
{
cout<<“Error opening file. program aborting.\n”;
}
cout<<“Here are the records in the file.\n”;
//read the first record from the file.
info.read(reinterpret_cast<char *>(&emp),sizeof(emp));
//while not at the end of the file, display the record.
while(!info.eof())
{
//display
cout<<” ID: “;
cout<<emp.ID<<endl;
cout<<“Name: “;
cout<<emp.name<<endl;
cout<<“Address: “;
cout<<emp.address<<endl;
cout<<“age: “;
cout<<emp.age<<endl;
cout<<“salary: “;
cout<<emp.salary<<endl;
//wait for the user to press the enter key.
cout<<“\npress the enter key to see the next record.\n”;
cin.get(again);
//read the nest record from the file.
info.read(reinterpret_cast<char*>(&emp), sizeof(emp));
}
}
void search_rec()
{
cout<<” search function under construction.”<<endl;
}
void edit_rec()
{
cout<<“under construction”<<endl;
}
void delete_rec()
{
system(“CLS”);
info emp;
ifstream info;
char ID[4];
cout<<“\n\n Delete function”;
cin.ignore();
cout<<” enter employee ID to be deleted:”;
cin.getline(ID, 4);
info.open(“employee.dat”,ios::binary);
if(!info)
{
cout<<“File could not be open !! press any key…”;
cin.ignore();
cin.get();
return;
}
ofstream outfile;
outfile.open(“temp.dat”,ios::out | ios::binary);
info.seekg(0,ios::beg);
while(info.read(reinterpret_cast<char*>(&emp),sizeof(emp)))
{
if(strcmp(emp.ID,ID)!=0)
{
outfile.write(reinterpret_cast<char*>(&emp), sizeof(emp));
}
}
outfile.close();
info.close();
remove(“employee.dat”);
rename(“temp.dat”,”employee.dat”);
cout<<“\n\n\trecord Deleted..”;
cin.ignore();
cin.get();
}
Why Work with Us
Top Quality and Well-Researched Papers
We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.
Professional and Experienced Academic Writers
We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.
Free Unlimited Revisions
If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.
Prompt Delivery and 100% Money-Back-Guarantee
All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.
Original & Confidential
We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.
24/7 Customer Support
Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.
Essays
No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.
Admissions
Admission Essays & Business Writing Help
An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.
Reviews
Editing Support
Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.
Reviews
Revision Support
If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.