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
Viktor [21]
3 years ago
15

Reverse Word Order: Write a program that reverses the order of the words in a given sentence. This program requires reversing th

e order of the words wherein the first and last words are swapped, followed by swapping the second word with the second to last word, followed by swapping the third word and the third to last words, and so on. Your program will ask the user for an input string and print out the resultant string where the order of the words is reversed. Please see the hints section for more details on an example algorithm. Assume a maximum C-string size of 1000 characters. Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. Do Not Use Predefined Functions from the cstring Library. Please properly comment your code before submission.For this part of the assignment, name your source file as Reverse Word Order_WSUID.cpp. For example, if your user ID is A999B999 name your file as Reverse Word Order_A999B999.cpp. Sample Test Cases: Test Case 1: Input: London bridge has been abducted Output: abducted been has bridge London Test Case 2: Input: Hello World Output: World Hello Test Case 3: Input: Hello World, how are you? Output: you? Are how World, HelloTest Case 4: Input: I like toast Output: toast like l
Computers and Technology
1 answer:
Lerok [7]3 years ago
8 0

Answer:

The program in C++ is as follows:

#include <bits/stdc++.h>

using namespace std;

int main(){

string sentence,word="";

getline (cin, sentence);

vector<string> for_reverse;

for (int i = 0; i < sentence.length(); i++){

 if (sentence[i] == ' ')  {

  for_reverse.push_back(word);

  word = "";  }

 else{    word += sentence[i];}  }

for_reverse.push_back(word);

sentence="";

for (int i = for_reverse.size() - 1; i > 0; i--){

 sentence+=for_reverse[i]+" ";}

sentence+=for_reverse[0];

cout<<sentence<<endl;

return 0;

}

Explanation:

This declares sentence and word as strings; word is then initialized to an empty string

string sentence,word="";

This gets input for sentence

getline (cin, sentence);

This creates a string vector to reverse the input sentence

vector<string> for_reverse;

This iterates through the sentence

for (int i = 0; i < sentence.length(); i++){

This pushes each word of the sentence to the vector when space is encountered

<em>  if (sentence[i] == ' ')  { </em>

<em>   for_reverse.push_back(word);</em>

Initialize word to empty string

  word = "";  }

If the encountered character is not a blank space, the character is added to the current word

<em>  else{    word += sentence[i];}  } </em>

This pushes the last word to the vector

for_reverse.push_back(word);  

This initializes sentence to an empty string

sentence="";

This iterates through the vector

for (int i = for_reverse.size() - 1; i > 0; i--){

This generates the reversed sentence

 sentence+=for_reverse[i]+" ";}

This adds the first word to the end of the sentence

sentence+=for_reverse[0];

Print the sentence

cout<<sentence<<endl;

You might be interested in
If you are planning to carry a large balance on your credit card, which of the following credit card features should you look fo
Setler [38]

If you are planning to carry a large balance on your credit card, then you should choose Low APR. Why does it so? Because APR, acronym from Annual Percentage rate will give you guidance on how much the interest you have to pay as an additional charge from your loan.

<h3>Further explanation</h3>

Interested to know more about this answer, let's take a look at our Brainly explanation below.

First, what is APR, APR is the acronym from Annual Percentage Rates. It's an entity from the credit that comes from your credit card. The formula of APR is listed below.

(\frac{\frac{Fees+interest fees}{total loan}}{days of loan}\times 365 ) \times 100 = APR

<h3>Example in Calculation:</h3>

To give a clear view and explanation of what is APR, please take a look at data below. For example, Bob bought a new Macbook pro, that cost him 2500 USD in June 2017. He bought it by his credit card and he need to pay monthly the bill of credit card within 10 months. In middle of 2018, when he finished paid all the bill of his Macbook pro, he realize he paid 150 dollar of the interest. So the calculation of APR from his credit card is.

1. The cost of the product that you pay

             The interest of the payment is 150 dollar.

2. Sum the number and divide by the loan amount

             The percentage 150 dollar divided by 2500 dollar. It gives 0.06

3. Divide them by the day terms of the loan

             The term of the loan is 10 months or 300 days. So It gives 0.06 / 300 = 0.0002

4. Multiply the result to 365 days

              Follow it with 0.002 x 365 = 0.073

5. Multiply by 100 to get the amount in percentage

              It gives 7.3

So the APR is 7.3 %

Below is also some of the reasons why you should not pick the other choice or feature.

<h3>Why the other choices are not relevant:</h3>

B-Low balance transfer fee

Usually, people not using cash in regards to credit card usage. Why does it so, because credit card will give you extra charge to withdraw some money. It also applies to transfer fee, most of the bank provides a free transfer from one account to another account. Therefore low balance transfer is not aligned as the choice to pick a credit card.

C-Lots of credit card rewards

Credit card rewards are a gamification way of the credit card issuer and do you know that in the world only 10% of customers that are using it. It applies to the reward in another service, such as miles award and so on.

D-A large credit limit

The credit limit is entirely the right of the credit card issuer in deciding on how much the credit card should be issued. You can not just pick up the large credit limit without any approval from the institution that approves your credit limit.

Learn more

If you are interested more into this topic, we recommend you too also take a look at the following question.

  • annual percentage rates by monthly: brainly.com/question/8970458
  • annual percentage rate on mortgage : brainly.com/question/1398763
  • how do annual percentage rates: work:brainly.com/question/1361627

<h3>Core curriculum category</h3>

Grade: 12

Subject: Economy

Subchapter: Loan

5 0
4 years ago
Read 2 more answers
How do i know my child's login info for parent infinite campus
Oliga [24]

Answer:

Logging in from a Web Browser

Visit infinitecampus.com and click Login at the top right.

Search for your District Name and State. Select your district from the list.

Click Parent/Student.

Click either Campus Parent or Campus Student.

Enter the Username and Password provided by your school. ...

Click Log In!

Explanation:

5 0
3 years ago
My friend Leo wants to have an emergency plan for his final exams on University of Southern Algorithmville. He has N subjects to
leonid [27]

Answer:

Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. Greedy algorithms are used for optimization problems. An optimization problem can be solved using Greedy if the problem has the following property: At every step, we can make a choice that looks best at the moment, and we get the optimal solution of the complete problem.

If a Greedy Algorithm can solve a problem, then it generally becomes the best method to solve that problem as the Greedy algorithms are in general more efficient than other techniques like Dynamic Programming. But Greedy algorithms cannot always be applied. For example, the Fractional Knapsack problem (See this) can be solved using Greedy, but 0-1 Knapsack cannot be solved using Greedy.

The following are some standard algorithms that are Greedy algorithms.

1) Kruskal’s Minimum Spanning Tree (MST): In Kruskal’s algorithm, we create an MST by picking edges one by one. The Greedy Choice is to pick the smallest weight edge that doesn’t cause a cycle in the MST constructed so far.

2) Prim’s Minimum Spanning Tree: In Prim’s algorithm also, we create an MST by picking edges one by one. We maintain two sets: a set of the vertices already included in MST and the set of the vertices not yet included. The Greedy Choice is to pick the smallest weight edge that connects the two sets.

3) Dijkstra’s Shortest Path: Dijkstra’s algorithm is very similar to Prim’s algorithm. The shortest-path tree is built up, edge by edge. We maintain two sets: a set of the vertices already included in the tree and the set of the vertices not yet included. The Greedy Choice is to pick the edge that connects the two sets and is on the smallest weight path from source to the set that contains not yet included vertices.

4) Huffman Coding: Huffman Coding is a loss-less compression technique. It assigns variable-length bit codes to different characters. The Greedy Choice is to assign the least bit length code to the most frequent character. The greedy algorithms are sometimes also used to get an approximation for Hard optimization problems. For example, the Traveling Salesman Problem is an NP-Hard problem. A Greedy choice for this problem is to pick the nearest unvisited city from the current city at every step. These solutions don’t always produce the best optimal solution but can be used to get an approximately optimal solution.

6 0
3 years ago
Press the enter key in all of the following circumstances except _____.
fiasKO [112]
B. When the insertion point reaches the right margin 
6 0
3 years ago
Which of the following are advantages of<br> assessments? Check all that apply.
garri49 [273]
Can you add a picture of the options
7 0
3 years ago
Other questions:
  • Need answers for 11&amp;12. Due today. Thanks.
    14·1 answer
  • Why should you stay out of the open space to the right of a semi-tractor-trailer?
    7·2 answers
  • Which hardware device should he consider upgrading in order to increase the system's storage space?
    6·1 answer
  • Write and test the definition of a haskell function 'largest', which finds the largest element of a list, but is implemented usi
    15·1 answer
  • When Tim Berners-Lee developed the first specifications, protocols, and tools for the World Wide Web in 1993, his employers at C
    12·1 answer
  • How do you use VMware Fusion to make a Tip Calculator?
    10·1 answer
  • HELP
    11·1 answer
  • The InfoBar is located below the ribbon and on top of a message. It is used for which purposes? Check all that apply. showing th
    9·2 answers
  • Describing the One-to-Many Relationship
    13·2 answers
  • why are microphones or digital cameras unlikely to cause the damage that is found in repetitive strain injury?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!