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
Una pregunta cuales son los ataques de Sindel que por favor y me lo diga gracias
Len [333]
I do not know spanish please say in english
5 0
3 years ago
Write code that prints: userNum ... 2 1 Print a newline after each number. Ex: userNum
ehidna [41]

Answer:

The program to this question can be given as follows:

Program:

public class data //defining class data

{

//main method

public static void main (String [] as) //declaring main method  

{

int userNum = 4; //declare variable userNum and assign value

for (userNum = 1; userNum <= 4; userNum++)  //loop for print values

{

System.out.println(userNum);  //print values in new lines.

}

}

}

Output:

1

2

3

4

Explanation:

In the above java program code firstly a class "data" is defined, inside this class the main method is defined in which an integer variable userNum is defined that holds a value that is "4".

  • In this method, a for loop is declare that uses variable userNum which starts from 1 and ends with a given value that is equal to 4.
  • Inside a for loop, the print function is used that print userNum variable each values in the newline.  

4 0
3 years ago
Write a java program.
Sliva [168]

Answer:

The source code has been attached to this response. It contains comments explaining each line of the code. Kindly go through the comments.

To run this program, ensure that the file is saved as ArithmeticProcessor.java

Keep editing line 7 of the code to test for other inputs and arithmetic operation.

A sample output has also been attached to this response.

6 0
3 years ago
Nina, a programmer, wants to use the programming language Primavera. For which application area should Nina use this language?
AnnyKZ [126]

C. Drawings is the correct answer

8 0
3 years ago
Read 2 more answers
What are the steps for consolidating data from multiple worksheets? 1. Select the range of data on the first worksheet you wish
likoan [24]

Answer:

2. Go to the Data tab on the ribbon and select Data Tools.

3. Then, select and the dialog box will appear.

4. Choose the in the drop-down. Then, select the first group of data and press Enter.

1. Select the range of data on the first worksheet you wish to consolidate.

5. To add from more worksheets, select from the View tab.

Explanation:

Consolidation in Microsoft Excel is used to gather information from several worksheets. To consolidate data in a new worksheet, select the new worksheet and click on the upper left side where the data should be.

Click on Data > Consolidate, then a dialog box would appear. From the dialog box click on the function to consolidate with, then click on the reference area and select the first data range by clicking on the first worksheet and drag the data range to the box and click Add.

To add more data range, click on the reference area and do the same as the first data.

7 0
3 years ago
Read 2 more answers
Other questions:
  • Following a company on likedin is most similar to
    8·1 answer
  • Hybrid processors that can process 32 bits or 64 bits are known by what term?
    8·1 answer
  • Forensic computer investigators must _____.
    6·2 answers
  • The process of encoding messages or information in such a way that only authorized parties can read it is called ____________.
    7·1 answer
  • Claudia has a bachelors degree in computer information systems and she has learned to use some popular software testing tolls wh
    13·2 answers
  • Write a program that accepts a positive integer N as command-line argument, and outputs True if N is the square of some integer,
    13·1 answer
  • What are 3 examples of a idler gear in real life?
    7·1 answer
  • Create a method called letterGrade that will pass the student's average grade as a parameter and return a letter grade (char). O
    12·1 answer
  • Re:
    15·1 answer
  • Can someone pelaseee help
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!