RECHERCHER :
COMMUNAUTE MP
Identifiez vous ...
Devenir Membre
J'ai oublié mon MDP
DOMAINE MP
Bavardages
Langages Généraux
Langages Web
Langages DotNet
Autres langages
Dev. Jeux Video
Sécurité
Sys. Exploitation
Graphismes
Logiciels
Réseaux
Bases de données
Méthodologies
Emplois High-tech
Aide juridique
Articles juridiques
FORUM
Index des forums
Ajouter un sujet
Rechercher sujet
Contact Responsable
Devenir modérateur
CHAT MP IRC
Votre pseudo ...
Serv: irc.irc-land.org
Chan: #MoteurProg
PARTICIPER
Plus de 3500 emplois.
Rechercher un job
Déposez votre CV
Emplois High-tech

Visiteur MP

 stack,queue,palindrome program help

Forum : IDE C++
Sous Catégorie : Aucune
Type du sujet : Sujet Normale
FAQ : FAQ IDE C++

SUIVI DES SUJETS PAR MAIL

SUIVI PAR MAIL INACTIF

RESOLUTION DU SUJET SUJET NON RESOLU
BLOQUAGE DU SUJET SUJET ACTIF
APPARTENANCE A LA FAQ N'APPARTIENT PAS A LA FAQ


PAGE : [1]

POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

FORUM IDE C++

PREMIERE PAGE

PAGE PRECEDENTE

Page précedente

Page suivante

PAGE SUIVANTE

DERNIERE PAGE
mysterio
Nouveau membre
Inscrit : 28/08/2005
Messages : 10
Message
#77218
Posté le 10/10/05 à 23:59
Question:
Write a program that read 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


Output:

Please enter a line of text
I am A.I


i AM a.i

This is a palindrome

---------------------------------------------------------
How do i change the capital letter to smaller letter??? wat is the function i must added in??
i using fstream with not same as my question..how do i change which i can type the own text by myself??

thanks 4 helping me...



my answers below:-


#include<iostream> #include <cstdlib> // For EXIT_FAILURE and EXIT_SUCCESS #include <fstream> #include<string> using namespace std; const int MAX=50; // initialize max string size of 50 characters typedef char StackElement; // define StackElement typedef char QueueElement; // define QueueElement class Stack { public: Stack(){top=-1;arr[MAX]=0;} // default stack constructor void push(StackElement & ch); // push function StackElement topNpop(); // top and pop functions combined bool empty() const; // empty function private: StackElement arr[MAX]; // define char array int top; // define int top }; /******************************************* FUNCTION: push() DESCRIPTION: Pushes an element onto the stack PRECONDITION: Waiting for function call POSTCONTION: New element character on top of stack *******************************************/ inline void Stack::push(StackElement & ch) { if(top<MAX) { top++; // increment top arr[top]=ch; // push onto stack } else { cout<<"Stack is full.\n"; // display stack is full } } /******************************************* FUNCTION: topNpop() DESCRIPTION: Reads and pops top element off the stack PRECONDIION: Waiting for function call POSTCONDITION: One element read and removed fromt he stack RETURN: Top element from stack ********************************************/ inline StackElement Stack::topNpop() { if(top>-1) { return(arr[top]); // returns top element top--; // remove froms stack } else { cout<<"Stack is empty.\n"; // display stack is empty return(0); } } /******************************************* FUNCTION: empty() DESCRIPTION: returns result value if stack is empty PRECONDITION: result=false POSTCONDITION: result may be true or remain false RETURN: result if true or false ********************************************/ inline bool Stack::empty() const { bool result=false; // initialize bool as false if (top==-1) { result=true; // if top is -1 return result true return(result); } else { return(result); // else return false } } class Queue // Queue class { public: Queue(){front=0, back=0;arr[MAX]=0;} // Queue default constructor void addq(QueueElement & ch); // define addq QueueElement frontNremoveq(); // define frontNremove private: QueueElement arr[MAX]; // initialize QueueElement array int front, back; // initialize int front and back }; /******************************************* FUNCTION: addq() DESCRIPTION: adds an element onto the queue PRECONDITION: Waiting for element to add POSTCONDITION: New element now on the queue ********************************************/ inline void Queue::addq(QueueElement &ch) { if(front!=(back+1)%MAX) { arr[back]=ch; // add element to back of queue back=(back+1)%MAX; } else { cerr<<"Error Queue is full\n"; // display queue is full } } /******************************************* FUNCTION: frontNremoveq() DESCRIPTION: reads and removes front element from queue PRECONDITION: front pointing to front of queue POSTCONDITION: front element is returned and then incremented ********************************************/ inline QueueElement Queue::frontNremoveq() { if(front!=back) { return(arr[front]); // return front element front++; // remove front element } else { cout<<"Queue is empty.\n"; // display queue is empty return(0); } } /***************************MAIN******************************/ int main() { Stack S; // initialize stack Queue Q; // initialize queue string s; int i=0; // initialze int 'i' char string[MAX]; // initialize char string bool RESULT=false; // initilize bool RESULT to false ifstream inside ("palindromeinput.txt"); if (! inside.is_open()) { cout << "Error opening file"; exit (1); } while (! inside.eof() ) { inside.getline (string,100); cout << string << endl; } while(string[i]!=NULL) { S.push(string[i]); // push chars individually from string to Q.addq(string[i]); // stack and queue i++; // next char } while(i>0) { if(S.topNpop()==Q.frontNremoveq()) // compare each element from { // stack and queue RESULT=true; // if same for all chars return true } else { RESULT=false; // if not same for any char break and return false break; } i--; } if(RESULT==true) { cout<<string<<" is a palindrome\n"; // display if true } else { cout<<string<<" is not a palindrome\n"; // display if false } ofstream outside ("palindromeoutput.txt"); if (outside.is_open()) { outside << string; outside<< string; outside.close(); } return 0; }

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

Publicité
Inscrit : X
Messages : X
Message
#Aucun

HAUT DE PAGE

  

vortex666
Modérateur :
- C & C++
- OpenGL
- Delphi
Chef de projet(s) :
- Vortez3DEngine

Avatar de vortex666
Inscrit : 20/09/2004
Messages : 482
Message
#78887
Posté le 31/10/05 à 01:55
What is a palindrome???

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 

lain82
Membre du club
Avatar de lain82
Inscrit : 25/04/2004
Messages : 1178
Message
#78895
Posté le 31/10/05 à 09:02
I think you can use the ASCII code of a letter to know if it's a uppercase letter to lowercase letter. With this, you can change the letter by decremeting or incrementing the ASCII Code.

Exemple :
If letter = 80 // P in uppercase letter
letter += 32 // 112 = p in lowcase letter


To resume, look a table of ASCII code and you will see a logical relation between lowcase and uppercase.

( Ps: Sorry for my bad english ... Smiley )
__________________________
A tous les membres, dite non à la (drogue...) sms-mania !

Avant de poster, vérifiez si la réponse n'est pas dans la FAQ ou un tutorial.

Je suis actuellement Image sur MSN

HAUT DE PAGE

PROFIL MEMBRE LUI ECRIRE 
POSTER UN NOUVEAU SUJET REPONDRE A CE SUJET

PREMIERE PAGE

PAGE PRECEDENTE Page précédente

Page suivante

PAGE SUIVANTE DERNIERE PAGE

FORUM IDE C++



    PAGE : [1]



.: Site Web développé par Julien Pichot et l'équipe MPWG avec www.evolvia-web.com :.