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 9PP
Program Plan Intro
Elimination of Duplicate Names
- Include required header file.
- Include required “std” namespace.
- Define main function
- Declare variable for input file.
- Declare a variable “ns” in “set” template class of “string” type.
- Open the given input file.
- If the input file is fail, then the program terminates.
- Otherwise, performs “while” loop. This loop executes until the end of file.
- Declare a variable “name” in “string” type.
- Read the name from given input file.
- Then insert a name into “set” template class. If any duplicate name contains, then it remove that name.
- Close the file.
- Display statement.
- Declare a variable “np” in constant iterator of “set” template class.
- Display the names to generate the invitation list after removing duplicates names using “for” loop.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Make a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.
Consider a text file of names, with one name per line, that has been compiled from several different sources. A sample is shown below:Brooke TroutDinah SoarsJed DyeBrooke TroutJed DyePaige TurnerThere are duplicate names in the file. We would like to generate aninvitation list but don’t want to send multiple invitations to the sameperson. Write a program that eliminates the duplicate names by usinga HashSet. Read each name from the file, add it to the HashSet, andthen output all names in the HashSet to generate the invitation listwithout duplicates
Two dat files are shown. You can use txt files instead to put in the names. One is a list of students from VR that took AP exams. The other list is a list of students across the world that scored 4+ on AP exams. Design a Java program that reads both files into two separate sets and then use set operations to create a 3rd set of VR students that scored 4+ on AP exams. The output is printing the 3rd set, which is the VR students that scored a 4+ on the AP exams.
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
- Write a program that reads a list of enrollments from a file and prints a class roster for the teacher. Make the class roster line up as neatly as you can and still fit on the screen. You can choose the actual values to use for your data. Make sure to do enough sets of data to well test your program! (Empty data set, normal data set, data with large values, data with short values, etc.) Also, your program can't know ahead of time how many people are enrolled in the class... Don't forget to read the file's name from the user and protect your program against any errors that may occur during the opening of the file. Try to use functions to break up the program into more manageable pieces. USING C++ As an example, you might have the data file contain:arrow_forwardWrite a program that reads a list of enrollments from a file and prints a class roster for the teacher. Make the class roster lineup as neatly as you can and still fit on the screen.You can choose the actual values to use for your data. Make sure to do enough sets of data to well test your program!(Empty data set, normal data set, data with large values, data with short values, etc.)Also, your program can't know ahead of time how many people are enrolled in the class... using c++arrow_forwardWe have two classes; these classes are "Car" and "Price".The "car" class is a class that keeps the id and price of the car.If the "Price" class is, there will be get / set methods for the segment of the fee (For example Y segment Z segment), the number of cars, and the "Car" class list.In the "Price" class, there should be a print method to add / remove cars to the list and find the ids of Vehicles whose segments are equal to X.The segments are as follows. 0$ -15999$ -> Y Segment16000$-24999$ -> Z Segment25000$-50000$ -> T Segment It is necessary to use "Single Linked List".The program should be written in JAVA.arrow_forward
- 1. The codewords will be scrambled words. You will read the words used for the codes from a file and store it into an array. There are 60 words in the file that range in size from 3 characters to 7 characters. The file is called wordlist.txt and can be found attached to the assignment in IvyLearn.2. Start with input for an integer seed for the random number generator. There is no need to put a prompt before the cin operation.3. Ask the Player if they are ready to play and only proceed if they type a Y or y. If the user types an N or n then the program should finish. a. INPUT VALIDATION: Make sure the user has typed either y, Y, n, or N4. Create a variable to keep track of the number of guesses the user has made.5. Use the random number generator to pick a word from the list of words.6. Once you have chosen a word as the codeword you will need to scramble the letters to make it into a code. You should use the random number generator to help you mix up the letters.7. Display to the user…arrow_forwardIn this assignment, you will write a program that readsa list of people from a file, create a HashSet of the people, and print the people in the HashSet.The input filename ispassed in as a command line argument.•The program must implement a main class, and a Person class.•A template for the Person class is provided.A Person has a name and an address, both Strings.•If the input file name is not provided, your program should an error message and exit, e.g., Usage: java FuAssignment10/FuMain inputfile•If the specified input file does not exist or cannot be opened, your program should an error message and exit, e.g.,File abc.txt does not existor cannot be opened!•The input file lists one person per line. Each line contains aname and an address, separated by a comma, “,”.For example, the following are in a sample file students.txt:James Bond, 111 Main StTayer Smoke, 2334 Murry LnDavid Jones, 302 Toast AveAbby Wasch, 84 Sunny PlJames Bond, 111 Main St•Yourprogram should read each line,…arrow_forwardFor this assignment, your program will read characters from a string for the purpose of assigning data from that string to the private data members of a class. This simulates a program that would read a record in from a stored file into memory for the purpose of making changes to that record. Below is a template of your program. For this assignment, you MUST use loops (100 pts off if not using loops) and you cannot use the following methods: indexOf() substring() subsequence().arrow_forward
- 1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or byentering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For example, if the list contains the following names: Charles Darwin Albert Einstein Issac Newton Tony Hoare Grace Hopper Edgar Dijkstra Ada Lovelace Charles Babbage Stephen Hawking Your program should output:The first name in the list in alphabetical order is: Ada Lovelace The last name in the list in alphabetical order is: Tony Hoarearrow_forwardWrite a program that reads a course's title and enrolled student information (student id, student score) and displays the input data followed by the frequency of each score in the course. The end of input is indicated by letter q on the last line For example, for the input: 10 90 12 50 17 85 15 90 42 75 20 90 30 75 78 50 61 50 21 85 22 50 q The output is: COP 3804 class list 10 90 12 50 17 85 15 90 42 75 20 90 30 75 78 50 61 50 21 85 22 50 COP 3804 class scores 90 3 50 4 85 2 75 2 Given classes: class Student represents a student class Roster represents a course class LabProgram contains the main method that reads course data (i.e. course title and students' information), creates a Roster object with the input data and produces the output by calling relevant methods of the Roster object Your task is to complete the following methods: class Student: public Student(String id, int score) { /* Student Employee */ } public String getID() { /* returns student's id */ } public…arrow_forwardWrite a program that reads in babynames.txt and produces two files, boynames.txt and girlnames.txt, separating the data for the boys and girls. Write a program that reads the above two files into 2 lists containing tuples (rank, name) Sort them based on the names - be sure ranks are sorted based on names print all names that are both boy and girl names (such as Alexis or Morgan). Everything has to be inside functions - the main function (on the top) should be calling functions. ////////////////////////////////////////////////////////////// IN PYTHON ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// babynames.txt ////////////////////////////////////////////////////////////// 1 Jacob 1.0013% Sophia 1.1297% 2 Mason 0.9637% Isabella 1.0282% 3 William 0.8522% Emma 0.9724% 4 Jayden 0.8378% Olivia 0.8940% 5 Noah 0.8307% Ava 0.8010% 6 Michael 0.8247% Emily 0.7375% 7 Ethan 0.8231% Abigail 0.6847% 8 Alexander 0.7746%…arrow_forward
- Create a Java program. You have a list of Student ID's followed by the course number(separated by aa space) that the student is enrolled in. The listing is in no particular order. For eg. is student 1 is in CS100 and CS200 while student 2 is in CS105 and MATH210 then the list may look like this: 1 CS100 2 MATH210 2 CS105 1 CS200 Write a program that reads data in this format from the console. If the ID is -1 then stop inputting data. Use the HashMap class to map from an Integer(Student ID) to an ArrayList of type String that holds each class that the student is enrolled in. The declaration should look like this: HashMap<Integer, ArrayList<String>> students = new HashMap<Integer, ArrayList<String>>(); After all data is input, iterate through the map and output the student ID and all classes stored in the vector for that student. The result should be a list of classes organized by student id.arrow_forwardYour program will read in a list of high and low integer temperatures and city names from System.in using the Scanner class, then sort the information three different ways: by high temperature, low temperature, and by city name. It is a requirement of the assignment that an ArrayList is used to store the data internally, and the sort method that ArrayList implements for the List interface is used to do the sorting. Here is some sample input/output. The program would first print out a prompt: Enter high/low temperatures and city: The user might then type or paste the following into the terminal or Netbeans' output window: 60 37 Dallas, TX 61 42 Kansas City, KS 75 57 Cleveland, OH 81 70 Fort Lauderdale, FL 79 55 Seattle, WA . Notice that the input ends with a line starting with a period; as in Programming Project 1, the last line could start with any non-digit character. There is no limit on the number of lines of input the program might receive; since your program is using an ArrayList…arrow_forwardYour program will read in a list of high and low integer temperatures and city names from System.in using the Scanner class, then sort the information three different ways: by high temperature, low temperature, and by city name. It is a requirement of the assignment that an ArrayList is used to store the data internally, and the sort method that ArrayList implements for the List interface is used to do the sorting. Here is some sample input/output. The program would first print out a prompt: Enter high/low temperatures and city: The user might then type or paste the following into the terminal or Netbeans' output window: 60 37 Dallas, TX 61 42 Kansas City, KS 75 57 Cleveland, OH 81 70 Fort Lauderdale, FL 79 55 Seattle, WA . Notice that the input ends with a line starting with a period; as in Programming Project 1, the last line could start with any non-digit character. There is no limit on the number of lines of input the program might receive; since your program is using an ArrayList…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