Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 18, Problem 3P
Program Plan Intro
Reverse String
Program Plan:
- Include required header file.
- Include required “std” namespace.
- Define main function
- Initializes the variable “str1” in “string” type.
- Declare the variable “stackValue” in “stack” template class of “char” type.
- Declare variable “t” in “string” type.
- Reverse the give string using “for” loop.
- Push the given string in last order to given stack.
- Then display the value in given stack.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a function that accepts a string parameter. The function must use a listcomprehension to build a list of characters. An example of calling the function and printing the value returned by the function would be:
print(your_func("this.is,a-test."))
['.', ',', '-', '.']
DO NOT USE: Dictionaries, Object-Oriented programming, and Python shortcuts!!!
Given a ListItem class, complete main() using the built-in list type to create a linked list called shoppingList. The program should read items from input (ending with -1), adding each item to shoppingList, and output each item in shoppingList using the PrintNodeData() function.
Ex. If the input is:
milkbreadeggswafflescereal-1
the output is:
milkbreadeggswafflescereal
#include "ListItem.h"#include <string>#include <list>#include <iostream>
using namespace std;
int main (int argc, char* argv[]) { // TODO: Declare a list called shoppingList of type ListItem
string item;
// TODO: Read inputs (items) and add them to the shoppingList list // Read inputs until a -1 is input
// TODO: Print the shoppingList list using the PrintNodeData() function
return 0;}
#ifndef LISTITEMH#define LISTITEMH
#include <string>
using namespace std;
class ListItem { public: ListItem();
ListItem(string itemInit);
// Print this node void…
Write a function that takes a string of words as an input, uses a stack to reverse the words and returns the reversed stringFor instance, if the user were to input “stacks are fun”, the function wouldreturn “fun are stacks”. Make sure you call the function to test it
Chapter 18 Solutions
Problem Solving with C++ (10th Edition)
Ch. 18.1 - If v is a vector, what does v.begin() return? What...Ch. 18.1 - If p is an iterator for a vector object v, what is...Ch. 18.1 - Suppose v is a vector of ints. Write a for loop...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose the vector v contains the letters 'A',...Ch. 18.1 - Suppose you want to run the following code, where...Ch. 18.2 - Prob. 7STECh. 18.2 - Prob. 8STECh. 18.2 - Prob. 9STECh. 18.2 - Prob. 10STE
Ch. 18.2 - Prob. 11STECh. 18.2 - Prob. 12STECh. 18.2 - Prob. 13STECh. 18.2 - Prob. 14STECh. 18.2 - Prob. 15STECh. 18.2 - Prob. 16STECh. 18.3 - Prob. 17STECh. 18.3 - Prob. 18STECh. 18.3 - Prob. 19STECh. 18.3 - Suppose v is an object of the class vectorint. Use...Ch. 18.3 - Prob. 21STECh. 18.3 - Can you use the copy template function with vector...Ch. 18.3 - Prob. 23STECh. 18 - Prob. 1PCh. 18 - Prob. 2PCh. 18 - Prob. 3PCh. 18 - Prob. 4PCh. 18 - Write a program that allows the user to enter any...Ch. 18 - Prob. 3PPCh. 18 - Prob. 5PPCh. 18 - Solution to Programming Project 18.6 In this...Ch. 18 - Prob. 7PPCh. 18 - You have collected a file of movie ratings where...Ch. 18 - Prob. 9PPCh. 18 - Prob. 11PPCh. 18 - Write a program that uses regular expressions to...
Knowledge Booster
Similar questions
- Assume that L is a list of Boolean values, True and False. Write a program in python with a function longestFalse(L) which returns a tuple (start, end) representing the start and end indices of the longest run of False values in L. If there is a tie, then return the first such run. For example, if L is False False True False False False False True True False False 0 1 2 3 4 5 6 7 8 9 10 then the function would return (3, 6), since the longest run of False is from 3 to 6.arrow_forwardJava Program A proper divisor of a positive integer, n, is a positive integer less than n whichd dividesevenly into n. Write a function that computes all of the proper divisors of ap positiveinteger. The integer will be passed to the function as its only parameter. Thef functionwill return a list containing all of the proper divisors as its only result.Complete this exercise by writing a main program that demonstrates the function byr readinga value from the user and displaying the list of its proper divisors. Ensuret thatyour main program only runs when your solution has not been imported into anotherf filearrow_forwardWrite a function findMaxTuple() that gets a list of tuples as a parameter, finds and returns the tuple with maximum sum inside the list. Write Python statements that create a sample list that has tuples inside (you can use the list of tuples in the sample run below), then use findMaxTuple() function to get the tuple with maximum sum and print it.arrow_forward
- For the code shown in the screenshot below, draw a picture of the program stack when the function findSlope() is called the first time. You only have to draw the part of the stack for findZero() and findSlope().arrow_forwardWrite a Java program that goes through Collection of Linked List elements of String data type and removes all the elements with string length of greater than five. Java Code +arrow_forwardUsing C++, A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Ex: If the input is: 3 Joe 123-5432 Linda 983-4123 Frank 867-5309 Frank the output is: 867-5309 A. Create a struct in your program called ContactInfo to store a name and a phone number. B. Define and call the following function. The return value of GetPhoneNumber is the phone number associated with the provided contact name. If the name is not found, the function should return "not found". string GetPhoneNumber(ContactInfo contacts[], int size, string contactName) C. Your main function should declare an array of ContactInfo structs of size…arrow_forward
- Write a class method called reverseString that accepts a String str as a parameter and then reverses the characters in the String by using a stack.arrow_forwardWrite a function that takes a list of tuples as its only argument, where each tuple contains three integers, and returns a list of those tuples where the sum of the integers are 0. For example, tupleSum([(1,2,3),(-4,2,2),(4,5,-8),(1,0,-1),(0,0,1)]) returns: [(-4,2,2),(1,0,-1)]arrow_forwardWrite a python function MedianWithoutHL(ScoreList) that takes an unsorted list of n numbers as a parameter, discards the highest and the lowest numbers and return the median. You can assume the number of items in the list is between 0.0 and 9.9. To find the median from a list of items, you have to sort the list and find out the value of the item in the middle.Note: If the list has an odd number of items, the median is the value of the middle item. If the list has an even number of items, the median is the average of the two middle items.Sample Run #1:scoreList1 = [9.0, 9.0, 7.5, 8.0, 9.5, 6.5, 5.0, 7.0, 7.5, 8.5]print("The Original ScoreList: ", scoreList1)print(MedianWithoutHL(scoreList1))Output of Sample Run #1:The Original ScoreList: [9.0, 9.0, 7.5, 8.0, 9.5, 6.5, 5.0, 7.0, 7.5, 8.5]The List after sorting: [5.0, 6.5, 7.0, 7.5, 7.5, 8.0, 8.5, 9.0, 9.0, 9.5]Without the High & Low: [6.5, 7.0, 7.5, 7.5, 8.0, 8.5, 9.0, 9.0]7.75arrow_forward
- In c++ please. Thank you! A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use linear search. Modify the algorithm to output the count of how many comparisons were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Joe 123-5432 Linda 983-4123 Frank 867-5309 Frank the output is:…arrow_forwardWrite a subroutine that takes a simple sentence in noun-verb-object form and parses the sentence into its different parts. For example, the sentence “Mary walked the dog” is parsed into this:Noun: MaryVerb: walkedObject: the dogThis function should work with both String objects and StringBuilder objects.arrow_forwardWrite a function that takes a list of tuples as its only argument, where eachtuple contains three integers, and returns a list of those tuples where the sum of the integers are 0. For example,tupleSum([(1,2,3),(-4,2,2),(4,5,-8),(1,0,-1),(0,0,1)]) returns:[(-4,2,2),(1,0,-1)]arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education