Here is my code so far for this project But I want to be able to create a file f
ID: 3815078 • Letter: H
Question
Here is my code so far for this project
But I want to be able to create a file for a lot of people, not just for one (e.g for an enterprise). My teacher said I have to use some data structure (parent and child leaves) but I don't really know how to do that. Can some help me with that, cause right now I'm just creating a record for one person. I want to create a record for many people at the same time.
#include<stdio.h>
#include<stdlib.h>
int balance,i=-1;
int withdraw(int arr[],int bal,int amt)/*for Withdrawal*/
{
i=i+1;
int j,no,flag=0;
if(i==0)
{
bal=bal-amt;
printf("Amount Succesfully Withdrawal. New Account Balance Is:%d",bal);
arr[i]=amt;
}
else
{
for(j=0;j<=i;j++)
{
if(arr[j]*1.30<=amt||arr[j]*0.70>=amt)
{
printf("");
}
else
{
bal=bal-amt;
printf(" Amount Succesfully Withdrawal. New Account Balance Is:%d",bal);
flag=1;
break;
}
}
}
if(0==flag)
{
printf(" Daviation is More Than 30 Percent. Amount Can't be Withdrawal.");
}
return bal;
}
int credit(int bal,int amt)/*for credit*/
{
bal=bal+amt;
printf("Amount Succesfully Credited. New Account Balance Is:%d",bal);
return bal;
}
int main(void)
{
long int account;
static int balance;
int ch,amt;
char country[20],name[30],c;
int arr[100];
printf(" ENTER THE ACCOUNT NUMBER:");
scanf("%ld",&account);
printf(" ENTER THE CUSTOMER NAME:");
scanf("%s",name);
printf(" ENTER THE COUNTRY:");
scanf("%s",country);
printf(" ENTER THE STARTING ACCOUNT BALANCE:");
scanf("%d",&balance);
do
{
printf(" CREDIT CARD SYSTEM 1.CREDIT 2.WITHDRAW 3.CHECK BALANCE 4.EXIT");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf(" Enter Amount to Be CREDITED:");
scanf("%d",&amt);
if(amt<1)
{
printf("INVALID AMOUNT");
}
else
{
balance=credit(balance,amt);
}
break;
case 2:
printf(" Enter Amount to WITHDRAW:");
scanf("%d",&amt);
if(amt>balance||amt<1)
{
printf(" INVALID AMOUNT OR LIMIT EXCEEDED.");
}
else
{
balance=withdraw(arr,balance,amt);
}
break;
case 3:
printf("ACCOUNT BALNACE IS:%d",balance);
break;
case 4:
exit(0);
default:
exit(0);
}
printf(" Do U Want to Continue(1 or 0):");
scanf("%d",&ch);
}while(ch==1);/*end of while*/
return 1;
}/*end of main*/
Explanation / Answer
you can use tree data structure,
you have to know the concept of structure, pointer, memory allocation function(malloc,calloc),
First, it is necessary to have a struct, or class, defined as a node.
The struct has the ability to store the key_value and contains the two child nodes which define the node as part of a tree. In fact, the node itself is very similar to the node in a linked list. A basic knowledge of the code for a linked list will be very helpful in understanding the techniques of binary trees. Essentially, pointers are necessary to allow the arbitrary creation of new nodes in the tree.
The following insert function will create a new tree if necessary; it relies on pointers to pointers in order to handle the case of a non-existent tree (the root pointing to NULL). In particular, by taking a pointer to a pointer, it is possible to allocate memory if the root pointer is NULL.
use above insert function and replace your content in a file, it will help to insert multiple records at a time.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.