Question

In: Computer Science

Can someone explain to me the program step by step next to each statement in the...

Can someone explain to me the program step by step next to each statement in the program by using comment \\ and do the program using the basic c++ cuz down program looked messy advance?

a. Request a five-letter string value from the console.

b. If the input string is not a five-letter word, print that the word is not a five-letter word.

c. If the input string is a five-letter word,determine if the word is or is not a Palindrome. Hint: String indexes can be used to compare letter values.

d. If the word is a Palindrome, print that it is a Palindrome.

Output Example (input is bold and italicized)

Enter a five-letter word: test

test is not a five-letter word.

Output Example (input is bold and italicized)

Enter a five-letter word: kayak

kayak is a palindrome.

#include<bits/stdc++.h>
using namespace std;
int main()
{

char string1[10000], string2[10000];

int i, j, length = 0, flag = 0;


cout << "Enter a Five-letter word: ";
cin>>string1;


length = strlen(string1)-1;


if((length+1) == 5)
{
for (i = length, j = 0; i >= 0 ; i--, j++)
string2[j] = string1[i];


if (strcmp(string1, string2))
flag = 1;
if (flag == 1)
cout << string1 << " is not a palindrome.";
else
cout << string1 << " is a palindrome.";
}
else
{
cout< }
return 0;
}

Solutions

Expert Solution

(Ans)

#include <iostream>
#include <cstring>//library for using strlen() 
using namespace std;

int main(){
    char word[30];
    int i, length;
    int flag = 0;
    
    cout << "Enter a Five-letter word: "; 
    cin >> word;
    
    length = strlen(word);//This gives us the length of the word given by the user
    
    if(length==5)//If length of the given word is 5 then execute the steps in the if condition
    {
        for(i=0;i < length ;i++)
        {
            if(word[i] != word[length-i-1])//This step compares the word characters from start and end i.e if word is "Hello" then it compares first letter 'H' with last letter 'o'
            //If they are same then it moves to the next set of words i.e 'e' and compares it with 'l' and so on. If any word mismatches then it breaks the loop and sets flag=1
            {
                flag = 1;
                break;
            }
        }
        
        if (flag)// If flag==1 that means that the characters of the input word from front and back doesn't match. So the given word is not a palindrome. 
            {
                cout << word << " is not a palindrome" << endl; 
            }    
        else //If the characters match then the word is a palindrome.
            {
                cout << word << " is a palindrome" << endl; 
            }
    }
    
    else//if the length of the word is not 5 then printing the given word is not a 5 letter word.
        {
            cout<< word <<" is not a five-letter word."; 
        }
    return 0;
}

Related Solutions

Hello can someone please explain the is lm curves step by step for me?
Hello can someone please explain the is lm curves step by step for me?
Hello can someone please explain the AS AD curve step by step to me? Thank you
Hello can someone please explain the AS AD curve step by step to me? Thank you
can someone explain to me circular, double, linked list? can someone show a program on how...
can someone explain to me circular, double, linked list? can someone show a program on how you would go about using recursive with proper functions and one not using recursive but somethibg simikar! bibary search tree, preorder, post order? good explanation of linked list sorted.
Can someone show me step by step how to determine the lattice constants of Graphite?
Can someone show me step by step how to determine the lattice constants of Graphite?
Can someone please walk through this program for me and explain out the outputs are generated....
Can someone please walk through this program for me and explain out the outputs are generated. #include <iostream> #include <iomanip> using namespace std; const int size = 5; int fun(int arz[size], int jump) { int i, j = 0; for(i = 0; i < size; i += jump) j += arz[i]; return j; } main() { int arx[size] = {1, 2, 4, 8, 16}; int ary[size] = {10, 20, 40, 80, 160}; cout << fun(arx, 1) << endl; cout <<...
Can someone please explain the following program to me? I have ran it, but do not...
Can someone please explain the following program to me? I have ran it, but do not understand how the answers are being derived. #include<iostream> using namespace std; int num1 = 1; int quiz(int num) { static int n1 = 10; int n2 = 20; n1--; n2++; num1++; if (num == 1) return num1; else if (num < 3) return n1; else return n2; } // quiz main() { cout << quiz(num1) << endl; cout << quiz(num1) << endl; cout <<...
Can someone please explain step-by-step if possible? Miller Company’s contribution format income statement for the most...
Can someone please explain step-by-step if possible? Miller Company’s contribution format income statement for the most recent month is shown below: Total Per Unit Sales (37,000 units) $ 222,000 $ 6.00 Variable expenses 111,000 3.00 Contribution margin 111,000 $ 3.00 Fixed expenses 44,000 Net operating income $ 67,000 Required: (Consider each case independently): 1. What is the revised net operating income if unit sales increase by 20%? 2. What is the revised net operating income if the selling price decreases...
Can Someone Explain Me Classes In Javascript With Examples?
Can Someone Explain Me Classes In Javascript With Examples?
Can someone show me the steps of how to solve this? A program needs to access...
Can someone show me the steps of how to solve this? A program needs to access the following pages: 1, 2, 3, 4, 2, 1, 3, 2, 1, 4, 2, 3 There are 3 initially empty frames, how many page faults will there be respectively, if we use First-in-First-out, and Farthest-in-Future page replacement algorithms? A) 7 and 7 B) 7 and 6 --  Correct Answer   C) 6 and 6 D) 6 and 5
Can someone explain how to get the answers step by step? I'm really confused by this...
Can someone explain how to get the answers step by step? I'm really confused by this stats question and I really need it "dummied down." A researcher has gathered information from a random sample of 178 households. For each of the following variables, construct confidence intervals to estimate the population mean. Use the 90% level. A. An average of 2.3 people resides in each household. Standard devisfikn is 0.35 B. There was an average of 2.1 television sets (s= 0.10)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT