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
Goshia [24]
4 years ago
10

A user is asked to type a caption for a photo in a web form's text field. If the caption didn't end with a punctuation mark (. !

?), a period should automatically be added. A common error is to end with a comma, which should be replaced by a period. Another common error is to end with two periods, which should be changed to one period (however, ending with three periods (or more) indicates elipses so should be kept as is). The corrected caption is output. If the input is "I like pie", the output is "I like pie." If the input is "I like pie!", the output remains "I like pie!" If the input is "Coming soon…", the output remains "Coming soon…"

Computers and Technology
1 answer:
svp [43]4 years ago
4 0

Answer:

Here is the c++ program:

#include <iostream>  //to use input output functions

using namespace std;  //to identify objects cin cout

int main() {  //start of main function

string caption;  //stores the caption

int last_index;  //stores the index position of the last character of caption

char last_character;  //stores the last character of the caption

cout<<"Please type a caption: ";  //prompts user to enter a caption

getline(cin, caption);  //reads the complete line of caption from user

last_index = caption.size() - 1;  //sets the last_index to the last character of caption

last_character = caption.at(last_index);  //sets the last_character to the last character positioned by last_index

if ((last_character == '!') || (last_character == '?')) {}  /* checks if the last character of the caption is either ! or ? and if this statement evaluate to true then this does not require any action */

else if (last_character == ',') {  //checks if the last character of the caption is a comma

caption.at(last_index) = '.'; }  //if the else if condition is true then replace that comma with a period .

else if (last_character != '.') {  //checks if the caption does not end with ! ? , .

caption.push_back('.');}  //append period to the caption . if above if else condition is true

else if ((last_index > 0) && (last_character == '.') && (caption.at(last_index - 1) == '.')) {  //checks if the caption has two periods .

if ((last_index > 1) && (caption.at(last_index - 2) == '.')) {}  //checks if the caption has three periods and does nothing if this is true

else {  //if caption has two periods

caption.pop_back();}}  //removes one period if caption has two periods .

cout << caption << endl;}  //displays the caption

Explanation:

I will explain the above program with an example

Lets say user input the caption: I like pie

So

caption = " I like pie"

The first if condition if ((last_character == '!') || (last_character == '?')) evaluate to false because the last character of the caption is not an exclamation mark of a question mark. So the program moves to the next else if statement:

else if (last_character == ',') This statement is also false because the last character of the caption is not a comma. So the program moves to the next else if part.

else if (last_character != '.')

Now this statement evaluate to true because the last character of the caption is not a period . sign. So this part is executed. It has a statement:

caption.push_back('.');

Now this statement uses push_back() method which adds new character i.e. period '.' at the end of the caption string, increasing its length by one.

So the output of the program is:

I like pie.

If the caption = " I like pie!" then this if ((last_character == '!') || (last_character == '?')) condition executes and since it does nothing {} so the caption remains as it is and the output is:

I like pie!

If the caption = "Coming soon…" then this else if ((last_index > 0) && (last_character == '.') && (caption.at(last_index - 1) == '.')) condition executes which checks if the caption has two period. When this condition evaluates to true then the statement inside this else if condition executes which is: if ((last_index > 1) && (caption.at(last_index - 2) == '.')) and this checks if the caption has three periods. Yes the caption has three periods so it does nothing and the caption remains as it is and the output is:

Coming soon…

However if the caption is Coming soon.. with two periods then the else part inside else if ((last_index > 0) && (last_character == '.') && (caption.at(last_index - 1) == '.')) condition executes which is: caption.pop_back(); and this removes one period from the caption and the output is:

Coming soon.

The screenshot of the program and its output is attached.

You might be interested in
Select the correct answer.
juin [17]

Answer:

A. <Title> tag

Explanation:

Required

Tag that can be written in the <head> element

Of the given options, <title> is correct.

This is so because, it is compulsory to have the <title> tag and the only location where it can be placed is inside the <head> tag.

Its function is to display the title of a page

e.g.

<em><title> This is my first page </title></em>

4 0
3 years ago
Which of the following solutions should an administrator use to reduce the risk from an unknown vulnerability in a third-party s
ser-zykov [4K]

Answer:

A. Sandboxing

Explanation:

The best solution to apply for this task would be Sandboxing. This is a software management strategy that isolates applications from critical system resources and other programs. In doing so you effectively add a secondary security layer on top of the application in order to prevent any and all malware from entering and damaging your overall system. Thus effectively reducing the risk.

4 0
3 years ago
You have $5 and earn $1.75 for each roll of wrapping paper you sell. Write an equation in two variables that represents the tota
qaws [65]

Answer:

A = 5 + 1.75r

Explanation:

Amount you have = $5

Earning per roll of wrapping paper = $1.75

Let

r = number of rolls of wrapping paper

A = Total amount earned

A = 5 + 1.75r

Equation that represents the total amount A (in dollars) you have after selling r rolls of wrapping paper is

A = 5 + 1.75r

3 0
3 years ago
Discuss the potential problems using biometrics can present to society, and in particular, what effect the loss of biometric rec
tamaranim1 [39]

Answer:

Biometrics in this sense refers to any human information that can be used as unique identifiers such as fingerprints, iris scan, facial scan, voice patterns and typing cadence.

The advantage of biometrics is that they can not be duplicated. That is, two people can never share the same biometric information except if they are clones of each other.  

Given that this kind of unique identifiers can be also be stored as data, it thus creates a cyber risk. If stolen, it may be used to access any part of the user's life. The loss of biometric data to hackers is so detrimental that it can be used to falsify legal documents, identifications documents, or other forms of and even credit card details.

Cheers!

7 0
4 years ago
Write a function called st_dev. St_dev should have one #parameter, a filename. The file will contain one integer on #each line.
kodGreya [7K]

Answer:

  1. import statistics
  2. def st_dev(file_name):
  3.    with open(file_name) as file:
  4.        data = file.readlines()
  5.        numList = []
  6.        for x in data:
  7.            numList.append(int(x))
  8.        
  9.        return statistics.pstdev(numList)
  10. print(st_dev("text1.txt"))

Explanation:

The solution code is written using Python.

To ease the calculation task, we can import Python statistics module to use the pstdev method to calculate the population standard deviation of a list of numbers (Line 1).

Next, create a st_dev function that take single argument file_name (Line 3). In the function, it will open the input file and read the data line by line (Line 4-5). Create a for loop to traverse through each line of the data which is an integer and append it to numList (Line 7-8). We can pass the numList to pstdev method (Line 10) and return the resulting standard deviation value as output.

We test the function by passing a file which hold a list of integer values in each line (Line 12).

8

9

12

11

21

15

16

10

7

13

And the output we shall get is 4.019950248448356

6 0
4 years ago
Other questions:
  • What are some of the challenges that could arise from setting up a file management system on a computer?
    11·1 answer
  • Write a program that calculates the cost of a phone call. The user enters a positive integer that
    11·1 answer
  • An instance variable name of type String, initialized to the empty String. An instance variable score of type int, initialized t
    8·1 answer
  • Why is the most important factor for investors always the quality of the venture's leadership team
    12·1 answer
  • Your team will write a function that reverses a C-string, to practice using pointers. You must use pointers and C-strings for th
    6·1 answer
  • Which of the following is not considered a system component that can be found inside a computer? A-CPU B-RAM C-PCIe graphics ada
    6·1 answer
  • Which of the following would most likely be the target audience for a product
    7·2 answers
  • 10(            )  8(532.2 )                         
    15·1 answer
  • List of rules for expert systems​
    6·1 answer
  • Which of these words is used to begin a conditional statement?<br> when<br> input<br> if<br> until
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!