5:48 PM aamu.blackboard.com 8496 .. Courses Content Data Structure using Dynamic
ID: 3708026 • Letter: 5
Question
5:48 PM aamu.blackboard.com 8496 .. Courses Content Data Structure using Dynamic Memory Allocation Attached Files: D Data Structure using Dynamic Memory Allocation.pdf (134.251 KB) Please use the above Data Structure using Dynamic Memory allocation code and create a program (you write the necessary main method to this code) that does the following: 1) has a Menu which gives the user choices and based on the User choice does the task f either adding and item, deleting an item or Exiting the program 2) keeps the program running until the user chooses to Exit. DUE: on or before 11:00 am April 17 2018 via email to me with the subject line "CS215 Dynamic Memory Allocation"Explanation / Answer
// just i write the one case for demo .it will ask until you enter the exit choice.write the code for delete and printitems
and call the switch case the program automatically works
// i write the code for only Add item in main menu and what you asked in the question
solution:
#include<iostream>
#include<string>
using namespace std;
typedef string itemType;
struct nodeType;
typedef nodeType *nodeptr;
struct nodeType
{
itemType item;
nodeptr next;
};
nodeptr front=NULL;
nodeptr rear=NULL;
void additem()
{
itemType newItem;
cout<<"enter the lastname of the customer"<<endl;
cin>>newItem;
nodeptr newptr=new nodeType;
newptr->item=newItem;
newptr->next-NULL;
if(front==NULL)
{
front=rear=newptr;
}else
{
rear->next=newptr;
rear=newptr;
}
}
void printItems()
{
nodeptr itemptr=front;
nodeptr tempptr=itemptr;
while(itemptr!=NULL)
{
cout<<itemptr->next;
itemptr=tempptr->next;
tempptr=itemptr;
}
}
int main()
{
int i=1;
while(i==1)
{
char grade ;
cout<<"enter your choice"<<endl;
cout<<" 'A' for add"<<endl;
cout<<" 'D' for delete"<<endl;
cout<<" 'E' for exit"<<endl;
cin>>grade;
switch(grade) {
case 'A' :
cout << "add item" << endl;
int no=0;
cout<<"enter how many nos you want to add in list"<<endl;
cin>>no;
for(int i=0;i<no;i++)
{
additem();
}
break;
case 'D' :
//write the code for deleteitem and call
cout << "for deleting the item" << endl;
break;
case 'E' :
cout << " try again" << endl;
exit(1);
break;
default :
cout << "Invalid " << endl;
}
}
}
output
// until the exit it will ask choice
enter your choice
'A' for add
'D' for delete
'E' for exit
A
add item
enter how many nos you want to add in list
2
enter the lastname of the customer
dfg
enter the lastname of the customer
dfg
enter your choice
'A' for add
'D' for delete
'E' for exit
A
add item
enter how many nos you want to add in list
3
enter the lastname of the customer
sdf
enter the lastname of the customer
dg
enter the lastname of the customer
dfg
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.