Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 17, Problem 12PC
Program Plan Intro
Recursive Generation of Subsets
Program Plan:
- Include the required header files
- Declare function prototypes.
- Define the “main ()” function.
- Declare the required variables.
- Get the input from the user.
- If the user input is not in the range the condition exits the program.
- Create the list and call the function “get_Subsets ()”.
- Display the output.
- Define the overloaded stream insertion operator for
vector of int.- Display the open square bracket.
- If the number is in the range, display the number inside the bracket.
- Display the close square bracket.
- Return the output to the main function.
- Define the overloaded stream insertion operator for a list of generic type.
- Display the open square bracket.
- Create a list and declare the variable name “itr” for the list.
- While condition used to check if the “itr” is not equal to last number in the same list.
- If so, display the number.
- Increment the “itr”.
- Print the numbers separated by commas.
- Display the close square bracket.
- Return the output to the main function.
- Define the “get_subsets” vector function.
- Declare the list of subsets.
- Check the “n” value is equal to 0.
- If do, start with a list of subsets of 1 to n that contains on the empty set.
- Return the sub list.
- Get the list of all subsets of 1 to n-1 and store it in a “sub_setList”.
- Temporarily used to extend the subset list by declaring the vector variables.
- While condition used to check if the “itr” is not equal to last number in the same list.
- Declare the vector variables.
- Push the value to the list.
- Increment the “itr” value.
- Return the value to the main function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
By using java, Write a recursive function that finds the maximum element in an array ofintegers, based on comparing the first element in the array against themaximum in the rest of the array recursively.
Write a recursive function using python for the problem:
A palindrome is a sequence of characters which is the same when the sequence is reversed. Given an array A indexed from p to q containing characters, determine if the sequence of characters in A[p..q] forms a palindrome. Return True is a palindrome is formed and return False if it does not.
Implement a recursive C++ function which takes an integer array (A) and the starting (start) and ending(end) indices of that array, and returns the sum of all elements present in that array. The prototype ofyour function should be:int findSum (int* A, int start, int end)
Chapter 17 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 17.1 - Prob. 17.1CPCh. 17.1 - Prob. 17.2CPCh. 17.1 - Prob. 17.3CPCh. 17.1 - Prob. 17.4CPCh. 17.2 - Prob. 17.5CPCh. 17.2 - Prob. 17.6CPCh. 17.2 - Why does the insertNode function shown in this...Ch. 17.2 - Prob. 17.8CPCh. 17.2 - Prob. 17.9CPCh. 17.2 - Prob. 17.10CP
Ch. 17 - Prob. 1RQECh. 17 - Prob. 2RQECh. 17 - Prob. 3RQECh. 17 - Prob. 4RQECh. 17 - Prob. 5RQECh. 17 - Prob. 6RQECh. 17 - Prob. 7RQECh. 17 - Prob. 8RQECh. 17 - Prob. 9RQECh. 17 - Write a function void printSecond(ListNode ptr}...Ch. 17 - Write a function double lastValue(ListNode ptr)...Ch. 17 - Write a function ListNode removeFirst(ListNode...Ch. 17 - Prob. 13RQECh. 17 - Prob. 14RQECh. 17 - Prob. 15RQECh. 17 - Prob. 16RQECh. 17 - Prob. 17RQECh. 17 - Prob. 18RQECh. 17 - Prob. 1PCCh. 17 - Prob. 2PCCh. 17 - Prob. 3PCCh. 17 - Prob. 4PCCh. 17 - Prob. 5PCCh. 17 - Prob. 6PCCh. 17 - Prob. 7PCCh. 17 - Prob. 8PCCh. 17 - Prob. 10PCCh. 17 - Prob. 11PCCh. 17 - Prob. 12PCCh. 17 - Running Back Program 17-11 makes a person run from...Ch. 17 - Read , Sort , Merge Using the ListNode structure...
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
- Write an iterative function that determines the number of even elements in an array a of integers of size n. The function should return the number of elements that are even in array a of size n. Propose an appropriate prototype for your function and then write its code. Write a recursive function to solve the above problem. Propose an appropriate prototype for your function and then write its code.arrow_forwardpython code Write a recursive function such that, given a list of intergers (say v) and an integer value (say x), the function returns resulting subset if there is a subset of intergers in v that sum up to x. Otherwise the function returns an empty list; Also write a sample code that runs this function using an example list and value x, and state the expected resultarrow_forwardThe Polish mathematician Wacław Sierpiński described the pattern in 1915, but it has appeared in Italian art since the 13th century. Though the Sierpinski triangle looks complex, it can be generated with a short recursive function. Your main task is to write a recursive function sierpinski() that plots a Sierpinski triangle of order n to standard drawing. Think recursively: sierpinski() should draw one filled equilateral triangle (pointed downwards) and then call itself recursively three times (with an appropriate stopping condition). It should draw 1 filled triangle for n = 1; 4 filled triangles for n = 2; and 13 filled triangles for n = 3; and so forth. API specification. When writing your program, exercise modular design by organizing it into four functions, as specified in the following API: public class Sierpinski { // Height of an equilateral triangle whose sides are of the specified length. public static double height(double length) // Draws a filled equilateral…arrow_forward
- Consider the following function: void fun_with_recursion(int x) { printf("%i\n", x); fun_with_recursion(x + 1); } What will happen when this function is called by passing it the value 0?arrow_forwardWhen recursion is used to solve a problem, why must the recursive function call itself to solve asmaller version of the original problem?arrow_forwardImplement a recursive C++ function which takes an array of integers (arr) and the starting (start) andending (end) indices of a portion (part) of this array, and returns the index of thelargest element present in that portion of array arr. The prototype of your function should be:int findLargest (int* arr, int start, int end) For example, the function call findLargest(arr,3,8)should determine and return the index of the largest element present in the array arr between the indices 3and 8 (both inclusive)arrow_forward
- implement two recursive versions of the linear search that gets an array of songs and a title and searches for a song with the given title in the array. In this version, the function returns the first index of the array containing the number. If the number is not in the array, the function returns -1. int linear_search_rec_first(int* ar, int length, int number);arrow_forwardWrite a recursive implementation of Euclid's Algorith for finding the greatest common divisor(GCD) of two intergers. Descriptions of this algorithm are available in algebra books and on theweb. (Note: A nonrecursive version of the GCD problem was given in the programming exercisesfor Chapter 7.) Write a test program that calls your GCD procedure five times, using thefollowing pairs of integers: (5,20),(24,18),(11,7),(432,226),(26,13). After each procedure call,display the GCD.arrow_forwardIn Kotlin, Write a recursive function with an expression body that takes an Int n and returns a list of the areas of circles for each radius from n to 1 (in decreasing order.) Get the areas by calling the area function. Then rewrite the recursive function so that the areas appear in increasing order. You do not need to use tail recursion in this casearrow_forward
- Write a recursive function named RecursiveSum that, given a positive number n (n> 0), returns the sum of the numbers from 1 to n. Also, show the process of finding the result using a recursion tree. (answer the second question using c++)arrow_forwardImplement a recursive C++ function which takes a character (ch) and a positive integer (n) and prints thecharacter ch, n times on the screen. The prototype of your function should be:void printChar (char ch, int n)For example, calling printChar('*',5) should display ***** on screen.Note: There should NOT be any loop in your function.arrow_forwardGive a recursive definition of the following set of ordered pairs of positive integers: S = {(a, b)| (a is element of positive integer), (b is an integer multiplied by 3)}arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning