Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,401 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,122 people online right now. Registration is fast and FREE... Join Now!




i need some help please

 
Reply to this topicStart new topic

i need some help please, i'm trying to writea program but my results are not what i want

larry48
30 Sep, 2006 - 08:25 PM
Post #1

New D.I.C Head
*

Joined: 30 Sep, 2006
Posts: 2


My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Xing
RE: I Need Some Help Please
30 Sep, 2006 - 09:27 PM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Please use code tags.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:08AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month