So here is my code:
and this is whats its supposed to put out, if we used the word goober for example:
[/font]
I give up. What did I do wrong? I know it involves functions, damn those arguments...[/font]
[font=verdana,arial,helvetica]code:[/font]
#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;
const int MAX_WORD_LENGTH = 20;
//Function Prototypes
void Description();
//Description of program
void InitWord(char w[],int len);
//Cells 0..len -1 are initialized to space character
void GetWord (char w[], int& len);
//User is prompted to enter a word with less than MAX_WORD_LENGTH
//letters. The user is then prompted to enter the word.
void ShowWord (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed on the screen.
// w and len are unchanged.
void ShowReversedWord (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed backwards on the screen.
//w and len are unchanged
bool WordsAreSame (char w1[], int len1, char w2[], int len2);
//Precondition: w1 is an array which contains a word of
//len1 letters stored in cells 0..len1-1.
// w2 is an array which contains a word of
//len2 letters stored in cells 0..len2-1.
//Postcondition: Returns true if the words are the same, false otherwise
//Case is ignored in that Hello and hello will be regarded as equal.
// w1, w2, len1, and len2 are unchanged.
//Uses <cctype>
bool IsPalindrome (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns true if the word is a palindrome, false otherwise
//Case is ignored in that AbcBa will be regarded as a palindrome.
// w, len are unchanged.
//Uses <cctype>
int NumberVowels (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns the number of letters that are in the set
//{A,a,E,e,I,i,O,o,U,u}
//w and len are unchanged.
void DisplayWordCharm (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: The word is displayed on the screen as an ancient
//word charm as described on the assignment.
//Uses <iomanip> and <cctype>
//The main program
int main()
{
char word1[MAX_WORD_LENGTH];
int word1Length;
char word2[MAX_WORD_LENGTH];
int word2Length = MAX_WORD_LENGTH;
Description();
cout << "First word:\n";
InitWord(word1,MAX_WORD_LENGTH);
GetWord(word1,word1Length);
cout << "\n\nSecond word\n";
InitWord(word2,MAX_WORD_LENGTH);
GetWord(word2,word2Length);
//Test GetWord and ShowWord
cout <<"Your first word(between the bars): ";
cout << '|';
ShowWord(word1,word1Length);
cout << '|'<< endl;
cout << "Your second word:";
cout << '|';
ShowWord(word2,word2Length);
cout << '|'<< endl;
//Test ShowReversedWord
cout << "Your first word spelled backwards is ";
ShowReversedWord(word1,word1Length);
cout << endl;
//Test WordsAreSame
if (WordsAreSame(word1,word1Length,word2,word2Length))
cout << "Your words were the same.\n";
else
cout << "Your words are different.\n";
//Test NumberVowels
cout << "The number of vowels in your second word is ";
cout << NumberVowels(word2,word2Length);
cout << ".\n";
//Test IsPalindrome
if (IsPalindrome(word1,word1Length))
cout << "Your first word is a palindrome.\n";
else
cout << "Your first word is not a palindrome.\n";
//Test WordCharm
cout << "Your second word displayed as a word charm:\n\n";
DisplayWordCharm(word2,word2Length);
return 0;
}
//Function Implementations
//Description of program
void Description()
{
cout << "Greetings to the fun with words program.\n";
cout << "You will be prompted to enter two words with ";
cout << MAX_WORD_LENGTH << " \nletters or less. The program";
cout << " will then test your \nfunction implementations.\n";
}
void InitWord(char w[],int len)
//Cells 0..len -1 are initialized to space character
{}
void GetWord (char w[], int& len)
//User is prompted to enter a word with less than MAX_WORD_LENGTH
//letters. The user is then prompted to enter the word.
{ cout << "Please enter the number of letters in your word.\n";
cout << "Make sure the number given doesn't exceed "
<< MAX_WORD_LENGTH << " characters in length: ";
cin >> len;
cout << "Now enter your word.\n";
for (int i=0; i<len; i++)
cin >> w;
}
void ShowWord (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed on the screen.
// w and len are unchanged.
{
for (int i = len; i<0; i++)
cout << w;
}
void ShowReversedWord (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed backwards on the screen.
//w and len are unchanged
{
for(int i = len-1; i>0; i--)
cout << w;
}
bool WordsAreSame (char w1[], int len1, char w2[], int len2)
//Precondition: w1 is an array which contains a word of
//len1 letters stored in cells 0..len1-1.
// w2 is an array which contains a word of
//len2 letters stored in cells 0..len2-1.
//Postcondition: Returns true if the words are the same, false otherwise
//Case is ignored in that Hello and hello will be regarded as equal.
// w1, w2, len1, and len2 are unchanged.
//Uses <cctype>
{
if((len1==len2)&&(w1==w2));
else
cout << "Words are different.\n";
}
bool IsPalindrome (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns true if the word is a palindrome, false otherwise
//Case is ignored in that AbcBa will be regarded as a palindrome.
// w, len are unchanged.
//Uses <cctype>
{int
if((c1==c5)&&(c2==c4))
return true
if (toupper(c1)=toupper(c5));
}
int NumberVowels (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns the number of letters that are in the set
//{A,a,E,e,I,i,O,o,U,u}
//w and len are unchanged.
{const int A = 1;
const int a = 1;
const int E = 1;
const int e = 1;
const int I = 1;
const int i = 1;
const int O = 1;
const int o = 1;
const int U = 1;
const int u = 1;
if(w==A,a,E,e,I,i,O,o,U,u);
int count=0;
for(int i=0; i<len; i++;
{{if(w%5==0)} return count};
else
cout << "No vowels.\n"
}
void DisplayWordCharm (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: The word is displayed on the screen as an ancient
//word charm as described on the assignment.
//Uses <iomanip> and <cctype>
{
int setw = 42;
}
[font=verdana, arial, helvetica]#include <iostream>
#include <cctype>
#include <iomanip>
using namespace std;
const int MAX_WORD_LENGTH = 20;
//Function Prototypes
void Description();
//Description of program
void InitWord(char w[],int len);
//Cells 0..len -1 are initialized to space character
void GetWord (char w[], int& len);
//User is prompted to enter a word with less than MAX_WORD_LENGTH
//letters. The user is then prompted to enter the word.
void ShowWord (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed on the screen.
// w and len are unchanged.
void ShowReversedWord (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed backwards on the screen.
//w and len are unchanged
bool WordsAreSame (char w1[], int len1, char w2[], int len2);
//Precondition: w1 is an array which contains a word of
//len1 letters stored in cells 0..len1-1.
// w2 is an array which contains a word of
//len2 letters stored in cells 0..len2-1.
//Postcondition: Returns true if the words are the same, false otherwise
//Case is ignored in that Hello and hello will be regarded as equal.
// w1, w2, len1, and len2 are unchanged.
//Uses <cctype>
bool IsPalindrome (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns true if the word is a palindrome, false otherwise
//Case is ignored in that AbcBa will be regarded as a palindrome.
// w, len are unchanged.
//Uses <cctype>
int NumberVowels (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns the number of letters that are in the set
//{A,a,E,e,I,i,O,o,U,u}
//w and len are unchanged.
void DisplayWordCharm (char w[], int len);
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: The word is displayed on the screen as an ancient
//word charm as described on the assignment.
//Uses <iomanip> and <cctype>
//The main program
int main()
{
char word1[MAX_WORD_LENGTH];
int word1Length;
char word2[MAX_WORD_LENGTH];
int word2Length = MAX_WORD_LENGTH;
Description();
cout << "First word:\n";
InitWord(word1,MAX_WORD_LENGTH);
GetWord(word1,word1Length);
cout << "\n\nSecond word\n";
InitWord(word2,MAX_WORD_LENGTH);
GetWord(word2,word2Length);
//Test GetWord and ShowWord
cout <<"Your first word(between the bars): ";
cout << '|';
ShowWord(word1,word1Length);
cout << '|'<< endl;
cout << "Your second word:";
cout << '|';
ShowWord(word2,word2Length);
cout << '|'<< endl;
//Test ShowReversedWord
cout << "Your first word spelled backwards is ";
ShowReversedWord(word1,word1Length);
cout << endl;
//Test WordsAreSame
if (WordsAreSame(word1,word1Length,word2,word2Length))
cout << "Your words were the same.\n";
else
cout << "Your words are different.\n";
//Test NumberVowels
cout << "The number of vowels in your second word is ";
cout << NumberVowels(word2,word2Length);
cout << ".\n";
//Test IsPalindrome
if (IsPalindrome(word1,word1Length))
cout << "Your first word is a palindrome.\n";
else
cout << "Your first word is not a palindrome.\n";
//Test WordCharm
cout << "Your second word displayed as a word charm:\n\n";
DisplayWordCharm(word2,word2Length);
return 0;
}
//Function Implementations
//Description of program
void Description()
{
cout << "Greetings to the fun with words program.\n";
cout << "You will be prompted to enter two words with ";
cout << MAX_WORD_LENGTH << " \nletters or less. The program";
cout << " will then test your \nfunction implementations.\n";
}
void InitWord(char w[],int len)
//Cells 0..len -1 are initialized to space character
{}
void GetWord (char w[], int& len)
//User is prompted to enter a word with less than MAX_WORD_LENGTH
//letters. The user is then prompted to enter the word.
{ cout << "Please enter the number of letters in your word.\n";
cout << "Make sure the number given doesn't exceed "
<< MAX_WORD_LENGTH << " characters in length: ";
cin >> len;
cout << "Now enter your word.\n";
for (int i=0; i<len; i++)
cin >> w;
}
void ShowWord (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed on the screen.
// w and len are unchanged.
{
for (int i = len; i<0; i++)
cout << w;
}
void ShowReversedWord (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: the word is displayed backwards on the screen.
//w and len are unchanged
{
for(int i = len-1; i>0; i--)
cout << w;
}
bool WordsAreSame (char w1[], int len1, char w2[], int len2)
//Precondition: w1 is an array which contains a word of
//len1 letters stored in cells 0..len1-1.
// w2 is an array which contains a word of
//len2 letters stored in cells 0..len2-1.
//Postcondition: Returns true if the words are the same, false otherwise
//Case is ignored in that Hello and hello will be regarded as equal.
// w1, w2, len1, and len2 are unchanged.
//Uses <cctype>
{
if((len1==len2)&&(w1==w2));
else
cout << "Words are different.\n";
}
bool IsPalindrome (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns true if the word is a palindrome, false otherwise
//Case is ignored in that AbcBa will be regarded as a palindrome.
// w, len are unchanged.
//Uses <cctype>
{int
if((c1==c5)&&(c2==c4))
return true
if (toupper(c1)=toupper(c5));
}
int NumberVowels (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: Returns the number of letters that are in the set
//{A,a,E,e,I,i,O,o,U,u}
//w and len are unchanged.
{const int A = 1;
const int a = 1;
const int E = 1;
const int e = 1;
const int I = 1;
const int i = 1;
const int O = 1;
const int o = 1;
const int U = 1;
const int u = 1;
if(w==A,a,E,e,I,i,O,o,U,u);
int count=0;
for(int i=0; i<len; i++;
{{if(w%5==0)} return count};
else
cout << "No vowels.\n"
}
void DisplayWordCharm (char w[], int len)
//Precondition: w is an array which contains a word of
//len letters stored in cells 0..len-1.
//Postcondition: The word is displayed on the screen as an ancient
//word charm as described on the assignment.
//Uses <iomanip> and <cctype>
{
int setw = 42;
}
and this is whats its supposed to put out, if we used the word goober for example:
[/font]
[font=verdana,arial,helvetica]code:[/font]
Greetings to the fun with words program.
You will be prompted to enter two words with 20
letters or less. The program will then test your
function implementations.
First word:
How many letters are in your word? 6
Enter your word:goober
Second word
How many letters are in your word? 6
Enter your word:goober
Your first word(between the bars): |goober|
Your second word:|goober|
Your first word spelled backwards is reboog
Your words were the same.
The number of vowels in your second word is 3.
Your first word is not a palindrome.
Your second word displayed as a word charm:
G
O O
O O O
B B B B
E E E E E
R R R R R R
[font=verdana, arial, helvetica]Greetings to the fun with words program.
You will be prompted to enter two words with 20
letters or less. The program will then test your
function implementations.
First word:
How many letters are in your word? 6
Enter your word:goober
Second word
How many letters are in your word? 6
Enter your word:goober
Your first word(between the bars): |goober|
Your second word:|goober|
Your first word spelled backwards is reboog
Your words were the same.
The number of vowels in your second word is 3.
Your first word is not a palindrome.
Your second word displayed as a word charm:
G
O O
O O O
B B B B
E E E E E
R R R R R R
I give up. What did I do wrong? I know it involves functions, damn those arguments...[/font]