Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 18, Problem 5PP
Program Plan Intro
Intersection of two sets
Program Plan:
- Include required header file.
- Define main function.
- Declare variable “R” in “set” template class of type “string”.
- Declare iterator variable “iter” in “set” template class of type “string”.
- Initializes the string for set “Q” and set “D”.
- Declare the iterator variable “cIterator” for storing result of intersection of two sets “Q” and “D”.
- Compute the intersection of two sets by using the generic function “set_intersection” function.
- Display the string in resultant string after intersecting two sets.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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!
Can you help with with the following questions, regarding population genetics and the Wright Fisher model in python?
1. Go through the given WFtrajectory function and give a short explanation of what each line of code does. Pay attention to the variables in the function and explain what they contain.
2. Make a new version of the WFtrajectory function which does exactly the same thing except that instead of appending to a list it initialises a numpy vector with zeroes and fills the vector with a for loop instead of a while loop. Make a plot of the output from a few example trajectories.
You need to edit the same code so as to make it a circular doubly linked list. Implement the necessary functionality in all the given functions.
Note: A circular doubly linked list is a doubly linked list whose last next pointer points to the head node
#include <iostream>
using namespace std;
class Node{
public:
int data;
Node *next;
Node *prev;
};
class List{
public:
Node *head;
List(){
head = NULL;
}
void display(){
Node *temp = head;
while(temp!=NULL)
{
cout<<temp->data<<endl;
temp=temp->next;
}
}
void insert(int data){
Node *nn = new Node;
nn->next = NULL;
nn->prev = NULL;
nn->data = data;
if(head==NULL){
head = nn;
cout<<"Node inserted successfully at head"<<endl;
}
else{
Node *temp = head;…
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
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
- Topical Information Use C++. The purpose of this project is to test your ability to use templates, dynamic memory (mixed with classes), operator overloading, and libraries effectively in program design. Program Information Create a template class for a dynamic 1D array. You can model your class off of our String class or the dynamic list class. Changes from String class: You won't need an end-of-string element in the array. The element type is now templated. Translation will no longer be necessary. operators - and -= 'might' now make sense (erase element(s)?). ... Show how useful your template array class is by creating arrays of short integers doubles String class objects (static) Point class objects pointers to Point class objects (each allocated on the heap) — all in one test application. Make sure your test application is a good/thorough test of your class. (Your test application might utilize the applyand accumulatefunctions from lecture to facilitate testing. Also note how a…arrow_forwardin C++ kth ElementExtend 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, do not copy from any other sources, give me a fresh new code. Thank youarrow_forwardWrite in C++ Now, what if Sam wants to insert Eevee after Pikachu but he doesn't know where Pikachu is located in his list. Let's help him search for a Pokemon by its name and insert another Pokemon directly after it. Write a function secondPlace() that takes six parameters and inserts a new Pokemon into a list right after another specified pokemon. Once you find the specified Pokemon, use the insertAfter() function from the previous sub-question to add the new Pokemon. The function should return the new number of strings in the array. Note The same Pokemon may appear in the list multiple times (Sam has a bad memory). Assume that Sam wants every instance of the Pokemon he is searching for to be followed by the Pokemon he is attempting to insert. If the array is already full or if the number of strings that are going to be added to the array plus the current number of strings exceeds the total size of the array, the array should remain unchanged. Assume all inputs are lowercase…arrow_forward
- Write a template function that takes as parameter a vector of a generic type and reverses the order of elements in the vector, and then add the function to the program you wrote for Programming Challenge 5. Modify the driver program to test the new function by reversing and outputting vectors whose element types are char, int, double, and string.arrow_forwardUsing C++arrow_forwardAssuming you have a c-string variable "location" with a size of 30, write a line of code that allows you to read in an entire line of input to fill the variable. When we say that vectors are an example of a template class, what do we mean? Provide two unique vector declarations to illustrate this. What is the difference between the find and find_first_of string member functions?arrow_forward
- Write a function myJoin(lst, glue) in JavaScript that takes a "glue" string and a list of strings and uses Array#reduce to return a single string that contains all the elements in lst joined by the "glue" string. You must use Array#reduce do the vast majority of the work. (You may do a little pre- and post- processing outside the call to reduce.) The lambda passed to Array#reduce function has parameters in this order: partial, item. When working on this question, you may visit this page containing the documentation for the Array class. You may assume that lst is not empty. For example, myJoin(["Arizona", "Nevada"], ",") should return "Arizona, Nevada" myJoin(["GVSU", "Ferris", "Michigan Tech"], "--") should return "GVSU -- Ferris -- Michigan Tech"arrow_forwardWrite the definition of the function template reverseVector to reverse the elements of a vector object. template<class elemType> void reverseVector(vector<elemType> &list); //Reverses the elements of the vector list. //Example: Suppose list = {4, 8, 2, 5}. // After a call to this function, list = {5, 2, 8, 4}. Also, write the (C++) program to test the function reverseVector. When declaring the vector object, do not specify its size. Use the function push_back to insert elements in the vector object.arrow_forwardWrite a template for a function that has parameters for a list of items and for a possible item on the list. If the item is on the list, then the function returns the position of the first occurrence of that item. If the item is not on the list, the function returns −1. The first position on the list is position 0, the next is position 1, and so forth. The type of the items on the list is a type parameter. Use the class template GenericList that you defined in Project 1. Write a suitable program(main function) to test this function template.arrow_forward
- C++arrow_forwardQUESTION: NOTE: This assignment is needed to be done in OOP(c++/java), the assignment is a part of course named data structures and algorithm. A singly linked circular list is a linked list where the last node in the list points to the first node in the list. A circular list does not contain NULL pointers. A good example of an application where circular linked list should be used is a items in the shopping cart In online shopping cart, the system must maintain a list of items and must calculate total bill by adding amount of all the items in the cart, Implement the above scenario using Circular Link List. Do Following: First create a class Item having id, name, price and quantity provide appropriate methods and then Create Cart/List class which holds an items object to represent total items in cart and next pointer Implement the method to add items in the array, remove an item and display all items. Now in the main do the following Insert Items in list Display all items. Traverse…arrow_forwardin c++, use parallel arrays , and srand(time(NULL)) to randomize the two cards dealt at the start Create a Blackjack (21) game. Your version of the game will imagine only a SINGLE suit of cards, so 13 unique cards, {2,3,4,5,6,7,8,9,10,J,Q,K,A}. Upon starting, you will be given two cards from the set, non-repeating. Your program MUST then tell you the odds of receiving a beneficial card (that would put your value at 21 or less), and the odds of receiving a detrimental card (that would put your value over 21). Recall that the J, Q, and K cards are worth ‘10’ points, the A card can be worth either ‘1’ or ‘11’ points, and the other cards are worth their numerical values.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