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
Online education students need to be taught
weeeeeb [17]

Online education is a teaching practice delivered through the internet. The students learning from online platforms must be taught to be ethical.

<h3>What is the importance of ethics and integrity?</h3>

In the online education system, the students should learn to be ethical and integral as it enables the students and their teachers to be creative, free to create ideas, and acknowledge others' work.

Ethics teaches the students to develop their personalities and behavior. Students' integrity allows them to be honest, responsible, and fair towards their work and instructor.

Therefore, option A. online learning students must be taught to be ethical.

Learn more about online learning here:

brainly.com/question/14708323

#SPJ1

7 0
2 years ago
Write a function analyze_text that receives a string as input. Your function should count the number of alphabetic characters (a
laiz [17]

Answer:

def analyze_text(sentence):

   count = 0

   e_count = 0

   for s in sentence:

       s = s.lower()

       if s.isalpha():

           count += 1

       if s == "e":

           e_count += 1

   return "The text contains " + str(count) + " alphabetic characters, of which " + str(e_count) + " (" + str(e_count*100/count) + "%) are ‘e’."

Explanation:

Create a function called analyze_text takes a string, sentence

Initialize the count and e_count variables as 0

Create a for loop that iterates through the sentence

Inside the loop, convert all letters to lowercase using lower() function. Check each character. If a character is a letter, increment the count by 1. If a character is "e", increment the e_count by 1.

Return the count and e_count in required format

5 0
3 years ago
Which of the following statements is true of subroutines? Check all that apply.
erica [24]
I believe it’s the first answer

“They can be used in multiple places “

But I’m not sure!!
6 0
3 years ago
Read 2 more answers
   In the Start menu of Windows 7, you see your name listed as an option. Where does this shortcut lead if you select it?
ss7ja [257]
I do believe the answer is c. I used to own a computer with a windows 7 program.

5 0
3 years ago
What is required when opening a checking account?
Brums [2.3K]
A, because if not, there is nothing to say it exsists
8 0
3 years ago
Read 2 more answers
Other questions:
  • Marcus just created a new folder specifically for his buisness records so he would like to move last months business transaction
    13·2 answers
  • Which one of the following statements most fully describes the general capabilities of desktop publishing software?
    12·1 answer
  • Current versions of windows support file names up to ________ characters long
    5·1 answer
  • You asked your colleague to provide feedback on a blog post you recently wrote. When they sent you their feedback, they made edi
    10·1 answer
  • 4. In this problem, we consider sending real-time voice from Host A to Host B over a packet-switchednetwork (VoIP). Host A conve
    14·1 answer
  • Given two variables matric_age and grad_age, write a statement that makes the associated value of grad_age 4 more than that of m
    15·1 answer
  • Which of the following recently developed technologies has NOT greatly increased the speed of information dissemination?
    13·2 answers
  • Given that Apache and Internet Information Services (IIS) are the two most popular web application servers for Linux and Microso
    10·1 answer
  • 1. Answer the following questions: a. What are the different types of number system? Name them.​
    8·1 answer
  • Explain logic circuit​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!