| | |
Any Sample Program???
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi... there... I'm omick from the Philippines... Actually I'm a newbie here... I really dont know what you people are talking about... But anyways i'll be giving my idea of how to make a palindrome... I mean not really the whole thing... and i'm not that sure if this stuff thats on my mind will work out... ok here it is:
define your main function and include all those prompt thingy...:
like this one... i'm not so sure with this...
<< moderator edit: added code tags: [code][/code] >>
uhmmm.... i'm using a cafe... sorry i dont have much time left... maybe next time ok...
but wait...
arrays are very useful here...
this function should be included:
*function that will convert all your letters into small letters
e.g.
*function that will remove any punctuation marks including spaces
Tell me if you like my sample solution... I can really solve the problem... But I dont have enough time... If you like it... I can provide you the whole program... ok... e-mail me: << moderator edit: email snipped >>
define your main function and include all those prompt thingy...:
like this one... i'm not so sure with this...
C++ Syntax (Toggle Plain Text)
bool it_is_palindrome(string palindrome2) int main() { string palindrome; //prompt the user for a line of input e.g.: cout << "Enter now your word: "; getline(cin, palindrome); //now to test whether it is a palindrome you make a validation function... e.g. bool; if (it_is_palindrome(palindrome)) cout << "It is a palindrome!"; else cout << "Not a palindrome"; return 0; }
uhmmm.... i'm using a cafe... sorry i dont have much time left... maybe next time ok...
but wait...
arrays are very useful here...
this function should be included:
*function that will convert all your letters into small letters
e.g.
C++ Syntax (Toggle Plain Text)
for (int i=0; i<lengt_of_string; i++) letter[i]=(tolower(another_letter[i]);
Tell me if you like my sample solution... I can really solve the problem... But I dont have enough time... If you like it... I can provide you the whole program... ok... e-mail me: << moderator edit: email snipped >>
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
You could implement a stack, then pop each element off the top while at the same time pushing the element on to another stack. Then compare the results.
Naturally, there are much better ways to do what you want.
Naturally, there are much better ways to do what you want.
www.uncreativelabs.net
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
•
•
Join Date: Sep 2005
Posts: 16
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by omick16
Hi... there... I'm omick from the Philippines... Actually I'm a newbie here... I really dont know what you people are talking about... But anyways i'll be giving my idea of how to make a palindrome... I mean not really the whole thing... and i'm not that sure if this stuff thats on my mind will work out... ok here it is:
define your main function and include all those prompt thingy...:
like this one... i'm not so sure with this...
<< moderator edit: added code tags: [code][/code] >>C++ Syntax (Toggle Plain Text)
bool it_is_palindrome(string palindrome2) int main() { string palindrome; //prompt the user for a line of input e.g.: cout << "Enter now your word: "; getline(cin, palindrome); //now to test whether it is a palindrome you make a validation function... e.g. bool; if (it_is_palindrome(palindrome)) cout << "It is a palindrome!"; else cout << "Not a palindrome"; return 0; }
uhmmm.... i'm using a cafe... sorry i dont have much time left... maybe next time ok...
but wait...
arrays are very useful here...
this function should be included:
*function that will convert all your letters into small letters
e.g.
*function that will remove any punctuation marks including spacesC++ Syntax (Toggle Plain Text)
for (int i=0; i<lengt_of_string; i++) letter[i]=(tolower(another_letter[i]);
Tell me if you like my sample solution... I can really solve the problem... But I dont have enough time... If you like it... I can provide you the whole program... ok... e-mail me: << moderator edit: email snipped >>
i didnt know where to put the function...
i done with #include 'Stack.h', #include 'Queue.h' and Main.cpp
i show main program n add me the function (tolowercase,touppercase)
my main.cpp as below..
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cstdlib> // For EXIT_FAILURE and EXIT_SUCCESS #include <fstream> #include <string> #include <algorithm> #include <iomanip> #include <cctype> using namespace std; #include "Queue.h" #include "Stack.h" /***************************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 strcpy(string," "); cout << "Please enter a line of text: " << endl; cin.getline (string,100); for( int j = 0; j < s.size(); ++j) { if(s[j] >= 'A' && s[j] <= 'Z') s += (s[j] | 32); else if(s[j] >= 'a' && s[j] <= 'z') s += (s[j] & (~32)); else s += s[j]; } 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<<" \nThis is a palindrome\n"; // display if true } else { cout<<string<<" \nThis is not a palindrome\n"; // display if false } cout<<s<<s<<endl; return 0; }
hi hey... sorry for the late reply... i'm so busy processing my clearance to get home... kindly check for any mispelled things ok??? I have only type this stuff for you... so i cannot assure you that is free from errors... i havent tested this program... ok>>> but i know this would surely work!
heres the function that will convert any capital letters into small ones
<< moderator edit: added code tags:
heres the function that will convert any capital letters into small ones
C++ Syntax (Toggle Plain Text)
//your main_function here //dont forget to use getline(cin, your_string_here); //if (is_your_string_palindrome(your_string_here)); //cout << "Palindrome!"; //else //cout << "not!"; //and one thing... dont forget your header string ok? #include <string> :cheesy: //heres the function that will remove all punctuation marks string punctuation_erase (const string& your_string, const string& punctuation) { string no_punctuation; //this will create an empty string ok. int your_string_length = your_string.length(); int punctuation_length = punctuation.length(); for (int i =0; i < your_string_length; i++) { string report_char = your_string.substr(i, 1) //pick-up a one character int character_location = punctuation.find(report_char, 0); if (character_location < 0 || character_location >= punctuation_length) no_punctuation = no_punctuation + report_char // concatenates (+) strings that cannot be found in punctuation } return no_punctuation; } //the function that will determine whether the input line is a palindrome bool is_your_string_palindrome(cons string& your_string) { string punctuation ("?,:;'!\" "); // theres a space ok.. you can add other punctuations here. string string_here(your_string); string_here = make_lower_letters(string_here); string lowerstring_puncterase = punctuation_erase(string_here, punctuation); return (lowerstring_puncterase==reverse(lowerstring_puncterase); } string make_lower_letters (const string& your_string) { string new_string(your_string); for (int i=0; i < your_string.length(); i++) new_string[i] = tolower(your_string[i]); return new_string; } string reverse(const string& your_string) { int first = 0; int last = your_string.length(); string string_here(your_string); while (first < last) { last--; swap(string_here[first], string_here[last]; first++; } return string_here; } void swap_letters(char& letter1, char& letter2) { char letter_here = letter1; letter1 = letter2; letter2 = letter_here; }
[code][/code] >> So you bump a 2.5 year old thread and then expect to get some free homework?
You're not even in the right forum, this is C++ not VB.
[...]
Here's what you could try:
- Begin programming it yourself
- If you get stuck go to the right forum (VB) and look for the answer
- If the question was not answered in other thread, start a new thread and ask your question
- Don't use words like "Quick"
And to get you started, you might want to look here
Niek
You're not even in the right forum, this is C++ not VB.
[...]
Here's what you could try:
- Begin programming it yourself
- If you get stuck go to the right forum (VB) and look for the answer
- If the question was not answered in other thread, start a new thread and ask your question
- Don't use words like "Quick"
And to get you started, you might want to look here
Niek
Last edited by niek_e; Jan 30th, 2008 at 9:39 am.
![]() |
Similar Threads
- cpu scheduling program (Java)
- why this sample program doesen't work? (C++)
- A question on an error in a SpringLayout example program (Java)
- IMF message filter SDK sample problem (C)
- Program using a Menu Selection with Subprograms (C++)
Other Threads in the C++ Forum
- Previous Thread: Error:Null Pointer assignment
- Next Thread: The Calendar Program
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






