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

Define a function sentenceCapitalizer that has one parameter of type string. The

ID: 3812979 • Letter: D

Question

Define a function sentenceCapitalizer that has one parameter of type string. The function returns a copy of the string with the first character of each sentence capitalized. The function should return “Hello. My name is Joe. What is your name?” if the argument to the function is “hello. my name is Joe. what is your name?” Assume sentences are separated by a period followed by a space.

Using assertEqual, verify your function with at least 3 test cases.

You cannot use the string method, capitalize, or any built-in function or method that capitalizes a sentence. You are writing your own version of “capitalize” function.

Explanation / Answer

Note: The asker has not specified in which high-level language the question has to be answered. so I have used C++ to write the program. I have written the program using sentenceCapitalizer() function

Answer:

#include<iostream>
using namespace std;
void sentenceCapitalizer(char[]);
int main()
{
   char str[100];
   cout<<"Enter the text";
   cin.getline(str,100);
   cout<<"Befor, sentence ccapitalization the string is ";
   cout<<str;
   sentenceCapitalizer(str);
   cout<<endl<<"After, sentence capitalization the string is ";
   cout<<str;
   return 0;  
}
void sentenceCapitalizer(char str[])
{
   int i=0;
   str[i]=(int)str[i]-32;
   i++;
   while(str[i]!='')
   {
       if(str[i]=='.')
       {
           i++;
           str[++i]=(int)str[i]-32;
       }
       else
       {
       i++;
       }
   }
}

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