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
DaniilM [7]
3 years ago
9

Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes:

Computers and Technology
1 answer:
vodomira [7]3 years ago
6 0

Answer:

Here is the complete function:

void MakeSentenceExcited(char* sentenceText) {  // function that takes the text as parameter and replaces any period by an exclamation point in that text

int size = strlen(sentenceText);  //returns the length of sentenceText string and assigns it to size variable

char * ptr;  // character type pointer ptr

ptr = sentenceText;  // ptr points to the sentenceText string

for (int i=0; i<size; i++){  //iterates through the sentenceText string using i as an index

    if (sentenceText[i]=='.'){  // if the character at i-th index of sentenceText is a period

        sentenceText[i]='!'; } } } //places exclamation mark when it finds a period at i-th index of sentenceText

Explanation:

The program works as follows:

Suppose we have the string:

sentenceText = "Hello. I'm Miley. Nice to meet you."

The MakeSentenceExcited method takes this sentenceText as parameter

int size = strlen(sentenceText) this returns the length of sentenceText

The size of sentenceText is 35 as this string contains 35 characters

size =  35

Then a pointer ptr is declared which is set to point to sentenceText

for (int i=0; i<size; i++) loop works as follows:    

1st iteration:

i=0

i<size is true because i=0 and size = 35 so 0<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[0]=='.')

The first element of sentenceText is H

H is not a period sign so the statement inside if statement does not execute and value of i increments to 1. Now i = 1

2nd iteration:

i=1

i<size is true because i=1 and size = 35 so 1<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[1]=='.')

This is the second element of sentenceText i.e. e

e is not a period sign so the statement inside if statement does not execute and value of i increments to 1. Now i = 2

So at each iteration the if condition checks if the character at i-th index of string sentenceText is a period.

Now lets see a case where the element at i-th index is a period:

6th iteration:

i=5

i<size is true because i=5 and size = 35 so 5<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[5]=='.')

This is the character at 5th index of sentenceText i.e. "."

So the if condition evaluates to true and the statement inside if part executes:

sentenceText[i]='!'; statement becomes:

sentenceText[5]='!'; this means that the character at 5th position of sentenceText string is assigned an exclamation mark.

So from above 6 iterations the result is:

Hello!

This loop continues to execute until all the characters of sentenceText are checked and when the value of i gets greater than or equal to the length of sentenceText then the loop breaks.

The screenshot of the program along with its output is attached.

You might be interested in
To find out what a database contains simply look at the ________ inside the database.
SIZIF [17.4K]

Answer:

10) To find out what a database contains, one can look at the metadata inside the database. 11) Most organizations develop their own database management systems.

4 0
3 years ago
In your own words explain the following about the Domain Name System
borishaifa [10]

Answer:

Suppose you want to access brainly.com.  You type that into your favorite browser and hit enter.  Your computer does not know how to get to brainly.com.  This is the DNS comes in.  The DNS looks for brainly.com and maps it to an IP address (eg. 104.17.74.91).  Your computer can easily find 104.17.74.91 in order to connect you to questions and answers on a variety of topics.

8 0
3 years ago
To create a numbered list, you use the numbering button in the ____ group.
Jet001 [13]
To create a numbered list, use the button in the Paragraph group
5 0
3 years ago
A medium is a...........,,,,,,...
LenaWriter [7]
Sizing between small and large ;)
5 0
3 years ago
Read 2 more answers
A disadvantage with a subject directory is that users sometimes have difficulty deciding which categories to choose as they work
spin [16.1K]

The answer is True.  One disadvantage with the subject directory is that users sometimes have difficulty deciding which categories to choose as they work through the menus of links presented.  A subject Directory classifies web pages into categories, such as sports, shopping, etc.  One can locate a particular topic from general to the specific.  

4 0
3 years ago
Other questions:
  • What function does the domain name system (dns) perform?
    8·1 answer
  • A typical pda includes a(n) _____.
    6·2 answers
  • Which of the following is true about science and technology?
    5·1 answer
  • Which of the following is a recommended approach for data backup? Select one: a. Allow employees to take copies of vital data ho
    10·1 answer
  • Write code for a function that uses a loop to compute the sum of all integers from 1 to n. Do a time analysis, counting each bas
    11·1 answer
  • What is a scenario where records stored in a computer frequently need to be checked
    14·2 answers
  • Describe what each of the following functions in R do.1. t2. matplot3. c4. seq5. legend6. matrix7. rownames8. colnames9. type of
    14·1 answer
  • Think of all your favorite movies or games. Is their digital animation present? How do you think that it affected the movie or g
    13·2 answers
  • Discuss new concepts that you have learned about Cisco Devices and how they will be helpful in the workplace.
    11·1 answer
  • Which directory contains the initrd file? in suse linux
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!