Hello, I\'ve been working on a Banking program that turns arrays into linked lis
ID: 642398 • Letter: H
Question
Hello,
I've been working on a Banking program that turns arrays into linked lists. For the most part, I have it all working but I have a few problems that I cannot seem to fix. Here is my program that I pasted in pastebin that I have done: http://pastebin.com/r21nnvX1 . The program DOES work, but a few functions I cannot get working. Specifically lines 187-202 on pastebin that correspond with functions Remove / Add nodes in linkedlist.cpp. Basically, what needs to happen is the user has to enter the account number and the balance and then it has to add / remove from the linked list.
el1 is the account Number (type string) and el2 is the balance (type double). Each node has to have both the account # and the balance associated with that.
***EDIT***
Since posting this, I've solved my problem EXCEPT for the Case 1 and 2 not working correctly in the switch. Namely, I have to translate the acct.depositBalance and acct.withdrawBalance to work in a linked list and correctly deposit / withdraw money to the accounts in the linked list.
If the c_bank.dat is needed to do this, I've included the download link in the comments but here it is again (forgot about that part): http://www.megafileupload.com/en/file/613448/c-bank-dat.html
Explanation / Answer
in a linked list we should have a head node and a tail node
each node will have a variable for holding the pointer to the next node in the list
for example - array a[5] will be represented as a1 - data, link. a2 data,link, a3 data,link. a4 data,link. a5 data,null.
if array values are a[1] = 10 a[2] = 20. a[3] = 30 a[4] = 40 a[5] = 50 then linked list will have
10, a+1 a is the name of the array and it holds the value of the address of the first array location. by adding one, two three so on we get the address of the consecutive locations of the array therefore accessing the consecutive elements
20, a+2
30, a+3
40, a+4
50, null
in a linked list we have to consciously store the address of the consecutive location in the field that will hold the address
if the linked list is declared using a struct, then
strut acc-node
{ char acc-no
double balance
struct *acc-nodeptr }
when we create the new node in the loop we have to assign the addressto the previous node and then store the data
the address of the first node created has to be stored in in a variable ( start )
when we are withdrawing the amount we accept the acc-no from the user and using a loop
we have to check the acc-no field of each node of the list.
let the variable be uaccno,
let the amt withdrawn be amtwd
struct v1;
v1.acc-nodeptr = start
while acc-nodeptr <> null
{ if v1.acc-no = uaccno
v1.balance = v1.balance - amtwd;
exit;
else
acc-nodeptr = v1.acc-nodeptr}
we use a variable acc-nodeptr that has the start address at first then we assign the address of the next from the variable of the
structure if the current instance is not the actual account number we are searching the loop
similarly if a person is depositing we have to add the amount in the balance field of the structure.
// * note : as i am unable to download the link specified i have explained the concept of linked list and converting array to linked list.
// the programmer should use appropriate program statements and structures
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.