1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
elena-s [515]
3 years ago
14

Write a method that accepts a String object as an argument and returns a copy of the string with the first character of each sen

tence capitalized. For instance, if the argument is "hello. my name is Joe. what is your name?" the method should return the string "Hello. My name is Joe. What is your name?" Demonstrate the method in a program that asks the user to input a string and then passes it to the method. The modified string should be displayed on the screen.
Computers and Technology
1 answer:
emmainna [20.7K]3 years ago
7 0

Answer:

The programming language is not stated; However, the program written in C++ is as follows: (See Attachment)

#include<iostream>

using namespace std;

string capt(string result)

{

result[0] = toupper(result[0]);

for(int i =0;i<result.length();i++){

 if(result[i]=='.' || result[i]=='?' ||result[i]=='!')  {

 if(result[i+1]==' ') {

  result[i+2] = toupper(result[i+2]);

 }

 if(result[i+2]==' ')  {

  result[i+3] = toupper(result[i+3]);

 }

 } }

return result;

}

int main(){

string sentence;

getline(cin,sentence);

cout<<capt(sentence);

return 0;

}

Explanation:

<em>The method to capitalize first letters of string starts here</em>

string capt(string result){

<em>This line capitalizes the first letter of the sentence</em>

result[0] = toupper(result[0]);

<em>This iteration iterates through each letter of the input sentence</em>

for(int i =0;i<result.length();i++){

This checks if the current character is a period (.), a question mark (?) or an exclamation mark (!)

if(result[i]=='.' || result[i]=='?' ||result[i]=='!')  {

 if(result[i+1]==' '){  ->This condition checks if the sentence is single spaced

  result[i+2] = toupper(result[i+2]);

-> If both conditions are satisfied, a sentence is detected and the first letter is capitalized

 }

 if(result[i+2]==' '){ ->This condition checks if the sentence is double spaced

  result[i+3] = toupper(result[i+3]);

-> If both conditions are satisfied, a sentence is detected and the first letter is capitalized

 }

}

}  <em>The iteration ends here</em>

return result;  ->The new string is returned here.

}

The main method starts here

int main(){

This declares a string variable named sentence

string sentence;

This gets the user input

getline(cin,sentence);

This passes the input string to the method defined above

cout<<capt(sentence);

return 0;

}

Download cpp
You might be interested in
Write the sql command to show which tutor needs to be reminded to turn in reports.
NemiM [27]
SELECT TO_CHAR (Tutor Report.Month, 'MONTH') MONTH, Tutor Report.MatchID, Match History.MatchID, MatchHistory.Tutor.ID FROM Tutor Report, MatchID WHERE <span>Tutor Report.MatchID=Match History.MatchID AND NOT (TutorReport.Month=‘JULY’);</span>
4 0
2 years ago
What is not true of efs
Lemur [1.5K]

Answer:

EFS cannot store files encrypted.

Explanation:

EFS) is a feature introduced in version 3.0 of NTFS that provides filesystem-level encryption. EFS is useful for mobile computer users, whose computer are subject to physical theft, and for storing highly sensitive data. Encryption itself is the method where the information is converted into secret code that hides the information's true meaning. (EFS) is used to encrypt files and folders. EFS is easy to use, with nothing more than a check box in a file’s properties. It is not fully supported on Windows 7 Starter, Windows 7 Home Basic, and Windows 7 Home Premium!

3 0
3 years ago
The faster alcohol is consumed, the faster it reaches the __________.
Anni [7]
The faster it reaches the bloodstream

6 0
3 years ago
Read 2 more answers
Which was cited as a reason why Google became so popular?
kupik [55]

Answer:

Google became successful because its founders were well-connected. Google was the world's first and best search engine. Google changed the world by solving an old problem in a new way. Google's other products are now more important to its success than search.

Explanation:

3 0
2 years ago
John wants to know the amount of ram memory installed on his computer. in which category of the windows 7 control panel can this
Verizon [17]

John can find the amount of Random Access Memory (RAM) memory installed on his computer with the Windows 7 under the category “<u>System and Security</u>” in the Control Panel.

To know the total amount of installed RAM through Control Panel in the computer with Windows 7, John should follow the steps as:

  • Click the Windows key
  • Type Control Panel
  • Click the category named “System and Security”
  • Now under “System”, click “View amount of RAM and processor speed”
  • “Device Specifications” section displays the amount of installed RAM in John’s computer

Thus, above are the steps by which John’s can find the amount of installed RAM in his Windows 7 computer’s Control Panel.

What is Random Access Memory (RAM)?

RAM is the temporary memory in computers that stores the data currently being used by the processor.

You can learn more about Control Panel at

brainly.com/question/1445737

#SPJ4

5 0
1 year ago
Other questions:
  • How to select the entire table in microsoft excel
    11·1 answer
  • Which option best describes the cheapest way to file your federal income taxes?
    5·1 answer
  • In order for Dr. Reynolds to send a CPOE from her office computer system to the computer system at the local hospital, a/an ____
    5·1 answer
  • Seth is considering advertising his business using paid search results.What do you think makes paid search advertising so effect
    11·2 answers
  • ________type of website is an interactive website kept constantly updated and relevant to the needs of its customers using a dat
    5·1 answer
  • Please help Ill give you brainliest if I get 2 answers. Which is used to input information on a laptop?
    6·1 answer
  • Which statements about editing an existing Contact in Outlook are true? Check all that apply.
    9·2 answers
  • Why do people make Among Us games on Ro-blox, and thousands of people play them, when Among Us is free on all devises?
    10·1 answer
  • Please respond not with answer but with comment.
    12·1 answer
  • NAT addresses concerns over the dwindling IPv4 address space by ___________________. 1 point allowing networks to use fewer IP a
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!