Write a C++ program That reads a line of text, changes each uppercase letter to
ID: 3661489 • Letter: W
Question
Write a C++ program
That reads a line of text, changes each uppercase letter to lowercase,
and places each letter both in a queue and onto a stack. The program should then verify
whether the line of text is a palindrome (a set of letters or numbers that is the same
whether read forward or backward).
I need original code and not something copied exactly off the Internet
Not a copy of the code from any of these sites or elsewhere online.
https://www.daniweb.com/programming/software-development/threads/33685/help-on-stack-queue-palindrome-program-
https://www.assignmentexpert.com/free-answers/programming/c_/question-40838
http://www.justanswer.com/computer-programming/3ivwf-hello-logicpro-programming-stacks.html
Just looking for unique code that can't be found online at a bunch of sites already
Thanks much
Jason
Explanation / Answer
main program
#include <iostream>
#include <cstdlib>
#include <cctype>
#include "Stack.h"
#include <string>
#include "Queue.h"
#include <algorithm>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
string str;
int j=0;
char strng[MAX] ;
bool OUTPUT=false ;
Queue V;
Stack T;
strcpy( strng," " );
cout << " Please type a line of sentence :" << endl ;
cin.getline ( strng,100 );
for( int i = 0; i < str.size(); ++i )
{
if( str[i] >= 'A' && str[i] <= 'Z' )
str += ( str[i] | 32);
else
if( str[i] >= 'a' && str[i] <= 'z')
str += (str[i] & (~32));
else
str += str[i];
}
while( strng[j]!= NULL )
{
V.addq( strng[j] ) ;
T.push( strng[j] ) ;
j++ ;
}
while( j > 0 )
{
if( T.topNpop() == V.frontNremoveq())
{
OUTPUT = true ;
}
else
{
OUTPUT = false ;
break ;
}
j-- ;
}
if( OUTPUT == true )
{
cout<<strng<<" A palindrome " ;
}
else
{
cout<<strng<<" Not a palindrome " ;
}
cout <<str<<str<<endl ;
return 0 ;
}
queue program
#define _Queue_h
#ifndef _Queue_h
typedef char QueueClassElement;
const int MAX=100;
class QueueClass
{
public:
QueueClass(){qFront = 0, qBack = 0;qArray[MAX] = 0 ; }
void queueAdd(QueueClassElement & letter);
QueueClassElement removeQueue();
private:
QueueClassElement qArray[MAX];
int qFront , qBack ;
} ;
inline QueueClassElement QueueClass::removeQueue()
{
if(qFront != qBack)
{
return(qArray[qFront]);
qFront++;
}
else
{
cout<<" QueueClass is empty. ";
return(0);
}
}
inline void QueueClass::queueAdd(QueueClassElement &letter)
{
if(qFront != (qBack +1 ) % MAX )
{
qArray[qBack] = letter;
qBack = ( qBack +1 ) %MAX;
}
else
{
cerr<<"Error QueueClass is full ";
}
}
#endif
stack program:
#define _Stack_h
#ifndef _Stack_h
typedef char StackClassElement;
const int MAX = 100;
class StackClass
{
public:
StackClass(){ stop =-1; sArray[MAX] = 0; }
void push( StackClassElement & letter );
StackClassElement removeTop();
bool empty() const;
private:
StackClassElement sArray[MAX] ;
int stop;
};
inline void Stack::push( StackClassElement & letter )
{
if( stop < MAX )
{
stop++ ;
sArray[stop] = letter ;
}
else
{
cout<<" StackClass is full. ";
}
}
inline bool StackClass::empty() const
{
bool result = false;
if ( stop == -1 )
{
result = true ;
return( result ) ;
}
else
{
return( result );
}
}
inline StackClassElement StackClass::removeTop()
{
if( stop > -1 )
{
return( sArray[stop] );
stop-- ;
}
else
{
cout<<" StackClass is empty. " ;
return (0) ;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.