Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with one space after every period. Another function twoSpaceAfterPeriod (String Parameter) that will return a string with two spaces after every period.
ONE SPACE METHOD
//method to provide one space after period symbol
string oneSpaceAfterPeriod(string s)
{
int i,j=0;
char s1[s.size()+1]; //allocate memory for a
character array according to size of s
for(i=0;i<s.length();i++)
{
if(s[i]=='.') //if period
symbol found
{
s1[j]='.';
//copy the period symbol to converted string
j++; //j
is used for the index of converted string
s1[j]=' ';
//assign a white space to the string
j++;
}
else
{ //copy all
charcters except period symbol
s1[j]=s[i];
j++;
}
}
s1[j]='\0'; //assign null to end
return s1; //return converted string
}
TWO SPACE METHOD
//method to provide two white spaces after period symbol
string twoSpaceAfterPeriod(string s)
{
int i,j=0;
char s1[s.size()+1];
for(i=0;i<s.length();i++)
{
if(s[i]=='.')//if period
symbol found
{
s1[j]='.';
//copy the period symbol to converted string
j++;//j is
used for the index of converted string
s1[j]=' ';
//assign a white space after period symbol
j++;
s1[j]='
';//assign second white space
j++;
}
else//copy all
charcters except period symbol
{
s1[j]=s[i];
j++;
}
}
s1[j]='\0'; //assign null to end
return s1; //return converted string
}
PROGRAM IMPLEMENTATIONS
#include<iostream>
using namespace std;
//method to provide one space after period symbol
string oneSpaceAfterPeriod(string s)
{
int i,j=0;
char s1[s.size()+1]; //allocate memory for a
character array according to size of s
for(i=0;i<s.length();i++)
{
if(s[i]=='.') //if period
symbol found
{
s1[j]='.';
//copy the period symbol to converted string
j++; //j
is used for the index of converted string
s1[j]=' ';
//assign a white space to the string
j++;
}
else
{ //copy all
charcters except period symbol
s1[j]=s[i];
j++;
}
}
s1[j]='\0'; //assign null to end
return s1; //return converted string
}
//method to provide two white spaces after period symbol
string twoSpaceAfterPeriod(string s)
{
int i,j=0;
char s1[s.size()+1];
for(i=0;i<s.length();i++)
{
if(s[i]=='.')//if period
symbol found
{
s1[j]='.';
//copy the period symbol to converted string
j++;//j is
used for the index of converted string
s1[j]=' ';
//assign a white space after period symbol
j++;
s1[j]='
';//assign second white space
j++;
}
else//copy all
charcters except period symbol
{
s1[j]=s[i];
j++;
}
}
s1[j]='\0'; //assign null to end
return s1; //return converted string
}
//driver program
int main()
{
string s,s1,s2;
cout<<endl<<"Enter a string";
getline(cin,s);//read the string
//display the string
cout<<endl<<"Entered String is :
"<<s;
s1=oneSpaceAfterPeriod(s); //call method to
provide one space
//display the converted
string
cout<<endl<<"Converted String with one
space after period is : "<<s1;
s2=twoSpaceAfterPeriod(s);//call method to provide two
spaces
//display the converted string
cout<<endl<<"Converted String with two
spaces after period is : "<<s2;
}
OUTPUT
Write a function oneSpaceAfterPeriod( String Parameter ) that will return a string with one space after...
Write a Python function make_triangle(trianglechar, triangleheight) that will return a string with an isosceles right triangle based on the two formal parameters triangle_height giving the triangle height and triangle_char that gives the symbol to be printed. Important notes: This program returns (not prints!) a string. For this function and the other part of this lab you are required to put in a docstring. That will be checked by a TA/grader reading the program. Every one of the occurrences of triangle_char...
#Write a function called check_formula. The check_formula #function should take as input one parameter, a string. It #should return True if the string holds a correctly #formatted arithmetic integer formula according to the rules #below, or False if it does not. # #For this problem, here are the rules that define a #correctly-formatted arithmetic string: # # - The only characters in the string should be digits or the five arithmetic operators: +, -, *, /, and =. Any other...
4. Write a C function int str2int(char *s) that takes string s as parameter and return the integer that s represents. For example, if string s is 123", then the function return integer 123.
Write a static method called printWithSpaces that takes a String as its parameter and prints the characters of the string separated by spaces. For example: > Methods.printWithSpaces("method") m e t h o d You should have a single space after the last character. This method should not return a value. That is similar to this code for printing the string vertically public static void printVertical(String s) { for (int i = 0; i < s.length(); i++) { char c =...
In the function below, return the string 'negative' if the numeric parameter number is in fact negative, or, return the string 'positive' if the parameter number is positive, otherwise return string 'zero' use function "def string_indicating_positivityOrNegativity(number):" python 3
(7) Implement the shorten_space() function. shorten_space() has a string parameter and updates the string by replacing all sequences of 2 or more spaces with a single space. shorten_space() returns the string. Call shorten_space() in the print_menu() function, and then output the edited string. Hint: Look up and use Python function .isspace(). Ex: Edited text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space....
Write a recursive function, take a String as input, return true, if the String is a palindrome; false otherwise. For instance, if the input is: “A nut for a jar of tuna” Then the return value is true. Notice that the non English letters are ignored; the spaces are ignored; and it is NOT case sensitive. You must write recursive function. You shall turn in a complete program, including main function to use your function to test if a String...
In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...
help ASAP 3. Write a string C++ function named UnsignedPartialSum() that takes two string parameters and an int parameter. If both string parameters represent binary numbers and the int parameter is equal to a positive number less than or equal to the length of the longest string parameter, the function should return a binary string whose length is equal to two times the length of the maximum length of the two string parameters whose value is equal to the sum...
CODIO python problem Write a function isRed() that accepts a string parameter and looks for the presence of the word ‘red’ in the string. If it is found, return boolean True otherwise False. Finally output the result of calling the function with the value in text.