Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862225
Author: Walter Savitch
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
We know that the first file name is stored at index zero in the ArrayList, and the list stores the file names as strings, so could we write the body of listAllFiles along the following lines? System.out.println(files.get(0)); System.out.println(files.get(1)); System.out.println(files.get(2)); etc. How many println statements would be required to complete the method?
Implement the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values.
Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count.
She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program.
Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut).
Plates.java
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Plates {
private Map<String, Integer> plateMap;…
Write a program that reads the following txt file using “with open file as f” method, converts each line to a list using the split method with ‘’, as the separator, reverses the order in each list, and writes a new txt file where each line is a list. Nothing in your program should be hard coded, meaning, your program should work properly with other txt files, with different number of lines, elements, and content.
The existing txt file:
1,4,3,2,5
8,6,7
C,D,B,A
E,F,H,I,J,G
The created txt file:
[‘5’, ‘2’, ‘3’, ‘4’, ‘1’]
[‘7’, ‘6’, ‘8’]
[‘A’, ‘B’, ‘D’, ‘C’}
[‘G’, ‘J’, ‘I’, ‘H’, ‘F’, ‘E’]
Need code in python
Chapter 18 Solutions
Problem Solving with C++, Student Value Edition plus MyProgrammingLab with Pearson eText -- Access Card Package (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
- For Python, write a program that reads and processes sets of data until a sentinel value of a negative number. The first number in a set is a room number, the second is the room's capacity, and the third is the size of the class scheduled to meet in that room. For each triplet set, print an output line showing the classroom number, capacity, number of seats filled, number of seats available, and a message ("FULL" or "OPEN") indicating whether the classroom is filled or not. After all classrooms have been processed, a summary is to be printed.arrow_forwardWrite a Java program that prompts a user for vehicle data and stores it in a linked list, and then sorts the list in ascending order based on miles-per-gallon and writes the sorted data to a text file, you can follow these steps: Create a class named Vehicle with private fields: make (String), model (String), and milesPerGallon (double). Include getters and setters for these fields. Implement the Comparable interface for Vehicle class and override the compareTo() method to compare vehicles based on their milesPerGallon. Create a main class (for example, VehicleDriver.java) to handle user input and perform the necessary operations. Inside the main method, create a BufferedReader object for user input. Prompt the user to enter the number of vehicle data they want to enter and store it in a variable (for example, nVehicles). Use a loop to iterate nVehicles times and prompt the user to enter make, model, and miles per gallon for each vehicle. Create Vehicle objects using the input data…arrow_forwardWrite a class in python that can store the date and place information (as strings) and can produce a string that represents all of the information that is hold in a list. For example: the following list my have len 3 or len 2 or 1. It should have a method that print the output like: "Birth 01 Aug 1990" Date =["1", "Aug", "1990"] Date2 = ["11", "22", "2003"] Date3= ["2017"] It should have a method that does the same for a place, so if you had to call the methods for a list that has: place= ["Miami"] place2 =["Portland", "Oregon"] It should print like "Place: Miami" or "Place: Portland, Oregon"arrow_forward
- Write 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 words from a filename, which is given as a string argument. It should return the words from the file in a list, sorted in reverse alphabetical order (case insensitive) . For instance, if the file has bell tea Zebra apple yellow Then the output should be ['Zebra', 'yellow', 'tea', 'bell', 'apple'] def reverse_sorted_words(filename): # YOUR CODE HERE raise NotImplementedError()arrow_forwardwrite a program that reads the students.txt file and stores the name of the student and the grade information as a student object in an arraylist sorts the students names based on their first grade in decreasing order using the selection sort algorithm writes the sorted list as the students last name , middle name (if theres one), first name , and grade information into a text file output example: Robison, Lee 95 80 Green, Alex R 85 60 Waston, Zoe G 100 80 use javaarrow_forward
- in python """Write a function get_new_grades, such that given a string of grades as an input parameter,returns two objects:the initial grades as a list of numerical valuesas well asa new list with the numerical values, where the scores that are less than 50 are replaced by 50. """arrow_forwardProvide a different implementation of ChoiceQuestion. Instead of storing the choices in an array list, the addChoice method should add the choice to the question text. For this purpose, an addLine method has been added to the Question class. Use the following files: Question.java /** A question with a text and an answer.*/public class Question{ private String text; private String answer; /** Constructs a question with empty text and empty answer. */ public Question() { text = ""; answer = ""; } /** Sets the answer for this question. @param correctResponse the answer */ public void setAnswer(String correctResponse) { answer = correctResponse; } /** Checks a given response for correctness. @param response the response to check @return true if the response was correct, false otherwise */ public boolean checkAnswer(String response) { return response.equals(answer); } /** Add a line of text to…arrow_forwardWrite a static method named "compareLines" that accepts one parameter (a Scanner attached to an input file). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then the 3rd and 4th lines, and so on) looking for indexes in both strings that contain vowels [a, e, i, o, u, y, A, E, I, O, U, Y] and should output the index where both strings contained a vowel. For example, in the strings "hello" and "bully, the characters at indexes 1 and 4 match since both contain vowels at that index. For each pair of lines, your method should print output showing the character indexes that match, separated by spaces in the format shown below. If no characters match, print "none" instead as shown below. For example, suppose the input file contains the following text. (Line numbers and character indexes are shown around the input and matching characters are shown in bold, but these markings do not appear in the actual file.) 0123456789012345678901234567890123456789 (String…arrow_forward
- Write a static method named "compareLines" that accepts one parameter (a Scanner attached to an input file). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then the 3rd and 4th lines, and so on) looking for indexes in both strings that contain vowels [a, e, i, o, u, y, A, E, I, O, U, Y] and should output the index where both strings contained a vowel. For example, in the strings "hello" and "bully, the characters at indexes 1 and 4 match since both contain vowels at that index. For each pair of lines, your method should print output showing the character indexes that match, separated by spaces in the format shown below. If no characters match, print "none" instead as shown below. For example, suppose the input file contains the following text. (Line numbers and character indexes are shown around the input and matching characters are shown in bold, but these markings do not appear in the actual file.) 0123456789012345678901234567890123456789 (String…arrow_forwardUsing the picture, ultilize Java to design a container class and implement the class PascalTriangle that will generate a Pascal Triangle from a given number of rows. Please represent each row in a triangle as a list and the entire triangle as a list of these lists, implement the class ArrayList for these lists. Inside this Java container class, develop a method called getChoice that takes in two parameters n and k (where n is the number for row and k is the position) and returns the integer value of C(n, k). For example, getChoices (5, 2) will return 7.arrow_forwardWrite a java program that reads in a series of first names and eliminates duplicates by storing them in a Set. Allow the user to search for a first name. Add a name to set, use end to terminate input: Search a name, use end to terminate searching: sample output is given in image: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