I really really need help on my C programming homework I hav

I really really need help on my C++ programming homework.

I have no idea what to do and these are the instructions.

Any help will be greatly appreciated.

My code requires 3 separate files: palindromes.cpp, functions.cpp and functions.h.

Thanks in advance

You will write a program that uses a recursive function to determine whether a string is a character-unit palindrome. Moreover, the options for doing case sensitive camparisons and not ignoring spaces are indicated with flags. For example \"A nut for a jar of tuna\" is a palindrome if spaces are ignored and not otherwise. \"Step on no pets\" is a palindrome whether spaces are ignored or not, but is not a palindrome if it is case sensitive.

Background

Palindromes are character sequences that read the same forward or backword (e.g. the strings \"mom\" or \"123 454 321\"). Punctuation and spaces are frequently ignored so that phrases like \"Dog, as a devil deified, lived as a god.\" are palindromes. Conversely, even if spaces are not ignored phrases like \"Rats live on no evil star\" are still palindromes.

Requirements

Command Line Parameters

The program name will be followed by a list of strings. The program will determine whether each string is a palindrome and output the results. Punctuation will always be ignored. An optional flag can preceed a term that modifies how the palindrome is determined.

Strings

Each string will be separated by a space on the command line. If you want to include a string that has spaces in it (e.g. \"Rats live on no evil star\"), then put quotes around it. The quote characters will not be part of the string that is read in.

Flags

Optional for the user

If present, flags always appear after the program name and before any strings are processed and apply to all subsequent strings processed.

Must start with a minus (-) sign followed by one or two flag values that can be capital or lower case. e.g. -c, -S, -Cs, -Sc, etc.

There are no spaces between starting minus (-) sign and flag(s).

Flags values are case insensitive.

c or C: Indicates that comparisons should be case-sensitive for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore case-sensitivity. So, for example:

palindrome Mom should evalate as being a palindrome.

palindrome -c Mom should not evalate as being a palindrome.

s or S: Indicates that comparisons should not ignore spaces for all input strings. The default condition (i.e. if the flag is NOT included) is to ignore spaces. So, for example:

palindrome \"A nut for a jar of tuna\" should evalate as being a palindrome.

palindrome -s \"A nut for a jar of tuna\" shouldnot evalate as being a palindrome.

Options can appear in different flags, e.g. you can use -Sc or-S -c

The same flag cannot appear more than one time prior to a term. If it does, print a usage statement and exit program.

Code Expectations

Your program should only get user input from the command line. (i.e. \"cin\" should not be anywhere in your code).

Required Functions:Function that prints program usage message in case no input strings were found at command line.

Name: printUsageInfo

Parameter(s): a string representing the name of the executable from the command line.

Return: void.

Recursive function that determines whether a string is a character-unit palindrome.

Name: isPalindrome

Parameter(s): an input string, a boolean flag that considers case-sensitivity when true, and a boolean flag that does not ignore spaces when true.

Return: bool.

All functions should be placed in a separate file following the code organization conventions we covered.

Program Flow

Your program will take arguments from the command-line.

Determine if you have enough arguments. If not, output a usage message and exit program.

If flags are present.

Process and set values to use when processing a palindrome.

Loop through remaining arguments which are all input strings:

Process each by calling isPalindrome function with flag values.

Output results

Program Flow Notes:

Any time you encounter a syntax error, you should print a usage message and exit the program immediately.

Hints

Remember rules for a good recursive function.

Recommended Functions to write:
Note: You could combine these into a single function. e.g. \"preprocessString\"tolower - convert each letter to lowercase version for case insensitive comparisons.

Parameter(s): a string to be converted to lower case

Return: a string with all lower case characters

removePunctuation - Remove all punctuation marks possibly including spaces.

Parameter(s): a string and a boolean flag indicating whether to also remove spaces

Return: a string with punctuation/spaces removed

Existing functions that might help:

tolower

erase

substr

isalnum

Example Output

Note: you will probably only see the ./ if running on build.tamu.edu.

Solution

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

#define MAX 255

int palindrome(char *string, int x, int y)
{
if (x >= y)
return 0;
while (y > x)
if (tolower(string[x++]) != tolower(string[--y]))
return 0;
return 1;
}

int main()
{
char reading[MAX+1];
char readfile[MAX+1];
int x, y, i;
FILE *r;
puts(\"Enter read file name\");
scanf(\"%s\", readfile);
r=fopen(readfile, \"rt\");
if(r==NULL)
perror(\"File does not exist\");
else {
while (fgets (reading, MAX, r) != NULL) {
x = 0;
do {
while (reading[x] && !isalpha (reading[x]))
x++;
y = x;
while (isalpha (reading[y]))
y++;
if (palindrome (reading, x, y)) {
printf (\"Palindrome: \");
for (i=x; i<y; i++)
printf (\"%c\", reading[i]);
printf (\"\ \");
}
x = y;
}
while (reading[x]);
}
fclose(r);
}
return 0;
}


#include <stdio.h>
#include <string.h>

void check(char [], int);

int main()
{
char word[15];

printf(\"Enter a word to check if it is a palindrome\ \");
scanf(\"%s\", word);
check(word, 0);

return 0;
}

void check(char word[], int index)
{
int len = strlen(word) - (index + 1);
if (word[index] == word[len])
{
if (index + 1 == len || index == len)
{
printf(\"The entered word is a palindrome\ \");
return;
}
check(word, index + 1);
}
else
{
printf(\"The entered word is not a palindrome\ \");
}
}}


#include <string>
#include <algorithm>
#include <iostream>
int main()
{
std::string s;
std::cin >> s;
if( equal(s.begin(), s.begin() + s.size()/2, s.rbegin()) )
std::cout << \"is a palindrome.\ \";
else
std::cout << \"is NOT a palindrome.\ \";
}


bool IsPalindrome(const char* psz)
{
int i = 0;
int j;

if ((psz == NULL) || (psz[0] == \'\\0\'))
{
return false;
}

j = strlen(psz) - 1;
while (i < j)
{
if (psz[i] != psz[j])
{
return false;
}
i++;
j--;
}
return true;

}

bool IsPalindrome(const string& str)
{
if (str.empty())
return false;

int i = 0; // first characters
int j = str.length() - 1; // last character

while (i < j)
{
if (str[i] != str[j])
{
return false;
}
i++;
j--;
}
return true;
}

I really really need help on my C++ programming homework. I have no idea what to do and these are the instructions. Any help will be greatly appreciated. My cod
I really really need help on my C++ programming homework. I have no idea what to do and these are the instructions. Any help will be greatly appreciated. My cod
I really really need help on my C++ programming homework. I have no idea what to do and these are the instructions. Any help will be greatly appreciated. My cod
I really really need help on my C++ programming homework. I have no idea what to do and these are the instructions. Any help will be greatly appreciated. My cod
I really really need help on my C++ programming homework. I have no idea what to do and these are the instructions. Any help will be greatly appreciated. My cod

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site