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]
4 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]4 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
Por que es importante el audlamiento social en una pandemia por virus biológico
Mamont248 [21]

Answer:

Para ayudar a mantener a las personas informadas y actualizadas

(No hablo español usé el traductor de Google)

3 0
3 years ago
Complete the sentence. <br><br> The internet is an example of a ______
maria [59]

Answer:

packet switched network

4 0
3 years ago
Choose the correct term to finish the program. When done, the contents of info will be as shown.
RideAnS [48]

Answer:

The correct term is info.pop(7)

Explanation:

Given:

info = {3:10, 4:23, 7:10, 11:31}

Required

Which term removes 7:10 from the dictionary

To remove an item from a dictionary in Python, you follow the syntax below:

[dictionary-name].pop(key)

In this case:

The dictionary name is info and the key is 7

So, the term that implements the syntax is: <em>info.pop(7)</em>

After the instruction <em>info.pop(7)</em> is executed, the content of the dictionary becomes: {3: 10.4:23, 11:31}

4 0
3 years ago
what is the programming language JavaScript commonly used to create? A. Internet databases B. Smartphone applications C. Operati
Tcecarenko [31]

Answer:

D: Web Based Animations

Explanation:

4 0
2 years ago
A(n) _________ is a computer system which is part of a larger system which performs a dedicated function.
Helga [31]

Answer:

An Embedded System

Explanation:

In computing, an embedded system (computer) refers to a computer with its complete components (processors, memory, IO devices, and peripherals) with a unique and dedicated role in a bigger system (usually a mechanical or electrical system). Embedded systems are found in cars, airplanes, home appliances, petrol dispensers etc. The technology is behind the Internet of Things (IoTs).

8 0
3 years ago
Other questions:
  • Bar-code readers are typically used to track large numbers of inventory items, as in grocery store inventory and checkout, packa
    14·1 answer
  • What is the benefit to having the user interface integrated into the operating system? a) Power users prefer the added flexibili
    13·1 answer
  • Which of the following is a Federal law that provides a definition of the term cyberterrorism and under which young people prima
    7·1 answer
  • How do you feel about your self as a responsive citizen?​
    7·1 answer
  • In any *NIX system, after saving a script named "script_name," you need to make it executable so that you can run it. Which comm
    12·1 answer
  •  In which part of a professional email should you try to be brief, but highly descriptive? 
    10·1 answer
  • You have a small network at home that is connected to the internet. On your home network, you have a server with the IP address
    14·1 answer
  • Adam is writing a program that: 1) has the user guess a number, and 2) tells the user how many guesses it took to get the correc
    9·2 answers
  • A browser is a program that allow
    11·1 answer
  • What security setting can cause a mobile device to erase installed apps and data if the passcode is incorrectly entered a number
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!