Prog error...plz give solution 4 this

Mar 22, 2016 at 8:36am
#include<iostream.h>
#include<conio.h>
class linked_list_stack
{
private:struct node
{
int data;
node *link;
};
node *top;
node *entry;
node *print;
node *bottom;
node *last_entry;
node *second_last_entry;
public:linked_list_stack()
{
top=NULL;
bottom=NULL;
}
void push();
void pop();
void print_list();
void show_working();
};
void linked_list_stack::push()
{
int num;
cout<<"Enter the value to be pushed:"<<endl;
cin>>num;
entry=new node;
if(bottom==NULL)
{
entry ->data=num;
entry ->link=NULL;
bottom=entry;
top=entry;
}
else
{
entry->data=num;
entry->link=NULL;
top->link=entry;
top=entry;
}
cout<<"the"<<num<<"is pushed on to stack"<<endl;
cout<<"press any key to return to menu"<<endl;
getch();
}
void linked_list_stack::pop()
{
if(bottom==NULL)
cout<<"**** error *****:stack is empty"<<endl;
else
{
for(last_entry=bottom;last_entry->link!=NULL;last_entry=last_entry->link)
second_last_entry=last_entry;
if(top==bottom)
bottom=NULL;
int popped_element=top->data;
delete top;
top=second_last_entry;
top->link=NULL;
cout<<"the"<<popped_element<<"is popped from the stack";
cout<<endl;
}
cout<<"press any key to return to menu"<<endl;
getch();
}
void linked_list_stack::print_list()
{
print=bottom;
if(print!=NULL)
cout<<"values are pushed onto stack are"<<endl;
else
cout<<"******* Nothing to display ********";
cout<<endl;
while(print!=NULL)
{
cout<<"\t"<<print->data<<endl;
print=print->link;
cout<<"press any key to continue";
getch();
}

void linked_list_stack::show_working()
{
clrscr();
char key=NULL;
do
{
gotoxy(5,5);
cout<<"***** Implementation of linked list as a stack ****"<<endl;
gotoxy(10,8);
cout<<"Select one of the linked list operation"<<endl;
gotoxy(15,10);
cout<<"press P to push avalue\n";
gotoxy(15,12);
cout<<"press O to pop a value\n";
gotoxy(15,14);
cout<<"press S to print a value\n";
gotoxy(15,16);
cout<<"press E to exit\n";
input:
gotoxy(10,20);
cout<<"enter the choice"<<endl;
key=getch();
if(int(key)==27||key=='e'||key=='E')
break;
else if(key=='p'||key=='P')
push();
else if(key=='o'||key=='O')
pop();
else if(key=='s'||key=='S')
print_list();
else
goto input;
}
while(1);
}

void main()
{
linked_list_stack obj;
obj.show_working();
return(0);
};
}
Mar 22, 2016 at 10:07am
What is the question?
Mar 22, 2016 at 10:14am
getting an error....in function show_working() says identifier 'show_working' cannot have type qualifier
Mar 22, 2016 at 1:22pm
Tell you what, allow me to demonstrate to you why you should INDENT YOUR CODE PROPERLY.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include<iostream.h>
#include<conio.h>
class linked_list_stack
{
private:struct node
	{
	  int data;
	  node *link;
};
  node *top;
  node *entry;
  node *print;
  node *bottom;
  node *last_entry;
  node *second_last_entry;
public:linked_list_stack()
  {
    top=NULL;
    bottom=NULL;
  }
  void push();
  void pop();
  void print_list();
  void show_working();
};
void linked_list_stack::push()
{
  int num;
  cout<<"Enter the value to be pushed:"<<endl;
  cin>>num;
  entry=new node;
  if(bottom==NULL)
    {
      entry ->data=num;
      entry ->link=NULL;
      bottom=entry;
      top=entry;
    }
  else
    {
      entry->data=num;
      entry->link=NULL;
      top->link=entry;
      top=entry;
    }
  cout<<"the"<<num<<"is pushed on to stack"<<endl;
  cout<<"press any key to return to menu"<<endl;
  getch();
}
void linked_list_stack::pop()
{
  if(bottom==NULL)
    cout<<"**** error *****:stack is empty"<<endl;
  else
    {
      for(last_entry=bottom;last_entry->link!=NULL;last_entry=last_entry->link)
	second_last_entry=last_entry;
      if(top==bottom)
	bottom=NULL;
      int popped_element=top->data;
      delete top;
      top=second_last_entry;
      top->link=NULL;
      cout<<"the"<<popped_element<<"is popped from the stack";
      cout<<endl;
    }
  cout<<"press any key to return to menu"<<endl;
  getch();
}
void linked_list_stack::print_list()
{
  print=bottom;
  if(print!=NULL)
    cout<<"values are pushed onto stack are"<<endl;
  else
    cout<<"******* Nothing to display ********";
  cout<<endl;
  while(print!=NULL)
    {
      cout<<"\t"<<print->data<<endl;
      print=print->link;
      cout<<"press any key to continue";
      getch();
    }

  void linked_list_stack::show_working()
  {
    clrscr();
    char key=NULL;
    do
      {
	gotoxy(5,5);
	cout<<"***** Implementation of linked list as a stack ****"<<endl;
	gotoxy(10,8);
	cout<<"Select one of the linked list operation"<<endl;
	gotoxy(15,10);
	cout<<"press P to push avalue\n";
	gotoxy(15,12);
	cout<<"press O to pop a value\n";
	gotoxy(15,14);
	cout<<"press S to print a value\n";
	gotoxy(15,16);
	cout<<"press E to exit\n";
      input:
	gotoxy(10,20);
	cout<<"enter the choice"<<endl;
	key=getch();
	if(int(key)==27||key=='e'||key=='E')
	  break;
	else if(key=='p'||key=='P')
	  push();
	else if(key=='o'||key=='O')
	  pop();
	else if(key=='s'||key=='S')
	  print_list();
	else
	  goto input;
      }
    while(1);
  }

  void main()
  {
    linked_list_stack obj;
    obj.show_working();
    return(0);
  };
} 


See anything odd about the function show_working(), now that the indentation is done? See how all the other functions start at the far left? Is there anything funny about the end of the previous function?
Last edited on Mar 22, 2016 at 1:23pm
Topic archived. No new replies allowed.