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
Trying to make the baseplate red and turn off can collide then the game waits 5 seconds and turns on can collide, making the bas
kenny6666 [7]

Answer:

Explanation:

yes

but dont forget to call makeBasePlateGreen

maybe you would call it at the end of the program?

by the way you have a typo at the end

make the O lowercase

myBlasePlate.BrickColor = BrickColor.Green()

and then add this to the end

makeBasePlateGreen()

so you call the function and actually use it.

4 0
2 years ago
What would be the best course of action for the scenario below? A user has a large amount of data that she or he needs to store.
horrorfan [7]
Bluetooth connection data on nonvolatile storage media such as a USB
7 0
3 years ago
In which career does the level of education vary the most?
Ksenya-84 [330]
Journalism
all the best
3 0
3 years ago
Read 2 more answers
Set the Append Only property to _____ to allow users to add data to a Long Text field but not to change or remove existing data.
diamong [38]

A computer data storage is made of many features. Set the Append Only property to YES to allow users to add data to a Long Text field but not to change or remove existing data.

  • Append-only is known to be a characteristic or component of computer data storage. It is where new data can be appended to the storage, but where existing data is said to be immutable.

A field's data type is very essential property as it shows what kind of data the field can store.

Learn more from

brainly.com/question/24795103

7 0
2 years ago
Cuales son las intenciones de la tecnología para el desarrollo social y calidad de vida
Nuetrik [128]

Answer:

jgiofhkjufihojsfguisjkdghsufijk

Explanation:

eafijbuiaoehfkjhadufyhbjadnifujkhmadjnigjkmhadfngkjadhmfj

7 0
2 years ago
Other questions:
  • Suppose a worker needs to process 100 items. the time to process each item is exponentially distributed with a mean of 2 minutes
    5·1 answer
  • Select the most likely outcome of making only on-time minimum payments to a credit card with a balance for an entire year?
    7·2 answers
  • Which logic gate produces an output of 1 only if both it’s inputs are 0?
    5·1 answer
  • A router is a device that addresses a packet on a network to the next router along the line. Under which layer of the OSI model
    5·1 answer
  • Semiconductors are only somewhat conductive electronic components.<br><br> True or False?
    14·1 answer
  • How do you freeze the total cell so that it doesn't change when copied?
    6·1 answer
  • Convert the following hexadecimal numbers to decimal: (a) FF (b) F0A2 (c) 0F100 (d) 100
    10·1 answer
  • What are the differences between tkinter toolkit and PyQt?
    14·1 answer
  • Describe s computer network that you are familiar with ?
    8·1 answer
  • In the context of machine learning, an artificial neural network (ann) is most likely used for?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!