I need help to explain what these lines of codes from C language does line by li
ID: 3772400 • Letter: I
Question
I need help to explain what these lines of codes from C language does line by line from start to finish. #include #include #include #include #define SURNAMESIZE 30 #define LASTNAMESIZE 30 #define ACCNUMBER 40 #define BANKSIZE 10000 typedef struct { char surName[SURNAMESIZE]; char lastName[LASTNAMESIZE]; char accNumber[ACCNUMBER]; float balance; } AccReg; AccReg initAccount(char accountNr[], char theSurName[], char theLastName[], float theBalance)/*ett konto skapas*/ { AccReg anAcc; strcpy(anAcc.accNumber,accountNr); strcpy(anAcc.surName,theSurName); strcpy(anAcc.lastName,theLastName); anAcc.balance=theBalance; return anAcc; } void createNewAccount (AccReg allTheAccounts[], int *fPtr,int banksize,int nrOfAcc ) { char theSurName[SURNAMESIZE]; char theLastName[LASTNAMESIZE]; char accountNr[ACCNUMBER]; float thebalance=0; if(*fPtraccNumber); printf("* The sur name : %s ", anAccPtr->surName); /* Print out the accounts */ printf("* The last name : %s ", anAccPtr->lastName); printf("* The balance : %.2f ", anAccPtr->balance); } void bubbelsort(AccReg allAccounts[],int nrOfAcc) { int n; AccReg tmpAcc; printf("Choose 1/2/3 Acc/Name/balance "); scanf("%d",&n); switch (n) { // Main sorting function for all Account records case 0: for(int times=0; times0) { tmpAcc=allAccounts[row]; allAccounts[row]=allAccounts[row+1]; allAccounts[row+1]=tmpAcc; } break; case 1: for(int times=0; times0) { tmpAcc=allAccounts[row]; allAccounts[row]=allAccounts[row+1]; allAccounts[row+1]=tmpAcc; } break; case 2: for(int times=0; timesallAccounts[row+1].balance) { tmpAcc=allAccounts[row]; allAccounts[row]=allAccounts[row+1]; allAccounts[row+1]=tmpAcc; } break; default: printf("Error "); } } void searchAcc(AccReg allAccounts[],int nrOfAcc) { int m=0; int n; char accountNumber [40]; char lastofname [30]; float min,max; printf("Choose 1/2/3 Acc/Name/balance "); scanf("%d",&n); getchar(); switch (n) { case 1: printf("Enter account number!: "); gets(accountNumber); for (int i=0; i=rec) allAccounts[i].balance=allAccounts[i].balance-rec; else printf("Not enough money "); break; case 2: printf("Enter amount: "); scanf("%f",&rec); allAccounts[i].balance=allAccounts[i].balance+rec; break; } break; } break; } } int main(void) { AccReg allAccount[BANKSIZE]; int nrAcc=0; restoreAccounts(allAccount,&nrAcc); int option; printf("0=exit 1=Create new account 2=Print all accounts record 3=Sort Account 4=Search Account 5=Modify balance 6=Delete Account "); do { printf("Enter your option! : "); scanf("%d",&option); getchar(); switch (option) { case 0: printf("exit "); saveAccounts(allAccount,nrAcc); break; case 1: printf("Create new Account "); createNewAccount(allAccount,&nrAcc,BANKSIZE,nrAcc); break; case 2: printf("Print all accounts records "); if(nrAcc) for (int i=0; i
Explanation / Answer
/*
The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre-processing before the actual compilation. We'll refer to the C Preprocessor as CPP.
All preprocessor commands begin with a hash symbol (#).*/
#include<stdio.h>//Inserts a particular header from another file.
#include<string.h>//which insert aa string libraries
#define SURNAMESIZE 30//
#define LASTNAMESIZE 30//#define for constants to increase readability.
#define ACCNUMBER 40//
#define BANKSIZE 10000//#define for constants to increase readability.
//The struct statement defines a new data type, with more than one member.
typedef struct {
char surName[SURNAMESIZE];// member definition;
// member definition;here we are declare the srname,lastname and accnmber with arry representation
char lastName[LASTNAMESIZE];
char accNumber[ACCNUMBER];
float balance; }//float is floting point numbers represented
AccReg;
AccReg initAccount(char accountNr[], char theSurName[], char theLastName[], float theBalance)//fnction prototype
//in braket data varible or local varible declaration
/*ett konto skapas*/
{
AccReg anAcc;
//below used string copy string prdefined function
strcpy(anAcc.accNumber,accountNr);//string copy function which copy the accunrNR into accnumber
strcpy(anAcc.surName,theSurName);
strcpy(anAcc.lastName,theLastName);
anAcc.balance=theBalance;
return anAcc; }
//another createaccont function declared here
//function means A function is a group of statements that together perform a task.
/*A function definition in C programming consists of a function header and a function body. Here are all the parts of a function
Return Type A function may return a value. The return_type is the data type of the value the function returns. Some functions perform the desired operations without returning a value. In this case, the return_type is the keyword void.
Function Name This is the actual name of the function. The function name and the parameter list together constitute the function signature.
Parameters A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter. This value is referred to as actual parameter or argument. The parameter list refers to the type, order, and number of the parameters of a function. Parameters are optional; that is, a function may contain no parameters.
Function Body The function body contains a collection of statements that define what the function does.*/
void createNewAccount (AccReg allTheAccounts[], int *fPtr,int banksize,int nrOfAcc )
{ char theSurName[SURNAMESIZE];
char theLastName[LASTNAMESIZE];
char accountNr[ACCNUMBER];
float thebalance=0;
if(*fPtraccNumber);//if codition which checks the fptraccnmber is true or not like boolean type questions check
printf("* The sur name : %s ", anAccPtr->surName);
/* Print out the accounts all account details*/
printf("* The last name : %s ", anAccPtr->lastName);//%s means string type of data varible printing so we use %s
printf("* The balance : %.2f ", anAccPtr->balance); }
/*sorting means which sorts the number in least number to highest number
here we use bubble sort technique
*/
void bubbelsort(AccReg allAccounts[],int nrOfAcc)//function declaration of bbbelsort
{ int n; AccReg tmpAcc;
printf("Choose 1/2/3 Acc/Name/balance ");
scanf("%d",&n);//which reads the input data from user ..here we read the N number value or choice
/*
A switch statement allows a variable to be tested for equality against a list of values.
Each value is called a case,and the variable being switched on is checked for each switch case.
*/
switch (n) {
// Main sorting function for all Account records
case 0://case 0 situation
/*A for loop is a repetition control structure that
allows you to efficiently write a loop that needs to execute a specific number of times.
The syntax of a for loop in C programming language is
for ( init; condition; increment ) {
statement(s);
}
*/
for(int times=0; times0) {
tmpAcc=allAccounts[row];
allAccounts[row]=allAccounts[row+1];
allAccounts[row+1]=tmpAcc;
} break;//When a break statement is reached, the switch terminates,
// and the flow of control jumps to the next line following the switch statement
case 1: for(int times=0; times0)
{ tmpAcc=allAccounts[row];
allAccounts[row]=allAccounts[row+1];
allAccounts[row+1]=tmpAcc; } break;
case 2: for(int times=0; timesallAccounts[row+1].balance)
{ tmpAcc=allAccounts[row];
allAccounts[row]=allAccounts[row+1];
allAccounts[row+1]=tmpAcc; } break;
default: printf("Error "); } }
void searchAcc(AccReg allAccounts[],int nrOfAcc)
{ int m=0;
int n;
char accountNumber [40];
char lastofname [30];
float min,max;
printf("Choose 1/2/3 Acc/Name/balance ");
scanf("%d",&n);
getchar();//which reads only one charcter at time from user...like A ,B etc
switch (n) {
case 1: printf("Enter account number!: ");
gets(accountNumber);//whch reads the account number from user..like scanf function type
for (int i=0; i=rec)
allAccounts[i].balance=allAccounts[i].balance-rec;
else printf("Not enough money "); break;
case 2: printf("Enter amount: ");
scanf("%f",&rec);
allAccounts[i].balance=allAccounts[i].balance+rec; break; } break;
} break;
} }
//main code is started here ....after all source code is compiled then our code will be
//start execution from main function first,,here we call all local and global functions
int main(void) {
AccReg allAccount[BANKSIZE];//declaring object for structure here...
int nrAcc=0; restoreAccounts(allAccount,&nrAcc);//calling above function...a
int option;
printf("0=exit 1=Create new account 2=Print all accounts record
3=Sort Account 4=Search Account 5=Modify balance 6=Delete Account ");
do { printf("Enter your option! : ");
scanf("%d",&option);
getchar();//reading choice
switch (option){//switch case
case 0: printf("exit ");
saveAccounts(allAccount,nrAcc);//calling save accounts function
break;
case 1: printf("Create new Account ");
createNewAccount(allAccount,&nrAcc,BANKSIZE,nrAcc); break;
case 2: printf("Print all accounts records ");
if(nrAcc) for (int i=0; i
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.