Untitled
unknown
plain_text
a year ago
6.2 kB
3
Indexable
#include<bits/stdc++.h>
using namespace std;
void Employee();
void User();
void CreateProfile();
void Admin();
void CentralBank();
void ShowAllProfile();
void SearchUserProfile();
void MaxSalary();
void ShowAllEmployee();
void RemoveEmployee();
void GreedyLoanDistribution(); // New function declaration
struct userinfo {
int ID;
char name[50];
char address[50];
char branch[50];
double balance;
double loanRequested; // Additional attribute for loan requests
};
struct employeeinfo {
int ID;
char name[50];
int workingHOUR;
char address[50];
};
struct userinfo users[10000];
struct employeeinfo employees[1000];
int usercounter = 0;
int empcounter = 0;
int main() {
printf("=======================================\n");
printf("Welcome to Banking Management System\n");
printf("=======================================\n");
while (true) {
printf("Press (1) to enter 'User' Menu\n");
printf("Press (2) to enter 'Employee' Menu\n");
printf("Press (3) to enter 'Admin' Menu\n");
printf("Press (4) to request money to central bank\n");
printf("Press (5) for Greedy Loan Distribution\n"); // New feature in the menu
printf("Press (0) to exit the system\n");
printf("-------------------------------------\n");
printf("Enter your choice: ");
int n;
scanf("%d", &n);
switch (n) {
case 1:
User();
break;
case 2:
Employee();
break;
case 3:
Admin();
break;
case 4:
CentralBank();
break;
case 5:
GreedyLoanDistribution(); // Call the new feature
break;
case 0:
return 0;
default:
printf("Your input is wrong, try again.\n");
}
}
}
void User() {
printf("=======================================\n");
printf("Welcome to USER MENU\n");
printf("=======================================\n");
while (true) {
printf("Press (1) to create a new user profile\n");
printf("Press (2) to search any existing user profile\n");
printf("Press (3) to display all user profiles\n");
printf("Press (4) to display maximum balance among all users\n");
printf("Press (5) to request a loan\n");
printf("Press (0) to return to the main menu\n");
printf("-------------------------------------\n");
printf("Enter your choice: ");
int n;
scanf("%d", &n);
if (n == 1) {
CreateProfile();
}
if (n == 2) {
SearchUserProfile();
printf("\n");
}
if (n == 3) {
ShowAllProfile();
printf("\n");
}
if (n == 4) {
MaxSalary();
printf("\n");
}
if (n == 5) {
printf("Enter your ID to request a loan: ");
int id;
double loan;
scanf("%d", &id);
printf("Enter the loan amount: ");
scanf("%lf", &loan);
for (int i = 0; i < usercounter; i++) {
if (users[i].ID == id) {
users[i].loanRequested = loan;
printf("Loan request of %.2lf submitted successfully!\n", loan);
return;
}
}
printf("User ID not found!\n");
}
if (n == 0) {
break;
}
}
}
void GreedyLoanDistribution() {
printf("=======================================\n");
printf("Greedy Loan Distribution System\n");
printf("=======================================\n");
if (usercounter == 0) {
printf("No users available for loan distribution.\n");
return;
}
printf("Enter the total loan amount available: ");
double totalLoan;
scanf("%lf", &totalLoan);
// Sort users by balance in ascending order (Greedy Approach)
sort(users, users + usercounter, [](const userinfo &a, const userinfo &b) {
return a.balance < b.balance;
});
// Allocate loans
for (int i = 0; i < usercounter && totalLoan > 0; i++) {
if (users[i].loanRequested > 0) {
double allocated = min(users[i].loanRequested, totalLoan);
users[i].balance += allocated;
totalLoan -= allocated;
users[i].loanRequested -= allocated;
printf("Allocated %.2lf to User ID: %d (Remaining loan request: %.2lf)\n",
allocated, users[i].ID, users[i].loanRequested);
}
}
printf("Loan distribution completed. Remaining funds: %.2lf\n", totalLoan);
}
void CreateProfile() {
if (usercounter > 10000) {
printf("No more than 10000 users can be allowed!\n");
return;
}
struct userinfo profile;
printf("Enter User ID: ");
scanf("%d", &profile.ID);
printf("Enter User name: ");
scanf("%s", profile.name);
printf("Enter User address: ");
scanf("%s", profile.address);
printf("Enter User branch: ");
scanf("%s", profile.branch);
printf("Enter User balance: ");
scanf("%lf", &profile.balance);
profile.loanRequested = 0; // Initialize loan request to 0
printf("\n");
users[usercounter++] = profile;
}
// Remaining functions are unchanged
void ShowAllProfile() {
printf("=======================================\n");
printf("Here are all the user profiles\n");
printf("=======================================\n");
for (int i = 0; i < usercounter; i++) {
printf("ID: %d, Name: %s, Address: %s, Branch: %s, Balance: %.2lf, Loan Requested: %.2lf\n",
users[i].ID, users[i].name, users[i].address, users[i].branch, users[i].balance, users[i].loanRequested);
}
}
// The rest of the code is unchanged as per your requirement.
Editor is loading...
Leave a Comment