Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For every program, make sure to: a) Prepare and include the testing scenarios b)

ID: 3695190 • Letter: F

Question

For every program, make sure to: a) Prepare and include the testing scenarios b) Consider the case where the list is empty or has only one node c) Clearly write any assumption For the questions below, assume the node structure is: struct node{ int data; node * next; node * prev; } Assignment 1) (12 points) Write a function to remove ALL duplicates in a doubly linked list. The function receives a pointer to the head. i.e. if the linked list with elements nullptr1221nullptr is passed as an argument, the function should modify the list to nullptr12nullptr by deleting the repeated values. Use the following function header: void removeDuplicates(node *h); 2) (8 points) Write a function that returns a doubly linked list that is the ordered union of two unordered doubly linked lists. i.e. if a linked list A with elements: nullptr472nullptr and another liked list B with elements nullptr1463nullptr are given as an input parameters, the function should return nullptr12 3 4 46 7nullptr. Use the following function header: node * concatLinkedList( node* A, node * B)

For the questions below, assume that initially baseClass has only an integer x as a private data member, and the derived class has only an integer y as a private data member. You need to provide the class definition and any function member needed i.e. set/get for each data member, constructor, destructor, etc., as well as he appropriate access modifier i.e. public, private, protected, static, virtual, friend, etc

3) Complete the following: a) (1 point) Write the base and derived class definition as well as mutators and accessors b) (2 point) Modify the base and derived classes in such a way that the statement: derivedClass *m = new derivedClass( 56, 14 ); will produce the output This is class 56 This is class 14 and the statement baseClass *n = new baseClass( 79 ); will produce the output: This is class 79 c) (2 point) Based on part b) modify the classes and write the functions such that, m- >print() will display 14, and n->print() will display 79 4) (3 points) Add an static data member count, write the initialization and increment it in such a way that when calling getCounter() after the statements in b) are executed, the function will print 2. Note: the count variable should increase when either a new instance of the base or the derived class is created. Write the code needed for the function getCounter(). 5) (2 points) Write a function printParentValue() in the derived class that will access directly the value of x, and will print it on the screen; and a function printChildValue() which is not a member function of either base or derive class, but can access y directly and display its value on the screen.

Explanation / Answer

#include<conio.h>

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

struct dlist

{

char *data;

struct dlist *prev,*next;

};

struct dlist *head,*p,*q;

void create()

{

char *k;

printf("Enter the city ");

scanf("%s",k);

if(p==NULL)

{

p=(struct dlist*)malloc(sizeof(struct dlist));

p->next=NULL;

strcpy(p->data,k);

head=q=p;

p->prev=NULL;

}

else

{

p=(struct dlist*)malloc(sizeof(struct dlist));

strcpy(p->data,k);

p->prev=q;

q->next=p;

q=p;

}

p->next=head;

head->prev=p;

}

void insert()

{

char *s1,*s2;

struct dlist *temp,*m;

printf("Enter after which city ");

scanf("%s",s1);

printf("Enter the new city ");

scanf("%s",s2);

temp=head;

m=temp->next;

while(temp->next!=head)

{

if(strcmp(s1,temp->data)==0)

{

   p=(struct dlist *)malloc(sizeof(struct dlist));

   strcpy(p->data,s2);

   temp->next=p;

   p->next=m;

   m->prev=p;

   p->prev=temp;

}

temp=temp->next;

m=m->next;

if((temp->next==head)&&(strcmp(s1,temp->data)==0))

{

   p=(struct dlist *)malloc(sizeof(struct dlist));

   strcpy(p->data,s2);

   temp->next=p;

   p->next=m;

   m->prev=p;

   p->prev=temp;

}

}

}

void dispbeg()

{

struct dlist *temp;

temp=head;

printf("farward direction ");

while(temp->next!=head)

{

printf("%s->",temp->data);

temp=temp->next;

}

printf("%s->",temp->data);

}

void dispend()

{

struct dlist *temp;

temp=head->prev;

printf(" backward direction ");

while(temp!=head)

{

printf("%s->",temp->data);

temp=temp->prev;

}

printf("%s->",temp->data);

}

void menu()

{

printf("1.Construct a list ");

printf("2.Display from front ");

printf("3.Insert after the given city ");

printf("4.Display from backward ");

printf("5.Exit ");

}

void main()

{

int ch,s,l;

char s1[10],s2[10];

clrscr();

menu();

while(1)

{

printf(" Enter your choice ");

scanf("%d",&ch);

switch(ch)

{

   case 1:create();

      break;

   case 2:dispbeg();

      break;

   case 3:insert();

      break;

   case 4:dispend();

      break;

   case 5:exit(0);

      break;

   default:

      printf("Invalid Choice ");

}

}

}