Practical8 2024 PF
Practical8 2024 PF
CO Mapping: CO4
Problem Definition: Write a program to create a structure Employee with members as employee id, name,
salary and date_of_joining and age. Use nested structure to get the date of joining of an employee. Read
information for ‘n’ employees. Display employee details in the format
Name EMP_ID Salary Date of Joining Age
struct_var.member=value;
Example:
s1.name=”Alice”;
struct Employee {
int id;
char name[50];
float salary;
char date_of_joining[11];
int age;
};
int main() {
int n;
printf("Enter number of employees: ");
scanf("%d", &n);
sortEmployees(employees, n);
return 0;
}
b) Definition: Write a program to create a structure Employee with members as
employee id, name, salary, date of joining and age. Sort it on the basis of Salary in
descending order.
struct Date {
int day;
int month;
int year;
};
struct Employee {
int id;
char name[50];
float salary;
struct Date joiningDate;
int age;
};
void sortEmployeesBySalary(struct Employee employees[], int n) {
struct Employee temp;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (employees[i].salary < employees[j].salary) {
temp = employees[i];
employees[i] = employees[j];
employees[j] = temp;
}
}
}
}
int main() {
int n = 3;
struct Employee employees[3] = {
{1, "Alice", 50000, {1, 1, 2020}, 30},
{2, "Bob", 60000, {1, 2, 2019}, 28},
{3, "Charlie", 55000, {1, 3, 2021}, 25}
};
sortEmployeesBySalary(employees, n);
return 0;
}
The program was tested for different sets of inputs.
Program is working is SATISFACTORY NOT SATISFACTORY ( Tick appropriate outcome)
Evaluation:
On time Completion and Knowledge of the topic Implementation and Total (10)
Submission (2) (4) Output (4)