Write a program with the following I/O
1.
Enter a sentence: Today is Wednesday
Sentence in reverse order is: yadsendeW si yadoT
Continue(y/n)? y
Enter a sentence: sit on a potato pan otis
Sentence in reverse order is: sito nap otatop a no tis
Continu(y/n)? n
Note: Make the size of the stack equal to 80. Use the STACK_PCK library
2.
Enter a group of positive integers with -1 at the end: 22 33 54 77 90
-1
The above numbers in reverse order are: 90 77 54 33 22
Note: Make the stack size equal to 20. Use the STACK_PCK library
MY PROGRAM IS :-------------------------------------------
CODE
#include <iostream>
using namespace std;
template <class T, char n>
class one
{ private: T a[4];
public: void Read()
{ for( char i=0; i<n; ++i)
{ cout<<"Enter data:"; cin>>a[i]; }
}
void Display()
{ for( char i=0; i<n; ++i)
cout<<a[i]<<"\t";
cout<<endl;
}
};
class stack
{ private: char a[5];
char counter;
public: void ClearStack() { counter=0; }
bool EmptyStack()
{ if( counter==0 )
return true;
else
return false;
}
bool FullStack()
{ if( counter == 5)
return true;
else
return false;
}
void Push( int x )
{ a[counter]= x;
counter++;
}
int Pop()
{ counter--;
return a[counter];
}
};
int main()
{
one<char, 5> p;
p.Read(); p.Display();
one<char, 4> q;
q.Read(); q.Display();
/*----------------output
Enter data:1
Enter data:2
Enter data:3
Enter data:4
Enter data:5
1 2 3 4 5
Enter data:a
Enter data:b
Enter data:c
Enter data:d
a b c d
Press any key to continue
---------------------------------*/
//example 2
stack s; char x;
s.ClearStack();
while( ! s.FullStack() )
{
cout<<"Enter a number:"; cin>>x;
s.Push(x);
}
// display stack s
while( ! s.EmptyStack() )
{
x=s.Pop();
cout<<x<<"\t";
}
cout<<endl;
return 0;
}
/*
Enter data:TODAY IS WEDNESDAY
Enter data:Enter data:Enter data:Enter data:T O D A Y
Enter data:Enter data:Enter data:Enter data:I S W E
Enter a number:Enter a number:Enter a number:Enter a number:Enter a number:Enter
a number:Enter a number:Enter a number:22
Enter a number:Enter a number:33
Enter a number:Enter a number:54
Enter a number:Enter a number:90
Enter a number:Enter a number:-1
Enter a number:Enter a number:-1
Enter a number:Enter a number:-1
- 1 - 1 - 0 9 4 5 3
3 2 2 Y a Ç a \ p
? ö ?
? ¦ ² @ ? ˜ +
¦ H ? Ç ?
B * Y ? Y A D
O T E W S I ¦ ¦ ? D
S E N D
Press any key to continue*/
EDIT : born2c0de : CODE Tags Added.