Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on how to this program repeat until a empty line is entered as input

ID: 667891 • Letter: I

Question

I need help on how to this program repeat until a empty line is entered as input, at which time it will exit.

#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include <cstdio>
using namespace std;

// Defining methods
bool plaindrome(int fname, int lname, char input_str[]);
string reverse(string str);
char fname_char(char *str);
int string_length(string str);
string fname_half(string str);


// Main method
int main()
{
// variable declaration
int fname = 0;
int lname = 0;
char input_str[100];

// cout and cin for the input and output from user
cout << " Please enter your word: ";
cin >> input_str;

// unction that will reverse the input string
cout<<"The word "<< input_str <<" backwards is :"<<reverse(input_str);

// calculate the string length
lname = strlen(input_str);
  
// Determine if the word is plaindrome or not
if (plaindrome(fname, lname-1,input_str)== true)
cout << " This word is a palindrome ";
else
cout << " This word is not a palindrome.";

// output the string length
cout<<" The word is "<< string_length(input_str) <<" characters long.";

// Output the firt half of the string
cout<<" The fname half of the word is "<<fname_half(input_str);

// output the first letter of the string
cout<<" The fname letter is "<<fname_char(input_str)<<endl;

getchar();
//system("pause");
return 0;
}

// Function that determines if the string is plaindrome or not
bool plaindrome(int fname, int lname, char *input_str)
{
if (fname > lname)
return true;
if (input_str[fname]!= input_str[lname])
return false;
else if (input_str[fname] == input_str[lname])
{
return plaindrome((fname+1),(lname-1),input_str);
}
}

// function to reverse the string
string reverse(string str)
{
string temp = "";
int len = str.length();
for(int i = len -1; i >= 0; --i)
{
temp += str[i];
}
return temp;
}

// Function to get the length of the input string
int string_length(string str)
{
return str.length();
}

// Function to get the first half of the string
string fname_half(string str)
{
int len=str.length();
string strhalf = str.substr(0, len/2);
return strhalf;
}

// Function to get the first letter of the input string
char fname_char(char *str)
{
return str[0];
}

Explanation / Answer

#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include <cstdio>
using namespace std;
// Defining methods
bool plaindrome(int fname, int lname, char input_str[]);
string reverse(string str);
char fname_char(char *str);
int string_length(string str);
string fname_half(string str);

// Main method
int main()
{
// variable declaration
int fname = 0;
int lname = 0;
char input_str[100];
// cout and cin for the input and output from user
cout << " Please enter your word: ";
cin >> input_str;
// unction that will reverse the input string
cout<<"The word "<< input_str <<" backwards is :"<<reverse(input_str);
// calculate the string length
lname = strlen(input_str);
  
// Determine if the word is plaindrome or not
if (plaindrome(fname, lname-1,input_str)== true)
cout << " This word is a palindrome ";
else
cout << " This word is not a palindrome.";
// output the string length
cout<<" The word is "<< string_length(input_str) <<" characters long.";

// Output the firt half of the string
cout<<" The fname half of the word is "<<fname_half(input_str);

// output the first letter of the string
cout<<" The fname letter is "<<fname_char(input_str)<<endl;
getchar();
//system("pause");
return 0;
}
// Function that determines if the string is plaindrome or not
bool plaindrome(int fname, int lname, char *input_str)
{
if (fname > lname)
return true;
if (input_str[fname]!= input_str[lname])
return false;
else if (input_str[fname] == input_str[lname])
{
return plaindrome((fname+1),(lname-1),input_str);
}
}
// function to reverse the string
string reverse(string str)
{
string temp = "";
int len = str.length();
for(int i = len -1; i >= 0; --i)
{
temp += str[i];
}
return temp;
}
// Function to get the length of the input string
int string_length(string str)
{
return str.length();
}
// Function to get the first half of the string
string fname_half(string str)
{
int len=str.length();
string strhalf = str.substr(0, len/2);
return strhalf;
}
// Function to get the first letter of the input string
char fname_char(char *str)
{
return str[0];
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote