Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello I need help tracing my pseudocode! #include using namespace std;struct record{ int accountno; char name[25]; char address[80]; struct record* next;};struct record *start=0,*temp;void addRecord(struct record

Hello I need help tracing my pseudocode!

#include using namespace std;struct record{ int accountno; char name[25]; char address[80]; struct record* next;};struct record *start=0,*temp;void addRecord(struct record *new_record){ //If list is empty make new_record as start node if(start==0) { start= new_record; temp=start; } //Compare with start node if new_record has less account number make it as start node else if(new_record->accountno accountno) { new_record->next = start; start=new_record; } else { temp=start; //used to find whether the new_record inserted or not int is_inserted=0; while(temp->next!=0) { //if new_record has less account number then insert after temp node //make is_inserted as 1 if(new_record->accountno next->accountno) { new_record->next = temp->next; temp->next = new_record; is_inserted=1; break; } //else move to next node else temp=temp->next; } //if new_record not inserted yet i.e. new_record has max account number than all //Then insert it at last if(is_inserted==0) { temp->next = new_record; } }}void display(){ temp=start; //Display the content of the list while(temp!=0) { cout accountno name addressnext; }}int main(){ int choice; //User input do { struct record *new_record = (struct record*)malloc(sizeof(struct record)); cout>new_record->accountno; cout> ch; cin >> new_record->name; cout>new_record->address; new_record->next=0; addRecord(new_record); cout>choice; }while(choice==1); display(); return 0;}

Instructions for tracing:

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed
Tracing After you are done, trace your pseudocode with the following test cases and fill in this file: trace.xIsx. Note: You don't have to have exactly the same data in the example. Just make up your own data for each of the test cases. 1. Adding a record to an empty list For example, . Record to add uaccountno: 1000 uname: Ravi Narayan uaddress: 1680 East-West Rd. o Heap: No record 2. Adding a record to a list that has two records (every account number is different form others) For example, o Record to add uaccountno: 1000 uname: Ravi Narayan uaddress: 1680 East-West Rd. o Heap: Record1: accountno: 1200 name: Tetsuya Idota address: 1-1 Chiyoda - Record2: accountno: 900 name: David Lassner address: 2500 Campus Rd.3. Adding a record to a list which has two records (the second existing record has the same account number as that of the new record) For example, o Record to add uaccountno: 1000 uname: Ravi Narayan uaddress: 1680 East-West Rd. o Heap: - Record1: accountno: 1100 name: David Lassner address: 2500 Campus Rd. Record2: accountno: 1000 name: Tetsuya Idota address: 1-1 Chiyoda Materials to submit Your submission must include the following: 1. Pseudocode (pseudocode . txt) for the addRecord function described above. Again, please use this template: -pseudocode.txt- !. 1. Traces that verify the algorithm for the following test cases (trace . x1sx) Again, please use this template: -trace.xIsx-!.A B C D E F G H K L M Complete the following tracing tables by examining your pseudocode. W N- Note1: the tables below are template, so please add/remove necessary/unnecessary spaces, respectively. Note2: if a value changes, keep the old value by stikethrough, e.g., "3- 5" UIA Note3: if the variable is a character array (not a character pointer), show the string in the "value" section. Note4: If the variable is a pointer (including char*), show the stored address value in the "value" section. 7 8 Size of data type (bytes) 9 tint 10 char 11 pointer .... 12 13 Test Case 1 | Adding a record to an empty list 1 1 15 Stack Heap 16 Address Name Datatype Scope Value 17 start struct record * addRecord ...... Address Name Datatype Value 18 uaccountno addRecord accountno 19 uname char 25 addRecord name 20 uaddress char 50 addRecord address 21 next i...... 22 23 Address Name Datatype Value 24 ..E.. accountno 25 name ...... 26 address ...... 27 nextA B C D E F G H K L 30 31 Test Case 2 |Adding a record to a list with two records (every account number is different form others) 33 Stack Heap F...... E.... 34 Address Name Datatype Scope Value 35 start struct record * addRecord Address Name Datatype Value 36 uaccountno int addRecord accountno 37 uname char 25] addRecord iname 38 juaddress char 50] addRecord address 39 ..... -4... next ...i.. ..i... 40 .... ...i.. 41 .4... Address Name Datatype Value 42 accountno 43 name .4... ..i.. 44 address ..A.. 45 next 46 ..... ...... 47 i.........." 48A B C D F F G H K L 48 49 Test Case 3 Adding a record to a list with two records (the second existing record has the same account number as that of the new record) 51 Stack Heap E.... 52 Address Name Datatype Scope Value 53 start struct record * addRecord Address Name Datatype Value 54 uaccountno int addRecord accountno ....... 55 uname char 25 addRecord name 56 uaddress char 50] addRecord address 57 ....... next 58 59 Address Name Datatype Value 60 accountno 61 ..4.. name 1...... ....MESS 62 address 63 next 64 65

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions