Question

In: Computer Science

Use the ListInterface operations only to create a tackPunct routine in C++ that will take a...

Use the ListInterface operations only to create a tackPunct routine in C++ that will take a list of string (array or linked, your choice) as a reference. Use the list operations on the passed list to make all items that don’t have a ‘.’, ‘?’ or ‘!’ have a ‘.’ tacked on.

Solutions

Expert Solution

Program

#include <iostream>
#include <list>
#include <iterator>
#include <string>
using namespace std;

//function tackPunct to make all items that don’t
//have a ‘.’, ‘?’ or ‘!’ have a ‘.’ tacked on
void tackPunct(list <string> &slist)
{
list <string> :: iterator it;
for(it = slist.begin(); it != slist.end(); ++it)
{
string s = *it;
int len = s.size();
if(s[len-1]!='.' && s[len-1]!='?' && s[len-1]!='!')
*it = *it + ".";
}
}

//main function
int main()
{
list <string> slist;
slist.push_back("Hello");
slist.push_back("World");
slist.push_back("Welcome!");

tackPunct(slist);

list <string> :: iterator it;

for(it = slist.begin(); it != slist.end(); ++it)
{
cout<<*it<<endl;
}
return 0;
}

Output:

Hello.
World.
Welcome!

Solving your question and helping you to well understand it is my focus. So if you face any difficulties regarding this please let me know through the comments. I will try my best to assist you. However if you are satisfied with the answer please don't forget to give your feedback. Your feedback is very precious to us, so don't give negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid plagiarism.
Thank you.


Related Solutions

Create a web calculator with JavaScript. Only four operations (Add, Sub, Multiplication, and Division) Use a...
Create a web calculator with JavaScript. Only four operations (Add, Sub, Multiplication, and Division) Use a CE button to cancel the operation.    Use the following website or any online resource as a reference. Don’t use their CSS or any other code.                 https://freshman.tech/calculator/ I am trying to learn please make comments then I will understand better.
Do only in C# (Not in C++ or C ) Minimum number of operations to convert...
Do only in C# (Not in C++ or C ) Minimum number of operations to convert array M to array N by adding an integer into a subarray Given two arrays M and N , the task is to find the minimum number of operations in which the array M can be converted into array N where each operation consists of adding an integer K into a subarray from L to R. M= {3, 7, 1, 4, 1, 2}, N...
In c++ Create a program regarding your wake up routine in the morning Alarm clock goes...
In c++ Create a program regarding your wake up routine in the morning Alarm clock goes off at 8:00AM You snooze for 5 mins (for loop I believe) You snooze again for 5 mins (Sub routines) 1. Brush teeth 2. Get dressed 3. Go to work In c++, Create a program regarding your wake up routine in the morning as seen below: Alarm clock goes off at 8:00AM You snooze for 5 mins (for loop I believe) You snooze again...
Your are to take the following c code and do the following on Eve: create a...
Your are to take the following c code and do the following on Eve: create a file with the code called quiz32.c create a second file with the code called quiz64.c Using gcc and stopping it after the Assembly phase, generate an optimization level 1, 32 bit ISA relocatable object file for quiz32.c Using gcc and stopping it after the Assembly phase, generate an optimization level 1, 64 bit ISA relocatable object file for quiz64.c obtain a list of the...
I'm supposed to create a c++ program which is supposed to take a sentence as an...
I'm supposed to create a c++ program which is supposed to take a sentence as an input and then output a sorted list of the occurrence of each letter. ex. Enter a phrase: It's a hard knock life A2 I2 K2 C1 D1 E1 F1 H1 L1 N1 O1 R1 S1 T1 I was also given a recommended code to use as a bubble sort procedure bubbleSort( A : list of sortable items ) n = length(A) repeat swapped =...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates...
***IN C# ONLY, USING WINDOWS FORMS*** --NO JAVA--. Create a GUI application in C# that calculates and displays the total travel expenses of a business person on a trip. Here is the information that the user must provide: • Number of days on the trip • Amount of airfare, if any • Amount of car rental fees, if any • Number of miles driven, if a private vehicle was used • Amount of parking fees, if any • Amount of...
Python we need to create a game using only the library graphic.py and use only Structure...
Python we need to create a game using only the library graphic.py and use only Structure Functions only.
We suggest the use of a spreadsheet to create the amortization tables. You take out a...
We suggest the use of a spreadsheet to create the amortization tables. You take out a 30-year mortgage for $70,000 at 9.65%, to be paid off monthly. Construct an amortization table showing how much you will pay in interest each year for the first 15 years and how much goes toward paying off the principal. If you sell your house after 15 years, how much will you still owe on the mortgage according to the amortization table? HINT [See Example...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
What are some recommendations for a workplace design (considering design for routine operations as well as...
What are some recommendations for a workplace design (considering design for routine operations as well as spills, leaks, and emergencies) specifically for machine operators? In this case, looking at machine operators who deal with machinery that processes from raw material to finished goods.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT