#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <conio.h>
#include <iomanip>
using namespace std;
int main()
{
FILE *fp, *ft;
char another, choice;
struct employee
{
char first_name[50], last_name[50];
int Age;
long Salary;
};
struct employee e;
char xfirst_name[50], xlast_name[50];
long int recsize;
fp=fopen("users.txt","rb+");
if (fp == NULL)
{
fp = fopen("users.txt","wb+");
if (fp==NULL)
{
puts("Cannot open file");
return 0;
}
}
recsize = sizeof(e);
while(1)
{
system("cls");
cout << "\n\t\t###### EMPLOYEE MANAGEMENT SYSTEM ######";
cout <<"\n\n ";
cout << "\n\n";
cout << "\n \t\t\t 1. Add Employee Record";
cout << "\n \t\t\t 2. Display Employee Record";
cout << "\n \t\t\t 3. Modify Employee Record";
cout << "\n \t\t\t 4. Delete Employee Record";
cout << "\n \t\t\t 5. Exit";
cout << "\n\n";
cout << "\t\t\t Select Your Choice :=> ";
fflush(stdin);
choice = getche();
switch(choice)
{
case '1' :
fseek(fp,0,SEEK_END);
another ='Y';
while(another == 'Y' || another == 'y')
{
system("cls");
cout << "Enter the First Name : ";
cin >> e.first_name;
cout << "Enter the Last Name : ";
cin >> e.last_name;
cout << "Enter the Employee Age : ";
cin >> e.Age;
cout << "Enter the Employee Salary : ";
cin >> e.Salary;
fwrite(&e,recsize,1,fp);
cout << "\n Add Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '2':
system("cls");
rewind(fp);
cout << "=== Display Records in the Database ===";
cout << "\n";
while (fread(&e,recsize,1,fp) == 1)
{
cout << "\n";
cout << "Firstname" << setw(14) << "Lastname" << setw(10) << "Age" << setw(10) << "Salary";
cout << "\n";
cout <<"\n" << e.first_name << setw(16) << e.last_name;
cout << setw(12) <<e.Age << setw(10) << e.Salary;
}
cout << "\n\n";
system("pause");
break;
case '3' :
system("cls");
another = 'Y';
while (another == 'Y'|| another == 'y')
{
cout << "\nEnter the last name of the Employee : ";
cin >> xlast_name;
cout << "\n";
rewind(fp);
while (fread(&e,recsize,1,fp) == 1)
{
if (strcmp(e.last_name,xlast_name) == 0)
{
cout << "Enter new the First Name : ";
cin >> e.first_name;
cout << "Enter new the Last Name : ";
cin >> e.last_name;
cout << "Enter new Employee Age : ";
cin >> e.Age;
cout << "Enter new Employee Salary : ";
cin >> e.Salary;
fseek(fp, - recsize, SEEK_CUR);
fwrite(&e,recsize,1,fp);
break;
}
else
cout<<"record not found";
}
cout << "\nModify Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '4':
system("cls");
another = 'Y';
while (another == 'Y'|| another == 'y')
{
cout << "\nEnter the last name of the Employee to delete : ";
cin >> xlast_name;
ft = fopen("temp.dat", "wb");
rewind(fp);
while (fread (&e, recsize,1,fp) == 1)
if (strcmp(e.last_name,xlast_name) != 0)
{
fwrite(&e,recsize,1,ft);
}
fclose(fp);
fclose(ft);
remove("users.txt");
rename("temp.dat","users.txt");
fp=fopen("users.txt","rb+");
cout << "\nDelete Another Record (Y/N) ";
fflush(stdin);
another = getchar();
}
break;
case '5':
fclose(fp);
cout << "\n\n";
cout << "\t\t THANKS YOU!";
cout << "\n\n";
exit(0);
}
}
system("pause");
return 0;
}
新华
- 粉丝: 1w+
- 资源: 628
最新资源
- 2018级计算机系数据库实验三.zip学习资料
- JS省市区三级联动效果、JS随机生成验证码、个税计算器.zip
- 跨平台防流式 ESP 破解程序,适用于《反恐精英全球攻势》,使用现代 C++ 编写 渲染和 GUI 由 Dear ImGui + FreeType 提供支持 .zip
- 跨平台游戏引擎(Windows、Linux、Mac、Android),具有物理、线程纹理加载、多后端(OpenGL、DirectX 等)和现代流音频 .zip
- 跨平台、与图形 API 无关的“自带引擎,框架”风格渲染库 .zip
- 2024数证杯apk部分验材-1
- 资产导入器和查看器旨在以 VR 帧速率对裸体人物进行照片般逼真的渲染 .zip
- 象形文字 3 渲染引擎.zip
- 该项目的主要目标是生成和可视化使用体素构建的地形 为了进行性能和实施比较,我们使用了不同的方法和计算技术来实现 .zip
- 大三年级2021年秋《计算机体系结构》课程实验部分.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈