2
Answers

I need help in converting this program to pseudocode

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#define array_size 255

struct applicantinfo
{
char fname[array_size];//applicant first name
char lname[array_size];//applicants last name
int telnum; //applicants telephone number
float salary;//amount applicant earns
float l_amt;// amount applicant wants to borrow
float amt_owed;// amount the applicant owes
float m_payments;//amont the applicant will have to pay bacl
int time;// this is the time they will take to pay back( 24, 32 or 72 months)
char approv_stat[array_size];//this will store the approval status for the applicant
};

void companyname(); //this function prints the company name
void main_menu();// this option allow the user to select which option they want
void create_applicant();//this function adds a new applicant and writes it to a file
void view_applicant();//this function allows you to search for an applicant located on a file
void append_applicant();//this function allows you to append records that are saved to a file
void search_applicant();//this function allows you to search records that are saved to the file
bool approv_Stat(struct applicantinfo applicant[array_size]);//this function determine if an applicant is approved
float amtOwed(struct applicantinfo applicant[array_size]);//this function calculates the amount the applicant will have to pay back
float mPayments(struct applicantinfo applicant[array_size]);// this function calculates the ampunt the applicant will have to pay per month
struct applicantinfo applicant[array_size];//declaring an array of struct applicant
int control_var1=0,total_amt=0,control_var2=0; //initializing counter and sum variables to 0
int main()
{
system("color 6F");//changes window color
companyname();
main_menu();//passes control to the main_menu function
return 0;
}
void companyname()
{
printf("\t\t\t QuickTime Loans Jamaica\n\t\t\t Loans At The Speed Of Light\n");
printf("\t\t 9 Columbia Avenue, Kingston 25, Jamaica\n\t\t 14 Macedonia Ave, Mandeville, Manchester,Jamaica\n");
printf("\t\t\t ***************************\n");
printf("\t\t\t Created by Nathaniel McLean\t\t\t\n");
printf("\t\t\t ***************************\n");
}
void main_menu()
{
int choice;
system("cls");//clears the screen
companyname();
system("pause");
system("cls");//clears the screen
companyname();
printf("\nMain Menu\n");
printf("\t\t\t 1. Create An Applicant\n\t\t\t 2. Search For An Applicant\n\t\t\t 3. View Applicants\n\t\t\t 4. Append Applicants\n\t\t\t 5. Exit\n");
printf("\nChoice: ");
scanf("%d",&choice);

if (choice==1){
create_applicant(); //passes control to the create applicant function
}else if (choice==2){
search_applicant(); //passes control to the search applicant function
}else if(choice==3){
view_applicant(); //passes control to the view applicant function
}else if(choice==4){
append_applicant(); //passes control to the append applicantfunction
}else if(choice==5){
system("cls");
printf("Thank you for using \n\t\t\t QuickTime Loans Jamaica\n\t\t\t Loans At The Speed Of Light\n" );
printf("\t\t\t Visit us at \n\t\t\t www.QuickTimeLoans.com\n");
printf("\t\t\t ***********************\n");
printf("\t\t\t Good Bye\n");
printf("\t\t\t ***********************\n");
system("pause");
exit(0);
}else if(choice>5){
system("cls");
system("color 4F");//changes window color for ERROR
printf("Enter A Valid Option\n");
system("pause");
system("color 6F");//changes window color to Normal
main_menu();
}else if(choice<1){
system("cls");
system("color 4F");//changes window color for ERROR
printf("Enter A Valid Option\n");
system("pause");
system("color 6F");//changes window color to Normal
main_menu();
}
}
void create_applicant(){
FILE *fwrite;
fwrite=fopen("customers.txt","w+");//opens a file for writing
system("cls");
printf("Enter Your First Name,Press 0 to exit: \n");
scanf("%s",applicant[control_var1].fname);
while(strcmp(applicant[control_var1].fname,"0")!=0){//checks to see if the user enter 0
printf("Enter Your last Name: \n");
scanf("%s",applicant[control_var1].lname);

printf("Enter Telephone Number: \n");
scanf("%d",&applicant[control_var1].telnum);

printf("Enter Amount You Want To Borrow: \n$");
scanf("%f",&applicant[control_var1].l_amt);

printf("Enter Your Salary/The Amount That You Earn: \n$");
scanf("%f",&applicant[control_var1].salary);

printf("Enter Payment Plan (24 Months,32 Months or 72 Months ): ");
scanf("%d",&applicant[control_var1].time);

applicant[control_var1].amt_owed= amtOwed(applicant); //calcualtes amount owed
applicant[control_var1].m_payments= mPayments(applicant);//calculates monthly payments
if (approv_Stat(applicant)){ /*Principle of If Statements: If condition is true then do something, the function approv_stat
returns true or false so if the value returned was true then it would yeild the same result as
if (approv_Stat(applicant)==true){
process
}
*/

//applicant[control_var1].approv_stat="Approved"; WRONG YOU CANNOT DO THIS
strcpy(applicant[control_var1].approv_stat,"Approved");
}else{
//applicant[control_var1].approv_stat="Not Approved"; WRONG YOU CANNOT DO THIS
strcpy(applicant[control_var1].approv_stat,"Not Approved");
}
control_var1++;//increment control_var1 by 1
printf("Enter Your First Name, Press 0 to exit: \n");
scanf("%s",applicant[control_var1].fname);
}//end while loop
system("cls");
if (fwrite==NULL){
printf("File Not Opened\n");
system("pause");
main_menu();
}else{
control_var2=control_var1-1;//remove last array that would of stored 0
for (control_var1=0;control_var1<=control_var2;control_var1++){
//writes all the data to the file
printf("Applicant's Data \n");
fprintf(fwrite,"%s\t %s\t %d\t",applicant[control_var1].fname,applicant[control_var2].lname,applicant[control_var1].telnum);
fprintf(fwrite," %s\t %.2f\t %.2f\t",applicant[control_var1].approv_stat,applicant[control_var1].l_amt,applicant[control_var1].salary);
fprintf(fwrite,"%d\t %.2f\t %.2f\n",applicant[control_var1].time,applicant[control_var1].amt_owed,applicant[control_var1].m_payments);

printf("Applicant Name: %s %s\n",applicant[control_var1].fname,applicant[control_var2].lname);

printf("Your Telephone Number is: %d\n",applicant[control_var1].telnum);

printf("Approval Status: %s\n",applicant[control_var1].approv_stat);

printf("The Amount You Want To Borrow: $%.2f\n",applicant[control_var1].l_amt);

printf("Enter Your Salary/The Amount That You Earn: $%.2f\n",applicant[control_var1].salary);

printf("Payment Term is: %d months\n",applicant[control_var1].time);

printf("Total Amount Owed: $%.2f\n",applicant[control_var1].amt_owed);

printf("Monthly Payment: $ %.2f\n",applicant[control_var1].m_payments);

}
system("pause");//pauses the output
system("cls");//clears the screen
main_menu();//passes control to the main menu
}
main_menu();
fclose(fwrite);
}//end function create applicant
void search_applicant(){
FILE *fread;//declares a file pointer called fread
char answer[array_size];//this will store the output
char word[array_size];//this will sotred the word that will be searched for
fread=fopen("customers.txt","r");//opens a file called customer for reading

system("cls");//clears the screen
printf("Enter Your Telephone Number: \n");
scanf("%s",word);

if(fread==NULL){//check if the filed was opened
printf("File Not Opened! ");
main_menu();
}else{
while (!feof(fread)){
fgets(answer,array_size,fread);// reads a line from a file
if (strstr(answer,word)){//if search term
printf("\t\tName\t\tTelephone\tApproved\tLoan Amount\tSalary\t\tTime\tAmount Owed\tMontly Payments\n");
fputs(answer,stdout);//prints it to the screen
printf("\n");
system("pause");
main_menu();
}else{
printf("\nSearch Term Not Found! ");
system("pause");
system("cls");
main_menu();
}
system("cls");
}
}
fclose(fread);
}
void view_applicant()
{ //int i=0;
FILE *fread;
system("color 3E");
fread=fopen("customers.txt","r");//opens a file called customer for reading
if(fread==NULL) // Checks for file
{
printf("\n FILE CANNOT BE OPENED \n");// error message
}else{
printf("FirstName\tLastName\tPhonenumber\tPayment Term\tTotal Amount Owed\tMonthly Payment\n");
fscanf (fread,"\t%s\t%s\t%d\t%d\t%d\t%d",applicant[control_var1].fname,applicant[control_var1].lname,&applicant[control_var1].telnum,applicant[control_var1].time,applicant[control_var1].amt_owed,applicant[control_var1].m_payments);
while(!feof(fread))
{
printf("%s\t%s\t%d\t%d\t%d\t%d",applicant[control_var1].fname,applicant[control_var1].lname,&applicant[control_var1].telnum,applicant[control_var1].time,applicant[control_var1].amt_owed,applicant[control_var1].m_payments);// Print from file
control_var1++; // increment
fscanf (fread,"%s\t%s\t%d\t%d\t%d\t%d",applicant[control_var1].fname,applicant[control_var1].lname,&applicant[control_var1].telnum,applicant[control_var1].time,applicant[control_var1].amt_owed,applicant[control_var1].m_payments);
}
}
fclose(fread);// close file
system("pause");//pauses the output
system("cls");//clears the screen
main_menu();//passes control to the main menu
}
void append_applicant()
{
fflush(stdin);
FILE *pAppend;
struct applicantinfo applicant[control_var1];//declaring an array of struct applicant

int v=0;

pAppend = fopen("customers.txt","a");

if(pAppend == NULL)
printf("\nFile not opened\n");

else
{
do
{
system("color F5");
printf("Enter Your First Name,Press 0 to exit: \n"); //checks to see if the user enter 0
scanf("%s",applicant[control_var1].fname);
printf("Enter Your last Name: \n");
scanf("%s",applicant[control_var1].lname);

printf("Enter Telephone Number: \n");
scanf("%d",&applicant[control_var1].telnum);

printf("Enter Amount You Want To Borrow: \n$");
scanf("%f",&applicant[control_var1].l_amt);

printf("Enter Your Salary/The Amount That You Earn: \n$");
scanf("%f",&applicant[control_var1].salary);

printf("Enter Payment Plan (24 Months,32 Months or 72 Months ): ");
scanf("%d",&applicant[control_var1].time);

applicant[control_var1].amt_owed= amtOwed(applicant); //calcualtes amount owed
applicant[control_var1].m_payments= mPayments(applicant);//calculates monthly payments
if (approv_Stat(applicant))
{ /*Principle of If Statements: If condition is true then do something, the function approv_stat
returns true or false so if the value returned was true then it would yeild the same result as
if (approv_Stat(applicant)==true){
process
}
*/

//applicant[control_var1].approv_stat="Approved"; WRONG YOU CANNOT DO THIS
strcpy(applicant[control_var1].approv_stat,"Approved");
}
else
{
//applicant[control_var1].approv_stat="Not Approved"; WRONG YOU CANNOT DO THIS
strcpy(applicant[control_var1].approv_stat,"Not Approved");
}
control_var1++;//increment control_var1 by 1
printf("Enter Your First Name, Press 0 to exit: \n");
scanf("%s",applicant[control_var1].fname);
}
while(strcmp(applicant[control_var1].fname,"0")!=0);
system("cls");
if (fwrite==NULL)
{
printf("File Not Opened\n");
system("pause");
main_menu();
}
else
{
control_var2=control_var1-1;//remove last array that would of stored 0
for (control_var1=0;control_var1<=control_var2;control_var1++)
{
//writes all the data to the file
printf("Applicant's Data \n");
fprintf(pAppend,"%s\t %s\t %d\t",applicant[control_var1].fname,applicant[control_var2].lname,applicant[control_var1].telnum);
fprintf(pAppend," %s\t %.2f\t %.2f\t",applicant[control_var1].approv_stat,applicant[control_var1].l_amt,applicant[control_var1].salary);
fprintf(pAppend,"%d\t %.2f\t %.2f\n",applicant[control_var1].time,applicant[control_var1].amt_owed,applicant[control_var1].m_payments);

printf("Applicant Name: %s %s\n",applicant[control_var1].fname,applicant[control_var2].lname);

printf("Your Telephone Number is: %d\n",applicant[control_var1].telnum);

printf("Approval Status: %s\n",applicant[control_var1].approv_stat);

printf("The Amount You Want To Borrow: $%.2f\n",applicant[control_var1].l_amt);

printf("Enter You Earn: $%.2f\n",applicant[control_var1].salary);

printf("Payment Term is: %d months\n",applicant[control_var1].time);

printf("Total Amount Owed: $%.2f\n",applicant[control_var1].amt_owed);

printf("Monthly Payment: $ %.2f\n",applicant[control_var1].m_payments);
}

system("pause");//pauses the output
system("cls");//clears the screen
printf("\n\n\t Edit Complete");
main_menu();//passes control to the main menu
}
main_menu();
fclose(pAppend);
}
}
float amtOwed(struct applicantinfo applicant[array_size]){
float amt_owed;
amt_owed=applicant[control_var1].l_amt + (.50 * applicant[control_var1].l_amt);
return amt_owed;
}
float mPayments(struct applicantinfo applicant[array_size]){
float mpay;
mpay=applicant[control_var1].amt_owed / applicant[control_var1].time;
return mpay;
}
bool approv_Stat(struct applicantinfo applicant[array_size]){
bool approv;
if (applicant[control_var1].m_payments>=(0.50 * applicant[control_var1].salary)){
approv=false;
}else{
approv=true;
}
return approv;
}
Answers (2)