Question: Write code In C++ Please Grocery Shopping List (list) Given a ListItem class, complete main() using the built-in list type to create a linked list

Write code In C++ Please

 Grocery Shopping List (list)

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

Here are the contents of ListItem.h:

#ifndef LISTITEMH #define LISTITEMH #include using namespace std; class ListItem { public: ListItem(); ListItem(string itemInit); // Print this node void PrintNodeData(); private: string item; }; #endif

Here are the contents of ListItem.cpp:

#include "ListItem.h" #include ListItem::ListItem() { item = ""; } ListItem::ListItem(string itemInit) { item = itemInit; } // Print this node void ListItem::PrintNodeData() { cout << item << endl; }

Use this as a template for your file, a1.1.cpp:

#include "ListItem.h" #include #include #include using namespace std; int main () { // 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 }

 Student Grades (map)

Given a map pre-filled with student names as keys and grades as values, complete main() by reading in the name of a student, outputting their original grade, and then reading in and outputting their new grade.

Ex: If the input is:

Quincy Wraight 73.1

the output is:

Quincy Wraight's original grade: 65.4 Quincy Wraight's new grade: 73.1

Use this as a template for your file, a1.2.cpp:

#include #include #include using namespace std; int main () { string studentName; double studentGrade; map studentGrades; // Students' grades (pre-entered) studentGrades.emplace("Harry Rawlins", 84.3); studentGrades.emplace("Stephanie Kong", 91.0); studentGrades.emplace("Shailen Tennyson", 78.6); studentGrades.emplace("Quincy Wraight", 65.4); studentGrades.emplace("Janine Antinori", 98.2); // TODO: Read in new grade for a student, output initial // grade, replace with new grade in map, // output new grade }

Ticketing Service (queue)

Given main(), complete the program to add people to a queue. The program should read in a list of people's names including "You" (ending with -1), adding each person to the peopleInQueue queue. Then, remove each person from the queue until "You" is at the head of the queue. Include print statements as shown in the example below.

Ex. If the input is:

Zadie Smith Tom Sawyer You Louisa Alcott -1

the output is:

Welcome to the ticketing service... You are number 3 in the queue. Zadie Smith has purchased a ticket. You are now number 2 Tom Sawyer has purchased a ticket. You are now number 1 You can now purchase your ticket!

Use this as a template for your file, a1.3.cpp:

#include #include using namespace std; int main () { string personName = ""; int counter = 0; int youPosition; queue peopleInQueue; getline(cin, personName); while (personName != "-1") { // TODO: Add personName to peopleInQueue // determine position of "You" (youPosition) getline(cin, personName); } cout << "Welcome to the ticketing service... " << endl; cout << "You are number " << youPosition << " in the queue." << endl; // TODO: In a loop, remove head person from peopleInQueue, // output their name and that they have purchased a ticket, // then output your position in the queue. When you are at // the head, output that you can purchase your ticket. }

 Palindrome (deque)

A palindrome is a string that reads the same backwards and forwards. Use a deque to implement a program that tests whether a line of text is a palindrome. The program reads a line, then outputs whether the input is a palindrome or not.

Ex: If the input is:

senile felines!

the output is:

Yes, "senile felines!" is a palindrome.

Ex: If the input is:

rotostor

the output is:

No, "rotostor" is not a palindrome.

Ignore punctuation and spacing. Assume all alphabetic characters will be lowercase.

Use this as a template for your file, a1.4.cpp:

#include #include using namespace std; int main() { string line; bool result; /* Type your code here. */ }

Unique Random Integers (set)

Given integer inputs howMany and maxNum, generate a vector of howMany unique random integers from 0 to maxNum (exclusive).

The structure of the program is:

  • main() calls UniqueRandomInts() with arguments howMany, and maxNum.
  • UniqueRandomInts() returns a vector of howMany unique random integers.
  • The required output is already provided in main() and PrintNums().

Complete UniqueRandomInts(), which generates random integers until howMany unique integers have been collected in vector nums.

Hint: If a generated number is new, add the number to vector nums and set alreadySeen. If the number has been seen before, increment the global variable retries and generate another random integer.

Note: For testing purposes, the random number generator is seeded with a fixed value (641) in main().

Ex: When the input is:

5 8

the output is

5 4 0 1 6 [2 retries]

(Note that your output may not match, because your system may generate different random numbers.)

Use this as a template for your file, a1.5.cpp:

#include #include #include using namespace std; void PrintNums(vector nums, int size); vector UniqueRandomInts(unsigned int howMany, int maxNum, int& retries); int main() { int howMany; int maxNum; int retries; cin >> howMany; cin >> maxNum; vector uniqueInts; srand(641); // Seed random number generator for testing uniqueInts = UniqueRandomInts(howMany, maxNum, retries); PrintNums(uniqueInts, howMany); cout << " [" << retries << " retries]" << endl; } // Print the integers in vector nums separated by a space void PrintNums(vector nums, int size) { for (int i = 0; i < size; ++i) { cout << nums.at(i) << " "; } } // Generate howMany unique random integers 0 <= N < maxNum and return in nums vector UniqueRandomInts(unsigned int howMany, int maxNum, int& retries) { int nextRand; retries = 0; set alreadySeen; vector nums; /* Type your code here. */ }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!