Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
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
In C++
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…
Chapter 18 Solutions
Problem Solving with C++ (9th 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. 9PP
Knowledge Booster
Similar questions
- Java 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 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 itarrow_forwardAssume 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_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_forwardDesign a C++ program which reads any number of integers in a linked list until "-1" is entered. Then your program must display all numbers between the smallest and largest numbers in this list. Enter your list: 14 33 28 7 16 22 38 10 39 40 36 -1 Result: 7->16->22->38->10->39->40 Enter your list: 30 34 4 29 27 19 2 21 23 33 3 4 7 21 24 14 5-1 Result: 34->4->29->27->19->2->21->23->33->3arrow_forwardThe function swap_list_ends in python takes one parameter, L, which is a list. The function then swaps the first and last items in L and returns the object None. Notice that since L is mutable, the changes the function makes to L are visible back in the calling program. SPECIAL CASE: If the list 'L' is empty, then the function does nothing to L and returns None. For example: Test Result L = [1, 3, 9, 2] if not(swap_list_ends(L) is None): print("Error: function should return None") print(L) [2, 3, 9, 1] L = ['super', 'awesome', 'excellent'] if not(swap_list_ends(L) is None): print("Error: function should return None") print(L) ['excellent', 'awesome', 'super'] L = [True, False] if not(swap_list_ends(L) is None): print("Error: function should return None") print(L) [False, True]arrow_forward
- Write 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_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_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
- 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 binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName 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 Frank 867-5309 Joe 123-5432 Linda…arrow_forwardWrite a C++ program that creates and prints a linked list of classes. Base this program on what you know so far about using structures and linked lists, however, create a class. Create a class with private member variables string and next (to point to the next class in the list). You'll need setters and getters. The string will simply be a word you enter. Request a word from the user until the user enters end. As the words are entered, build a linked list of classes, forward. Once the list is built, print the list of classes. Enter at least 4 words for a linked list of 4 class objects. You may call the class list . The program must compile and create at least one node with data.arrow_forwardUsing C++(DSA, Topic: Singly linked list) Write a simple airline ticket reservation program. The program should display a menu with the following operations: reserve a ticket, cancel a reservation, check whether a ticket is reserved for person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simper version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list of flights with each node including pointer to a linked list of passengers. Note: Screen shot of working Demo will be shown.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