Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18, Problem 2P
Program Plan Intro
Histogram of positive numbers
Program Plan:
- Include required header file.
- Include required “std” namespace.
- Define main function
- Declare a variable in “map” template class.
- Initializes the variable “numbers” to “0”.
- Display prompt statement.
- Performs “while” loop. This loop will perform upto “numbers” equal to “-1”.
- In this loop, first read the number from user.
- If the number is not equal to “-1”, then check if the number is in map or not using “find” function.
- If it is, then assign “mapResult[numbers]” is “1”.
- Otherwise, increment the counter
- Declare constant iter “result” in “map” template class.
- Display the given result using “for” loop.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The international standard letter/number mapping for telephones is:
Write a function that returns a number, given an uppercase letter, as follows:def getNumber(uppercaseLetter):Write a test program that prompts the user to enter a phone number as a string. The input number may contain letters. The program translates a letter (uppercase or lowercase) to a digit and leaves all other characters intact. Here is a sample run of the program:
Enter a string: 1-800 flowers1-800-3569377
A. write a code to find the number of students who pass CS course, when their marks>=40 . As thelist has 85 students.
B. wite a code to print this shape:
***
***
****
C. Write a code to find the area and parameter of a Tringle;
Area =1/2 * High * BaseParameter= S1+S2+ Base
In java
Develop a function that accepts an array and returns true if the array contains any duplicate values or false if none of the values are repeated.
Develop a function that returns true if the elements are in decreasing order and false otherwise.
A “peak” is a value in an array that is preceded and followed by a strictly lower value. For example, in the array {2, 12, 9, 8, 5, 7, 3, 9} the values 12 and 7 are peaks. Develop a function that returns the number of peaks in an array of integers. Note that the first element does not have a preceding element and the last element is not followed by anything, so neither the first nor last elements can be peaks.
Develop a function that finds the starting index of the longest subsequence of values that is strictly increasing. For example, given the array {12, 3, 7, 5, 9, 8, 1, 4, 6}, the function would return 6, since the subsequence {1, 4, 6} is the longest that is strictly increasing.
Develop a function that takes a string…
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
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- mergeAndRemove(int[], int[]) This is a public static function that takes a int[] and int[] for the parameters and returns an int[]. Given two arrays of integers. Your job is to combine them into a single array and remove any duplicates, finally return the merged array.arrow_forwardIN MAGICFS LANGUAGE The Fibonacci sequence begins like this: 0,1,1,2,3,5,8,13,21,... A number in the sequence is the sum of the previous two numbers in the sequence, with first two being 0 and 1. Implement a function named 'fibonacci' that expects a working value of an integer index, and returns the Fibonacci number at that position in the sequence. The index is zero-based. For instance, if given a value of 4, the function should return 3 because the sequence is 0, 1, 1, 2, 3, ... Use subroutines if necessary. Your answer will be evaluated for partial credit. Comments are encouraged.arrow_forwardobject oriented c++arrow_forward
- in C++... kth Element Extend the class linkedListType by adding the following operations:a. Write a function that returns the info of the kth element of the linked list. If no such element exists, terminate the program.b. Write a function that deletes the kth element of the linked list. If no such element exists, terminate the program. Provide the definitions of these functions in the class linkedListType. PLEASE DON'T reject this question, this is the whole question that I have... so please do it however u can, Thank you!arrow_forwardin c++ : The function insert of the class orderedLinkedList does not check if the item to be inserted is already in the list; that is, it does not check for duplicates. Rewrite the definition of the function insert so that before inserting the item it checks whether the item to be inserted is already in the list. If the item to be inserted is already in the list, the function outputs an appropriate error message. Also write a program to test your function (in the driver file).arrow_forwardComputer Science IN C++ Write a program that implements the game tic-tac-toe: Tic-Tac-Toe is a game played on a three-by-three board. Two players, X and O, alternate in placing their respective marks in the cells of this board, starting with player X. If either player succeeds in getting three of his or her marks in a row, column, or diagonal, then that player wins. In this homework, you should use the OOP concepts to implement the tic-tac-toe game.arrow_forward
- Problem 1: Lo Shu Magic Square The Lo Shu Magic Square is a grid with 3 rows and 3 columns. The Lo Shu Magic Square has the following properties: • The grid contains the numbers 1 through 9 exactly.• The sum of each row, each column, and each diagonal all add up to the same number. This is shown in Figure ➔➔➔ "Attached Image" In a python program, you can simulate a magic square using a two-dimensionallist. Write a function that accepts a two-dimensional list as an argumentand determines whether the list is a Lo Shu Magic Square. Test thefunction in a program. Below is the main() function and some globalconstants. You may need to define multiple functions to organize yourcode. # Global constants ROWS = 3 # The number of rowsCOLS = 3 # The number of columnsMIN = 1 # The value of the smallest numberMAX = 9 # The value of the largest numberdef main():# Create a two-dimensional list.test_list = [ [4, 9, 2],[3, 5, 7],[8, 1, 6] ] # Display the list in row and column…arrow_forwardWrite a program in C++ that lets the user enter a product code. The program should determine if the product code is valid by checking for it in the following list: 65482 15975 48758 58698 69618 78965 68416 26489 35498 91651 The codes should be initialized into an array. A simple linear search should be used to locate the code entered by the user. If the user enters a code that is in the array, the program should display a validation message. If the user enters a code that is not in the array, it should display an error message.arrow_forward#in c++arrow_forward
- IN C++ USING CLASS Write a program in C++ that implements the game tic-tac-toe: Tic-Tac-Toe is a game played on a three-by-three board. Two players, X and O, alternate in placing their respective marks in the cells of this board, starting with player X. If either player succeeds in getting three of his or her marks in a row, column, or diagonal, then that player wins. In this homework, you should use the OOP concepts to implement the tic-tac-toe gamearrow_forwardQ4. Write a program that read 2 matrices and has a function which finds their sum. Q5. Write a program that read 2 matrices and has a function which finds their multiplication. Q6. Write a program that handles a list of numbers where it has the following functions - Function that finds their average and sum - Function that finds their maximum and minimum - Function that search for a given number in that list. - Function that count the occurrence of a given number in that list. Then the program should do the following: - Read the list - Find the average and the sum of that list - Find the minimum and the maximum of that list - Count the occurrence of a given number in that list.arrow_forwardWrite these in Pseudocode #1a – In pseudocode, write a call to a function that passes 1 Integer variable and 1 Integer array, and saves a Boolean value in return. #1b – In pseudocode, write the function that accepts 1 Integer and 1 Integer array and returns a Boolean. In the function, search the Integer array with a for-loop, and if the Integer parameter is found in the array, return false. If the Integer parameter is not found, return true. #2a – In pseudocode, write a call to a module that passes 1 Integer variable, 1 Real variable, 1 String constant, and 1 String literal as arguments. #2b – In pseudocode, write the module header that accepts 1 Integer, 1 Real, and 2 Strings as parameters. #3 – This pseudocode has multiple problems. Fix the calling statement and the definition below so that the routine accepts 3 grades as parameters and returns the average into a variable.…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