Given a ListItem class, complete main() using the built-in list type to create a linked list called shoppingList. The program should read items from input (ending with -1), adding each item to shoppingList, and output each item in shoppingList using the PrintNodeData() function.
Ex. If the input is:
milk
bread
eggs
waffles
cereal
-1
the output is:
milk
bread
eggs
waffles
cereal
#include "ListItem.h"
#include <string>
#include <list>
#include <iostream>
using namespace std;
int main (int argc, char* argv[]) {
// TODO: Declare a list called shoppingList of type ListItem
string item;
// TODO: Read inputs (items) and add them to the shoppingList list
// Read inputs until a -1 is input
// TODO: Print the shoppingList list using the PrintNodeData() function
return 0;
}
#ifndef LISTITEMH
#define LISTITEMH
#include <string>
using namespace std;
class ListItem {
public:
ListItem();
ListItem(string itemInit);
// Print this node
void PrintNodeData();
private:
string item;
};
#endif
#include "ListItem.h"
#include <iostream>
ListItem::ListItem() {
item = "";
}
ListItem::ListItem(string itemInit) {
item = itemInit;
}
// Print this node
void ListItem::PrintNodeData() {
cout << item << endl;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- In python pleasearrow_forwardJAVA PROGRAM BELOW IS A WORKING PROGRAM. PLEASE MODIFY THIS PROGRAM SO IT PASSES THE TEST CASE. I HAVE PROVIDED THE failed part of the test case AND THE INPUTS AS A SCREENSHOT. TEST CASE 1 Enter a name to search or type QUIT to exit:\nAnnabelleENTERThe name 'Annabelle' was not found in either list.\nEnter a name to search or type QUIT to exit:\nxavierENTERThe name 'Xavier' was found in popular boy names list (line 81).\nEnter a name to search or type QUIT to exit:\nAMANDAENTERThe name 'Amanda' was found in popular girl names list (line 63).\nEnter a name to search or type QUIT to exit:\njOrdAnENTERThe name 'Jordan' was found in both lists: boy names (line 38) and girl names (line 75).\nEnter a name to search or type QUIT to exit:\nquitENTER import java.io.*;import java.util.*;public class NameSearcher { // Load a text file into a list of names (ignores case) private static List<String> loadFileToList(String filename) throws FileNotFoundException {…arrow_forwardImplement a function void printAll(void) to print all the items of the list.arrow_forward
- Debug the program debug_me.py. The program should test each of the users in the provided list. · If the list is empty, it should print “There are no users.” · If the user is “Admin,” the program should print “Hello all powerful one.” · Otherwise, for normal users, it should print “You are a normal user.” Test the program with an empty list to confirm correct operation for that case.arrow_forwardQUESTION 4 in phython language Write a program that creates a list of N elements (Hint: use append() function), swaps the first and the last element and prints the list on the screen. N should be a dynamic number entered by the user. Sample output: How many numbers would you like to enter?: 5 Enter a number: 34 Enter a number: 67 Enter a number: 23 Enter a number: 90 Enter a number: 12 The list is: [12, 67,23, 90, 34]arrow_forwardInstructions Write a program to test various operations of the class doublyLinkedList. Your program should accept a list of integers from a user and use the doubleLinkedList class to output the following: The list in ascending order. The list in descending order. The list after deleting a number. A message indicating if a number is contained in the list. Output of the list after using the copy constructor. Output of the list after using the assignment operator. An example of the program is shown below: Enter a list of positive integers ending with -999: 83 121 98 23 57 33 -999 List in ascending order: 23 33 57 83 98 121 List in descending order: 121 98 83 57 33 23 Enter item to be deleted: 57 List after deleting 57 : 23 33 83 98 121 Enter item to be searched: 23 23 found in the list. ********Testing copy constructor*********** intList: 23 33 83 98 121 ********Testing assignment operator*********** temp: 23 33 83 98 121 Your program should use the value -999 to denote the end of the…arrow_forward
- Write a function called find_duplicates which accepts one list as a parameter. This function needs to sort through the list passed to it and find values that are duplicated in the list. The duplicated values should be compiled into another list which the function will return. No matter how many times a word is duplicated, it should only be added once to the duplicates list. NB: Only write the function. Do not call it. For example: Test Result random_words = ("remember","snakes","nappy","rough","dusty","judicious","brainy","shop","light","straw","quickest", "adventurous","yielding","grandiose","replace","fat","wipe","happy","brainy","shop","light","straw", "quickest","adventurous","yielding","grandiose","motion","gaudy","precede","medical","park","flowers", "noiseless","blade","hanging","whistle","event","slip") print(find_duplicates(sorted(random_words))) ['adventurous', 'brainy', 'grandiose', 'light', 'quickest', 'shop', 'straw', 'yielding']…arrow_forwardPYTHON LAB: Inserting an integer in descending order (doubly-linked list) Given main.py and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing the insert_in_descending_order() method to insert new IntNodes into the IntList in descending order. Ex. If the input is: 3 4 2 5 1 6 7 9 8 the output is: 9 8 7 6 5 4 3 2 1 _____________________________________________________________________________________ Main.py: from IntNode import IntNode from IntList import IntList if __name__ == "__main__": int_list = IntList() input_line = input() input_strings = input_line.split(' ') for num_string in input_strings: # Convert from string to integer num = int(num_string) # Insert into linked list in descending order new_node = IntNode(num) int_list.insert_in_descending_order(new_node) int_list.print_int_list() IntNode.py class IntNode: def __init__(self, initial_data, next = None,…arrow_forward1.Given the argument passed to the function is a list containing integer values, what does the function return def mystery1(someListOfValues: list):total = 0for value in someListOfValues:total += valuereturn total/len(someListOfValues) 2. The function below is to find the largest value in a list passed by parameter. Does it work as intened (yes or no)? If not give an example of an argument it would not work for. def maxValue(someListOfValues:list):"""returns the largest value the list passed by parameter"""value = 0for num in someListOfValues:if num > value:value = numreturn value 3.Write a function called loadNames() that will open a file called names.txt and build a list of its contents and return it. Function Call: names = loadNames()print(names) Sample ouput: ['Nolan Rafaj\n', 'Brandon Brzuszkiewicz\n', 'Amanda Vozari\n', 'Chase Harper\n', 'Bryce Conner']arrow_forward
- Java - Elements in a Rangearrow_forwardTask 5 Write a Python program that takes numbers as input into a list, removes multiple occurences of any number and then finally prints a list without duplicate values. Hint: You may create a third list to store the results. You can use membership operators (in, not in) to make sure no duplicates are added. Sample Input 1: 0, 0, 1, 2, 3, 4, 4, 5, 6, 6, 6, 7, 8, 9, 4, 4 Sample Output 1: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Sample Input 2: 7, 7, 7, 1, 0, 3, 3, 55, 9 Sample Output 2: [7, 1, 0, 3, 55, 9]arrow_forward@6 The Reference-based Linked Lists: Select all of the following statements that are true. options: As a singly linked list's node references both its predecessor and its successor, it is easily possible to traverse such a list in both directions. According to the terminology introduced in class, the head reference variable in a singly linked list object references the list's first node. According to the terminology introduced in class, in a doubly linked list, each node references both the head and tail node. In a double-ended singly linked list, the tail reference variable provides access to the entire list. In a circular linked list, the last node references the first node.arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY