CLDA Loan Management Application: View, Request, Sort and Accept Loans
VerifiedAdded on 2023/05/28
|14
|3975
|327
AI Summary
This article provides step-by-step instructions and code snippets for viewing loan requests, requesting a loan, viewing loan offers, sorting loan offers, accepting loan offers, viewing account wallet, and saving and exiting the CLDA Loan Management Application.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Following are MENU items in application:
1. View Loan Requests
2. Request a Loan
3. View Loan Offers
4. Sort Loan Offers
5. Accept Loan Offer
6. View Account Wallet
7. Save and Exit CLDA
View Loan Request:
This option in application will help user to a detail of loans requested in proper format.
Steps to execute this operation are:
1. Open file in read mode where loan offer details are stored.
2. Check file exist or not. If not exist display proper message and return to main menu.
3. If file exist then read loan details from file using loop and store it in to a structure.
4. Display the details on screen using structure.
Request Loan:
This operation will create new request for user about loan.
Steps to execute this operation are:
1. Ask loan details from user.
2. Store it into a structure.
3. Open loan request file in append mode and add new detail in file.
View Loan Offer:
This operation will display all loan offer details to user along with offer time interest rate.
Steps to execute this operation are:
1. Open file in read mode where loan offer details are stored.
2. Check file exist or not. If not exist display proper message and return to main menu.
3. If file exist then read loan details from file using loop and store it in to a structure.
4. Display the details on screen using structure.
Sort Loan Offers.
This operation will help to sort all offered loans based on interest rate, so that it can help
user to accept the offered loan.
1. Read structure data.
1. View Loan Requests
2. Request a Loan
3. View Loan Offers
4. Sort Loan Offers
5. Accept Loan Offer
6. View Account Wallet
7. Save and Exit CLDA
View Loan Request:
This option in application will help user to a detail of loans requested in proper format.
Steps to execute this operation are:
1. Open file in read mode where loan offer details are stored.
2. Check file exist or not. If not exist display proper message and return to main menu.
3. If file exist then read loan details from file using loop and store it in to a structure.
4. Display the details on screen using structure.
Request Loan:
This operation will create new request for user about loan.
Steps to execute this operation are:
1. Ask loan details from user.
2. Store it into a structure.
3. Open loan request file in append mode and add new detail in file.
View Loan Offer:
This operation will display all loan offer details to user along with offer time interest rate.
Steps to execute this operation are:
1. Open file in read mode where loan offer details are stored.
2. Check file exist or not. If not exist display proper message and return to main menu.
3. If file exist then read loan details from file using loop and store it in to a structure.
4. Display the details on screen using structure.
Sort Loan Offers.
This operation will help to sort all offered loans based on interest rate, so that it can help
user to accept the offered loan.
1. Read structure data.
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
2. Apply bubble sort algorithm to sort an array of structure.
Following is the code for the same:
void sort_loan_offers()
{
int i=0, j=0;
struct LoanOfferData lod;
for(i = 0 ; i < (TotalOffer-1) ; i++)
{
for(j = (i+1) ; j < TotalOffer ; j++)
{
if(LoanData[i].OfferRate < LoanData[j].OfferRate)
{
lod = LoanData[i];
LoanData[i] = LoanData[j];
LoanData[j] = lod;
}
}
}
printf("\n\nTotal Loan Offers = %d",TotalOffer);
PrintLoanOfferData();
}
Accept loan offer:
This operation will allow user to accept a loan offered by bank.
Steps to execute this operation are:
1. Display offered loan details along with serial number.
2. Ask user to enter serial number of loan which he/she want to accept.
3. Change status of that loan from Not Accepted to Accepted.
View Account wallet.
This operation will allow user to view his/her account information.
Save and exit.
This operation will save all data from structure to the text file for permanent storage.
Complete code of this application
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dirent.h>
//global variable declaration:
Following is the code for the same:
void sort_loan_offers()
{
int i=0, j=0;
struct LoanOfferData lod;
for(i = 0 ; i < (TotalOffer-1) ; i++)
{
for(j = (i+1) ; j < TotalOffer ; j++)
{
if(LoanData[i].OfferRate < LoanData[j].OfferRate)
{
lod = LoanData[i];
LoanData[i] = LoanData[j];
LoanData[j] = lod;
}
}
}
printf("\n\nTotal Loan Offers = %d",TotalOffer);
PrintLoanOfferData();
}
Accept loan offer:
This operation will allow user to accept a loan offered by bank.
Steps to execute this operation are:
1. Display offered loan details along with serial number.
2. Ask user to enter serial number of loan which he/she want to accept.
3. Change status of that loan from Not Accepted to Accepted.
View Account wallet.
This operation will allow user to view his/her account information.
Save and exit.
This operation will save all data from structure to the text file for permanent storage.
Complete code of this application
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <dirent.h>
//global variable declaration:
int TotalOffer = 0;
int TotalRequest = 0;
/**
* Function Name :
* Description :
* @param (Data Ttpe : | Data Value : )
* @return (Data Ttpe : | Data Value : )
*/
/**
* Structure Name : "LoanRequestData"
* Description : This will contain data members which can hold the data of
requested loans.
*/
struct LoanRequestData
{
time_t RequestTime;
float AmountRequested;
float AmountPledged;
int LoanPeriod;
float InterestRate;
int Status;
}*LoanReqData;
/**
* Structure Name : "LoanOfferData"
* Description : This will contain data members which can hold the data of Offered
loans.
*/
struct LoanOfferData
{
char FileName[100];
time_t RequestTimeStamp;
time_t OfferTimeStamp;
char OfferAddress[60];
float OfferRate;
int AcceptedFlag;
}*LoanData;
/**
* Function Name : "DeleteOldLoan"
* Description : Function will delete loan offered before 72 hours
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : int | Data Value : user's choice)
*/
void DeleteOldLoan()
{
long current_time;
int i;
time_t epoch = time(NULL);
current_time = (long)epoch;
for(i=0;i<TotalOffer;i++)
{
if(current_time - (long)(LoanData[i].OfferTimeStamp) > (72*60*60))
{
printf("\n\n%s File Removed...!!!",LoanData[i].FileName);
remove(LoanData[i].FileName);
}
}
getch();
}
int TotalRequest = 0;
/**
* Function Name :
* Description :
* @param (Data Ttpe : | Data Value : )
* @return (Data Ttpe : | Data Value : )
*/
/**
* Structure Name : "LoanRequestData"
* Description : This will contain data members which can hold the data of
requested loans.
*/
struct LoanRequestData
{
time_t RequestTime;
float AmountRequested;
float AmountPledged;
int LoanPeriod;
float InterestRate;
int Status;
}*LoanReqData;
/**
* Structure Name : "LoanOfferData"
* Description : This will contain data members which can hold the data of Offered
loans.
*/
struct LoanOfferData
{
char FileName[100];
time_t RequestTimeStamp;
time_t OfferTimeStamp;
char OfferAddress[60];
float OfferRate;
int AcceptedFlag;
}*LoanData;
/**
* Function Name : "DeleteOldLoan"
* Description : Function will delete loan offered before 72 hours
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : int | Data Value : user's choice)
*/
void DeleteOldLoan()
{
long current_time;
int i;
time_t epoch = time(NULL);
current_time = (long)epoch;
for(i=0;i<TotalOffer;i++)
{
if(current_time - (long)(LoanData[i].OfferTimeStamp) > (72*60*60))
{
printf("\n\n%s File Removed...!!!",LoanData[i].FileName);
remove(LoanData[i].FileName);
}
}
getch();
}
/**
* Function Name : "display_menu"
* Description : Function will display main menu optrions require to perform
transactions.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : int | Data Value : user's choice)
*/
int display_menu()
{
int choice = 0;
system("CLS");
printf("\n 1. View Loan Requests.");
printf("\n 2. Request a Loan.");
printf("\n 3. View Loan Offers.");
printf("\n 4. Sort Loan Offers.");
printf("\n 5. Accept Loan Offer.");
printf("\n 6. View Account Wallet.");
printf("\n 7. Save and Exit CLDA.");
printf("\n\nEnter your choice : ");
scanf("%d",&choice);
return choice;
}
/**
* Function Name : PrintLoanRequestData
* Description : Print details of requested loans
* @param (Data Ttpe : LoanRequestData| Data Value : Object of structure
LoanRequestData)
* @return (Data Ttpe : VOID| Data Value : )
*/
void PrintLoanRequestData (struct LoanRequestData lrd)
{
printf("%16.2f%16.2f%13d%15.2f%8d %s",lrd.AmountRequested,
lrd.AmountPledged, lrd.LoanPeriod, lrd.InterestRate, lrd.Status,
asctime(gmtime(&(lrd.RequestTime))));
}
/**
* Function Name : "load_request_data"
* Description : Function will read text file in which data for requested loan is
stored, and load those
* data into an array of structure object
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void load_request_data()
{
time_t epoch;
int i = 0;
char string[200];
int count = 0; //count and store total number of records in loanrequest
file.
struct LoanRequestData *LRD;
FILE *infile;
//reading and counting total number of records from file.
infile = fopen("D:\\886866\\LoanRequest.txt","r");
if(infile == NULL)
printf("\nFile Can't Open");
* Function Name : "display_menu"
* Description : Function will display main menu optrions require to perform
transactions.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : int | Data Value : user's choice)
*/
int display_menu()
{
int choice = 0;
system("CLS");
printf("\n 1. View Loan Requests.");
printf("\n 2. Request a Loan.");
printf("\n 3. View Loan Offers.");
printf("\n 4. Sort Loan Offers.");
printf("\n 5. Accept Loan Offer.");
printf("\n 6. View Account Wallet.");
printf("\n 7. Save and Exit CLDA.");
printf("\n\nEnter your choice : ");
scanf("%d",&choice);
return choice;
}
/**
* Function Name : PrintLoanRequestData
* Description : Print details of requested loans
* @param (Data Ttpe : LoanRequestData| Data Value : Object of structure
LoanRequestData)
* @return (Data Ttpe : VOID| Data Value : )
*/
void PrintLoanRequestData (struct LoanRequestData lrd)
{
printf("%16.2f%16.2f%13d%15.2f%8d %s",lrd.AmountRequested,
lrd.AmountPledged, lrd.LoanPeriod, lrd.InterestRate, lrd.Status,
asctime(gmtime(&(lrd.RequestTime))));
}
/**
* Function Name : "load_request_data"
* Description : Function will read text file in which data for requested loan is
stored, and load those
* data into an array of structure object
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void load_request_data()
{
time_t epoch;
int i = 0;
char string[200];
int count = 0; //count and store total number of records in loanrequest
file.
struct LoanRequestData *LRD;
FILE *infile;
//reading and counting total number of records from file.
infile = fopen("D:\\886866\\LoanRequest.txt","r");
if(infile == NULL)
printf("\nFile Can't Open");
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
else
while(!feof(infile))
{
fscanf(infile,"%s",string);fscanf(infile,"%s",string);fscanf(infile,"%s",string);
fscanf(infile,"%s",string);fscanf(infile,"%s",string);
count++;
}
fclose(infile);
TotalRequest = count;
//Dynamic Memory Allocation
LoanReqData = (struct LoanRequestData *) malloc (count*sizeof(struct
LoanRequestData));
infile = fopen("D:\\886866\\LoanRequest.txt","r");
if(infile == NULL)
printf("\nFile Can't Open");
else
{
printf("\n\nFollowing are the details of Loan Requested...!!!\n");
printf("=================================================\n");
printf("\nAmount_Requested Amount_Pledged Loan_Period
Interest_Rate Status Request_Time_Stamp");
printf("\
n--------------------------------------------------------------------------------
--------------\n");
while(!feof(infile))
{
//reading requested loan details
fscanf(infile,"%s",string);
LoanReqData[i].RequestTime = atol(string);
fscanf(infile,"%s",string);
LoanReqData[i].AmountRequested = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].AmountPledged = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].LoanPeriod = atoi(string);
fscanf(infile,"%s",string);
LoanReqData[i].InterestRate = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].Status = atoi(string);
PrintLoanRequestData(LoanReqData[i]);
i++;
}
fclose(infile);
}
}
/**
* Function Name : "PrintLoanOfferData"
* Description : this function will print data of offered loan
* @param (Data Ttpe : LoanOfferData | Data Value : Object of structure)
* @return (Data Ttpe : VOID | Data Value : Nothing )
*/
while(!feof(infile))
{
fscanf(infile,"%s",string);fscanf(infile,"%s",string);fscanf(infile,"%s",string);
fscanf(infile,"%s",string);fscanf(infile,"%s",string);
count++;
}
fclose(infile);
TotalRequest = count;
//Dynamic Memory Allocation
LoanReqData = (struct LoanRequestData *) malloc (count*sizeof(struct
LoanRequestData));
infile = fopen("D:\\886866\\LoanRequest.txt","r");
if(infile == NULL)
printf("\nFile Can't Open");
else
{
printf("\n\nFollowing are the details of Loan Requested...!!!\n");
printf("=================================================\n");
printf("\nAmount_Requested Amount_Pledged Loan_Period
Interest_Rate Status Request_Time_Stamp");
printf("\
n--------------------------------------------------------------------------------
--------------\n");
while(!feof(infile))
{
//reading requested loan details
fscanf(infile,"%s",string);
LoanReqData[i].RequestTime = atol(string);
fscanf(infile,"%s",string);
LoanReqData[i].AmountRequested = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].AmountPledged = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].LoanPeriod = atoi(string);
fscanf(infile,"%s",string);
LoanReqData[i].InterestRate = atof(string);
fscanf(infile,"%s",string);
LoanReqData[i].Status = atoi(string);
PrintLoanRequestData(LoanReqData[i]);
i++;
}
fclose(infile);
}
}
/**
* Function Name : "PrintLoanOfferData"
* Description : this function will print data of offered loan
* @param (Data Ttpe : LoanOfferData | Data Value : Object of structure)
* @return (Data Ttpe : VOID | Data Value : Nothing )
*/
void PrintLoanOfferData ()
{
int i = 0;
printf("\n\nFollowing are the details of Offered Loan:\n\n");
printf("SrNo. Offer Address Offer Rate Status
Offer Time Stamp\n\n");
printf("-------------------------------------------------------------------------
-------------------------\n");
for(i = 0; i < TotalOffer; i++)
{
printf("%2d.)",i);
printf("%42s", LoanData[i].OfferAddress);
printf("%12.2f",LoanData[i].OfferRate);
if(LoanData[i].AcceptedFlag == 0)
printf(" Not Accepted");
else
printf("Accepted");
printf(" %s",asctime(gmtime(&(LoanData[i].OfferTimeStamp))));
printf("-------------------------------------------------------------------------
-------------------------\n");
}
}
/**
* Function Name : Store_OfferLoan_Data
* Description :
* @param (Data Ttpe : char *, char *, char *, int | Data Value : FilePath,
ReqTimeStamp, offertimestamp, record no.)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void Store_OfferLoan_Data(char *path, char *reqtime, char *offertime, int j)
{
char string[200];
char addr[60]="";
FILE *readFile = fopen(path, "r");
strcpy(LoanData[j].FileName,path);
LoanData[j].RequestTimeStamp = atol(reqtime);
LoanData[j].OfferTimeStamp = atol(offertime);
if(readFile == NULL)
printf("\nFile Can't Open");
else
{
while(!feof(readFile)) //this loop will read the file till end
{
fscanf(readFile,"%s",addr);
//LoanData[j].OfferAddress = string;
strcpy(LoanData[j].OfferAddress,addr);
//printf("\nnew - %s",LoanData[j].OfferAddress);
//getch();
fscanf(readFile,"%s",string);
LoanData[j].OfferRate = atof(string);
fscanf(readFile,"%s",string);
LoanData[j].AcceptedFlag = atoi(string);
}
fclose(readFile);
{
int i = 0;
printf("\n\nFollowing are the details of Offered Loan:\n\n");
printf("SrNo. Offer Address Offer Rate Status
Offer Time Stamp\n\n");
printf("-------------------------------------------------------------------------
-------------------------\n");
for(i = 0; i < TotalOffer; i++)
{
printf("%2d.)",i);
printf("%42s", LoanData[i].OfferAddress);
printf("%12.2f",LoanData[i].OfferRate);
if(LoanData[i].AcceptedFlag == 0)
printf(" Not Accepted");
else
printf("Accepted");
printf(" %s",asctime(gmtime(&(LoanData[i].OfferTimeStamp))));
printf("-------------------------------------------------------------------------
-------------------------\n");
}
}
/**
* Function Name : Store_OfferLoan_Data
* Description :
* @param (Data Ttpe : char *, char *, char *, int | Data Value : FilePath,
ReqTimeStamp, offertimestamp, record no.)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void Store_OfferLoan_Data(char *path, char *reqtime, char *offertime, int j)
{
char string[200];
char addr[60]="";
FILE *readFile = fopen(path, "r");
strcpy(LoanData[j].FileName,path);
LoanData[j].RequestTimeStamp = atol(reqtime);
LoanData[j].OfferTimeStamp = atol(offertime);
if(readFile == NULL)
printf("\nFile Can't Open");
else
{
while(!feof(readFile)) //this loop will read the file till end
{
fscanf(readFile,"%s",addr);
//LoanData[j].OfferAddress = string;
strcpy(LoanData[j].OfferAddress,addr);
//printf("\nnew - %s",LoanData[j].OfferAddress);
//getch();
fscanf(readFile,"%s",string);
LoanData[j].OfferRate = atof(string);
fscanf(readFile,"%s",string);
LoanData[j].AcceptedFlag = atoi(string);
}
fclose(readFile);
}
}
/**
* Function Name : "load_loan_offers"
* Description : Will read all loan offering files and display content of file on
screen
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void load_loan_offers()
{
struct dirent *de; // Pointer for directory entry
char *str;// = "strtok needs to be called several times to split a string";
char delim[] = "_";
char *RequestTimeStamp;
char *OfferTimeStamp;
int FileCounter = 0,i = 0;
//char FilePath[] = "";
// opendir() returns a pointer of DIR type.
DIR *dr = opendir("D:\\886866\\Offers");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return;
}
while ((de = readdir(dr)) != NULL)
{
str = de->d_name;
FileCounter++;
}
TotalOffer = (FileCounter-2);
//dynamic memory allocation
LoanData = (struct LoanOfferData *) malloc(TotalOffer*sizeof(struct
LoanOfferData));
dr = opendir("D:\\886866\\Offers");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory");
return;
}
while ((de = readdir(dr)) != NULL)
{
const char *str2;
char FilePath[200]="";
str2 = de->d_name; // get full file name including extension.
str = de->d_name;
strcat(FilePath,"D:\\886866\\Offers\\");
if(!(strcmp(str2,".") == 0 || strcmp(str2,"..") == 0))
{
strcat(FilePath,str2);
}
/**
* Function Name : "load_loan_offers"
* Description : Will read all loan offering files and display content of file on
screen
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void load_loan_offers()
{
struct dirent *de; // Pointer for directory entry
char *str;// = "strtok needs to be called several times to split a string";
char delim[] = "_";
char *RequestTimeStamp;
char *OfferTimeStamp;
int FileCounter = 0,i = 0;
//char FilePath[] = "";
// opendir() returns a pointer of DIR type.
DIR *dr = opendir("D:\\886866\\Offers");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory" );
return;
}
while ((de = readdir(dr)) != NULL)
{
str = de->d_name;
FileCounter++;
}
TotalOffer = (FileCounter-2);
//dynamic memory allocation
LoanData = (struct LoanOfferData *) malloc(TotalOffer*sizeof(struct
LoanOfferData));
dr = opendir("D:\\886866\\Offers");
if (dr == NULL) // opendir returns NULL if couldn't open directory
{
printf("Could not open current directory");
return;
}
while ((de = readdir(dr)) != NULL)
{
const char *str2;
char FilePath[200]="";
str2 = de->d_name; // get full file name including extension.
str = de->d_name;
strcat(FilePath,"D:\\886866\\Offers\\");
if(!(strcmp(str2,".") == 0 || strcmp(str2,"..") == 0))
{
strcat(FilePath,str2);
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
//split file name using delimeter '_' to get request time
stamp and offer time stamp from file name.
RequestTimeStamp = strtok(str, delim);
OfferTimeStamp = strtok(NULL, delim);
Store_OfferLoan_Data(FilePath, RequestTimeStamp,
OfferTimeStamp, i++);
}
}
closedir(dr);
return;
}
/**
* Function Name : "sort_loan_offers"
* Description : This function will sort the data of loan offers by it's time
stamp and interesr rate.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void sort_loan_offers()
{
int i=0, j=0;
struct LoanOfferData lod;
for(i = 0 ; i < (TotalOffer-1) ; i++)
{
for(j = (i+1) ; j < TotalOffer ; j++)
{
if(LoanData[i].OfferRate < LoanData[j].OfferRate)
{
lod = LoanData[i];
LoanData[i] = LoanData[j];
LoanData[j] = lod;
}
}
}
printf("\n\nTotal Loan Offers = %d",TotalOffer);
PrintLoanOfferData();
}
/**
* Function Name : "request_loan"
* Description : This function will allow user to request for a loan.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void request_loan()
{
FILE *infile;
//decleration of local membets of LoanRequestData structure.
float AR = 0.0; //AmountRequested
float AP = 0.0; //AmountPledged
int PL = 0; //LoanPeriod
float IR = 0.0; //InterestRate
int S = 0; //Status
stamp and offer time stamp from file name.
RequestTimeStamp = strtok(str, delim);
OfferTimeStamp = strtok(NULL, delim);
Store_OfferLoan_Data(FilePath, RequestTimeStamp,
OfferTimeStamp, i++);
}
}
closedir(dr);
return;
}
/**
* Function Name : "sort_loan_offers"
* Description : This function will sort the data of loan offers by it's time
stamp and interesr rate.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void sort_loan_offers()
{
int i=0, j=0;
struct LoanOfferData lod;
for(i = 0 ; i < (TotalOffer-1) ; i++)
{
for(j = (i+1) ; j < TotalOffer ; j++)
{
if(LoanData[i].OfferRate < LoanData[j].OfferRate)
{
lod = LoanData[i];
LoanData[i] = LoanData[j];
LoanData[j] = lod;
}
}
}
printf("\n\nTotal Loan Offers = %d",TotalOffer);
PrintLoanOfferData();
}
/**
* Function Name : "request_loan"
* Description : This function will allow user to request for a loan.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void request_loan()
{
FILE *infile;
//decleration of local membets of LoanRequestData structure.
float AR = 0.0; //AmountRequested
float AP = 0.0; //AmountPledged
int PL = 0; //LoanPeriod
float IR = 0.0; //InterestRate
int S = 0; //Status
time_t CurentTime = (long)(time(NULL));
infile = fopen("D:\\886866\\LoanRequest.txt","a");
if(infile == NULL)
printf("\nFile Can't Open");
else
{
printf("\n\nPlease specify loan terms: \n\n");
fflush(stdin);
printf("\nPlease entere the requested amount : ");
scanf("%f",&AR);
//printf("\n%f",AR);
//getch();
AP = AR * 4.0;
fflush(stdin);
printf("\nPlease Enter Loan Period in Months :");
scanf("%d",&PL);
fflush(stdin);
printf("\nPlease enter Max Monthly Interest : ");
scanf("%f",&IR);
S = 0;
printf("\n%ld %7.2f %7.2f %d %3.2f %d",(long)(time(NULL)),AR, AP, PL,
IR, S);
fprintf(infile,"\n%ld %7.2f %7.2f %d %3.2f %d",(long)(time(NULL)),AR,
AP, PL, IR, S);
fclose(infile);
load_request_data();
}
}
/**
* Function Name : "accept_loan_offer"
* Description : This function will Accept the offered loan.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void accept_loan_offer()
{
int n=0;
PrintLoanOfferData();
while(1)
{
printf("\nEnter SrNo. Which Loan you need to accept? ");
scanf("%d",&n);
if(n < TotalOffer && n >= 0)
{
LoanData[n].AcceptedFlag = 1;
PrintLoanOfferData();
break;
}
else
printf("\n\nPlease enter valid number...!!!");
}
}
/**
* Function Name : "view_account_wallet"
infile = fopen("D:\\886866\\LoanRequest.txt","a");
if(infile == NULL)
printf("\nFile Can't Open");
else
{
printf("\n\nPlease specify loan terms: \n\n");
fflush(stdin);
printf("\nPlease entere the requested amount : ");
scanf("%f",&AR);
//printf("\n%f",AR);
//getch();
AP = AR * 4.0;
fflush(stdin);
printf("\nPlease Enter Loan Period in Months :");
scanf("%d",&PL);
fflush(stdin);
printf("\nPlease enter Max Monthly Interest : ");
scanf("%f",&IR);
S = 0;
printf("\n%ld %7.2f %7.2f %d %3.2f %d",(long)(time(NULL)),AR, AP, PL,
IR, S);
fprintf(infile,"\n%ld %7.2f %7.2f %d %3.2f %d",(long)(time(NULL)),AR,
AP, PL, IR, S);
fclose(infile);
load_request_data();
}
}
/**
* Function Name : "accept_loan_offer"
* Description : This function will Accept the offered loan.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void accept_loan_offer()
{
int n=0;
PrintLoanOfferData();
while(1)
{
printf("\nEnter SrNo. Which Loan you need to accept? ");
scanf("%d",&n);
if(n < TotalOffer && n >= 0)
{
LoanData[n].AcceptedFlag = 1;
PrintLoanOfferData();
break;
}
else
printf("\n\nPlease enter valid number...!!!");
}
}
/**
* Function Name : "view_account_wallet"
* Description : This function display an account information of user.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void view_account_wallet()
{
//can't identify current user.
}
/**
* Function Name : "save_Loandata"
* Description : This function will save all changed data.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void save_Loandata()
{
int i;
for(i = 0; i < TotalOffer; i++)
{
FILE *writefile = fopen(LoanData[i].FileName,"w");
//printf("\n%s",LoanData[i].FileName);
//getch();
if(writefile == NULL)
{
printf("\n\nFile can't be open");
}
else
{
fprintf(writefile,"%s %f
%d",LoanData[i].OfferAddress,LoanData[i].OfferRate,LoanData[i].AcceptedFlag);
fclose(writefile);
}
}
}
/**
* Function Name : "exit_CLDA"
* Description : This function will terminate application.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void exit_CLDA()
{
exit(1);
}
int main()
{
int flag=0;
while(1)
{
switch(display_menu())
{
case 1:
load_request_data(); //load and print requested data.
DeleteOldLoan();
break;
case 2:
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void view_account_wallet()
{
//can't identify current user.
}
/**
* Function Name : "save_Loandata"
* Description : This function will save all changed data.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void save_Loandata()
{
int i;
for(i = 0; i < TotalOffer; i++)
{
FILE *writefile = fopen(LoanData[i].FileName,"w");
//printf("\n%s",LoanData[i].FileName);
//getch();
if(writefile == NULL)
{
printf("\n\nFile can't be open");
}
else
{
fprintf(writefile,"%s %f
%d",LoanData[i].OfferAddress,LoanData[i].OfferRate,LoanData[i].AcceptedFlag);
fclose(writefile);
}
}
}
/**
* Function Name : "exit_CLDA"
* Description : This function will terminate application.
* @param (Data Ttpe : VOID | Data Value : Nothing)
* @return (Data Ttpe : VOID | Data Value : Nothing)
*/
void exit_CLDA()
{
exit(1);
}
int main()
{
int flag=0;
while(1)
{
switch(display_menu())
{
case 1:
load_request_data(); //load and print requested data.
DeleteOldLoan();
break;
case 2:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
request_loan(); //generate neew request for loan
break;
case 3:
if(flag==0)
load_loan_offers(); // load loan offer data
into structure
printf("\n\nFollowing are the details of offered loans:");
printf("\n-------------------------------------------\n\n");
PrintLoanOfferData(); //print offered loan details.
flag++;
break;
case 4:
sort_loan_offers(); //sort offered loan information
by interest rate.
break;
case 5:
accept_loan_offer(); //accept loan offer by user.
break;
case 6:
view_account_wallet(); //diaplay account information of user
break;
case 7:
save_Loandata(); //save all changes into file
exit_CLDA(); //terminate application
default:
printf("\n\nEnter choice between 1 and 7 only...!!!");
}
printf("\n\nPress any key to continue...!!!");
getch();
}
return 0;
}
SCREEN SHOTS
Operation No 3. View Loan Offered
break;
case 3:
if(flag==0)
load_loan_offers(); // load loan offer data
into structure
printf("\n\nFollowing are the details of offered loans:");
printf("\n-------------------------------------------\n\n");
PrintLoanOfferData(); //print offered loan details.
flag++;
break;
case 4:
sort_loan_offers(); //sort offered loan information
by interest rate.
break;
case 5:
accept_loan_offer(); //accept loan offer by user.
break;
case 6:
view_account_wallet(); //diaplay account information of user
break;
case 7:
save_Loandata(); //save all changes into file
exit_CLDA(); //terminate application
default:
printf("\n\nEnter choice between 1 and 7 only...!!!");
}
printf("\n\nPress any key to continue...!!!");
getch();
}
return 0;
}
SCREEN SHOTS
Operation No 3. View Loan Offered
Generate Request for a New Loan
List offered loan.
List offered loan.
View requested loans.
Accept Loan
Accept Loan
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
Sorted list of offered loan based on it’s interest rate.
1 out of 14
Related Documents
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
© 2024 | Zucol Services PVT LTD | All rights reserved.