Using Structures write an interactive program in C language to create an application program for a small training company to maintain the Trainer's database. This application should be having menu options like
Creating a New Record
Reading/Listing of Records
Modify the record
Delete the record
Each Trainer record should have Trainer Name, Trainer ID, Department Name, Salary, Position, Date of Joining, etc.). The application should be designed user-friendly.
Here is a C program using structures and file handling to manage a trainer's database with options to create, read, modify, and delete records.
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FILE_NAME "trainers.dat"
struct Trainer {
int id;
char name[50];
char department[50];
float salary;
char position[50];
char date_of_joining[15];
};
void addTrainer() {
FILE *file = fopen(FILE_NAME, "ab");
struct Trainer t;
printf("\nEnter Trainer ID: ");
scanf("%d", &t.id);
printf("Enter Trainer Name: ");
scanf(" %[^\n]", t.name);
printf("Enter Department Name: ");
scanf(" %[^\n]", t.department);
printf("Enter Salary: ");
scanf("%f", &t.salary);
printf("Enter Position: ");
scanf(" %[^\n]", t.position);
printf("Enter Date of Joining (DD/MM/YYYY): ");
scanf(" %[^\n]", t.date_of_joining);
fwrite(&t, sizeof(t), 1, file);
fclose(file);
printf("\nRecord added successfully.\n");
}
void listTrainers() {
FILE *file = fopen(FILE_NAME, "rb");
struct Trainer t;
if (file == NULL) {
printf("\nNo records found.\n");
return;
}
printf("\nTrainer Records:\n");
while (fread(&t, sizeof(t), 1, file)) {
printf("\nID: %d\nName: %s\nDepartment: %s\nSalary: %.2f\nPosition: %s\nDate of Joining: %s\n",
t.id, t.name, t.department, t.salary, t.position, t.date_of_joining);
}
fclose(file);
}
void modifyTrainer() {
FILE *file = fopen(FILE_NAME, "rb+");
struct Trainer t;
int id, found = 0;
if (file == NULL) {
printf("\nNo records found.\n");
return;
}
printf("\nEnter Trainer ID to modify: ");
scanf("%d", &id);
while (fread(&t, sizeof(t), 1, file)) {
____ ________ ______ ____ ______ ____ _______ _____ ______ _______ ______ _____.
___ ___ _____ _________ ________ __________ __________.
______ _____ ______ ____ ________ ______ ______ _________ _____.
_______ ________ __________ ________ _________ ____ ______ __________ ____.
____ _______ ___ _______ _________.
__________ ______ _____ ____ ____ _______ __________.
__________ _______ _________ _____ ________ ______.
________ _____ ___ ________ __________.
______ _____ __________ _______ __________ _________ __________ __________ ___ __________ ___ _________.
___ ______ _______ ______ _______ ___ ______ __________ ______.
_________ __________ ________ _________ _______ _________ ______ ____ _____ ____.
___ ___ ___ __________ _______ _________ ___ ____.
__________ ________ _________ ___ ____ ______ ______.
_________ _____ ____ _________ ______ _______ _____ ________ ______ ____ ____ _____.
___ _____ ______ _____ ____ ___ _____ ______ ___ ____ _________ __________.
_________ ______ __________ ___ _________ ______ ____ _________ _________ ______.
_____ _____ __________ _____ _________ _______ _______ __________ _____ ____ ___ ____.
____ _________ ________ _______ ___ ______ _________.
_______ __________ ____ ______ _______ __________ ____ ________ _______ _________ _______ ______.
__________ _______ _____ ___ ____ ______ ___ _____ _______ _____ __________ _______.
_____ ______ ___ ______ _____.
__________ ___ _______ _________ ______ ______ ______.
__________ ________ ________ ____ ____ __________ ________ _____ __________ ___.
______ __________ ______ ________ __________ ______ ___ ________.
________ __________ ______ _______ ____ __________ _____ ________.
________ ____ ________ _____ _____ _________ ________ ____ ________.
____ ___ ____ ___ ________ ________.
__________ _________ _______ ____ ______ ______ ____.
__________ _________ _____ _____ _______ ___ __________ ________.
___ ________ _______ ______ _________ _________ ________ ____.
_____ __________ _____ ____ _______ ____ ________.
__________ _____ ____ ___ ___ ___ ____ _________ ___ ________ _________ ______.
_______ __________ ___ ___ ________ ______ ________ __________.
______ ________ _____ _____ _________ ________ _______ _____ ___ __________.
______ _______ ______ ____ _______ ______ ______ ______.
_____ _________ ________ _________ ____ _____ _______ _________ _________ _____ ______ ____.
___ _________ ____ ______ ____ _______ ____ _____.
_________ ____ ________ ______ ___ ______.
_____ _____ __________ _______ ________ __________.
___ ________ ___ ________ ____ ___ _____ __________.
_________ ______ __________ _______ _____ ____.
_____ _____ ____ _____ ______ _____ ___ ___ _____.
____ _____ __________ _________ ________ ________ __________.
___ ____ _________ _________ _______ ____ __________ ______ ________ ________.
___ _______ __________ ___ ______ _______ _________ ____ ___ _____ _________.
_____ __________ _____ ________ _________ _______.
____ ____ ________ ______ __________ _______ ________ _______ _______.
___ _______ _____ _________ ___ ____ __________ __________ _____.
_______ _________ ________ __________ ________ ________ ______ _______.
_______ ____ ____ _____ ________ _________ _________.
_________ _________ _____ _____ ________ _________ _______ _______ __________.
_____ ______ _______ _________ ____.
__________ ______ _________ ________ ______ ________ ______.
________ _______ ______ ________ ___ _________ ____ _________ _____ _____.
_____ __________ ____ _________ ________ _________.
___ _______ ___ ____ __________ _________ _________.
____ _____ ___ ________ ________ _______ ___ _______ _____.
____ _______ __________ ____ _______ ________ __________ ______ ______ ________ _____.
______ _______ ___ _________ ____ ____ ________ ______ ___.
________ __________ ______ _____ _________ __________ ______ ___.
________ _________ _________ __________ _______ _________ ____.
__________ ______ _________ _______ __________ _______ ___ ________ ________ __________ _____ ______.
____ _________ ________ ___ ___ ___ _______ ________.
_______ ____ ____ _________ _______.
________ ________ _____ ____ ____ __________ _______ ______ ____ __________ _________ ______.
________ __________.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required