CS 215 Program Design, Abstraction, and Problem Solving Programming Project #3
INTRODUCTION The goal of this programming project is to enable the student to practice designing a program that solves a problem using a class and a linked-list and developing a C++ program to implement the solution.
PROJECT TASKS
1. Read the problem definition below and then analyze it before designing a solution. You will produce a document (external documentation) of this definition, analysis, and design.
2. Write a C++ program that implements your solution. The program must match your design. Readability of the program will be graded based on variable naming, indentation, commenting (not too little and not too much), and styling including how the class and linked list are implemented.
3. Test your program on grace.bluegrass.kctcs.edu and you will provide proof of compiling and running the program on this platform.
PROBLEM Introduction
Write a program that simulates a customer service line at an Apple store. The line is a linked-list of pointers. Customers arrive at time specified by month/day/year plus hour/minute. The customers are served on a first come first serve basis. Here is the rest of the specification. Your solution Write a C++ program that has the following and does the following: Write a struct that will represent the template of a node in the linked list.
The members of the struct should be:
a) sequence number: type unsigned int
b) name: type string
c) month: integer
d) day: integer
e) year: integer
f) hour: integer
g) minute: integer
h) service_required: type string
i) next: pointer to a node Write a class whose data members are a head pointer to a node and a pointer to the last node.
DO NOT USE C++11 STL containers such as list, queue, stack.
The head will represent the start of a linked list. The member functions are specified below (define functions outside class).
(a) Constuctor: set the pointers to null
(b) InsertNode: When a customer has just arrived, allocate memory for a new node (using the struct) and assign details received in parameters to the new node. The first node will be given sequence number 1, and subsequent nodes will have sequence numbers in increments of 1. Make the new node the new head.
(c) DeleteNode: A customer may leave before being served. This method should receive the name of the customer as a parameter and call the SearchNode function to find the node of the customer. Delete the node by putting its next pointer into the previous node next pointer.
(d) SearchNode: This function receives the customer name and current node as parameters. Recursively process the list to find the customer. Return the pointer to the current node when found or null when end of list is reached.
(e) ServeCustomer: get the customer at the tail-end of the list and assign null to the previous next pointer. Display a message saying the customer has been served. Return the pointer to the tail customer.
(f) ListAll: recursively go through the linked list from beginning to end displaying line: N Customer-name MM/DD/YYYY HH:MM XXXXXXX where N is the sequence number, Customer-name is the name of the customer, MM/DD/YYY is the date from the date members of the clas, HH:MM is the time from the time data members, and XXXXXX is the purpose of the visit from the service_required data member. Return the number of nodes in the linked list.
(g) Destructor: Recursively delete the nodes.
The main() function: Write a main function that instantiates an object using the linked list class. The main function should have a do … while … loop that runs until quit is selected and offers the user the following menu:
1) New customer arrival
2) Serve customer
3) Customer left – remove from waiting list
4) List all customers waiting for service
5) Quit Next in the loop, an option made by the user should be input.
Depending on the option selected by the user, one of the operations listed in the bulleted list below should be performed. You may use a switch statement to handle this selection
. New customer arrival: input the name, date, and time. The member function of the class that inserts a node is then called passing the name, date, and time as arguments.
Serve customer: when this option is selected, call the ServeCustomer member function of the class.
Customer left: when this option is selected, input the name of the customer who left. This should be passed to the DeleteNode function of the class and the node should be deleted when found. The function should return the status of the delete. If the customer was found, display a message stating that the customer was not served and is removed otherwise state that the customer was probably already served anyway.
List all: First display the following table headings:
APPLE CUSTOMER SERVICE WAITING LIST SEQUENCE NAME ARRIVAL DATE/TIME PURPOSE OF VISIT
Next, call the ListAll member function of the object putting it on the right of an assignment to an integer to receive the returned number of nodes in the list. Display a message: There are NN customers waiting to be served. Where NN is an integer. ABOUT EXTERNAL DOCUMENTATION Submit the external documentation in Word or PDF. The structure of your document is four clear sections each with a subheading as follows: 1. PROBLEM DEFINITION This is a summary of the PROBLEM section above. Do not copy the text that I have written. Rather, phrase the problem in a few English sentences. 2. ANALYSIS Give the record structures and classes. This may include a class diagram. Explain your data design and the advantages. I chose the struct and the class for you but defend the use of a class versus not using a class and a linked list versus using an array. 3. DESIGN Give the algorithm in pseudocode form of the step by step statements to carry out the required programming task in structured English phrases for your main() function only. Remember that pseudocode should not be in C++ or any programming language. Pseudocode should not be in essay form. Rather, it should be short phrases with indentation with a bias towards what the final program will look like. 4. IMPLEMENTATION Write a description of your implementation. Implementation details include the platform and programming environment used. (Note that platform means CPU/Operating System combo. Example of a platform is Dell Computer with Intel 8-Core 2.8GHz processor running Windows 10.) Give the name of the development environment that you used such as Visual Studio or GNU pico/g++. How did you test your program? Did you encounter any unusual situations when running the program? Example of unusual encounters include the program crashing when a letter is entered where a number is required. SUBMISSION a) Upload to Blackboard a copy of your external documentation in Word or PDF. b) Upload to Blackboard a copy of your source program (the one with a .cpp extension). c) A text file containing the record of the program run session. May use script to record MAXIMUM POSSIBLE SCORE This program will be graded out of 75 points distributed as follows: ITEM MAX. POINTS External documentation . . . . . . . . . . . . . . . . . . . . . 20 Style: comments, meaningful names, . . . . . . . . . . 10 indentation, and readability in general Program written to specification . . . . . . . . . . . . . . 20 Program works correctly . . . . . . . . . . . . . . . . . . . . 25
#include<bits/stdc++.h>
using namespace std;
struct customer{
unsigned int sequence_number;
int
month,day,year,hour,minute;
string name,service_required;
struct customer *next;
};
class task{
public:
struct customer *head,*last;
task()
{
head=last=NULL;
}
~task()
{
struct customer
*start,*temp;
start=temp=head;
while(start!=NULL)
{
temp=start;
start=start->next;
free(temp);
}
}
void insert_node(string name,int
day,int month,int year,int hour,int minute)
{ static int
counter=0;
struct customer
*node=NULL;
node = new
struct customer();
node->name=name;
node->day=day;
node->month=month;
node->year=year;
node->hour=hour;
node->minute=minute;
node->sequence_number=counter++;
if(head==NULL
&& last==NULL)
{
head=last=node;
node->next=NULL;
}
else
{
node->next=head;
head=node;
}
}
int delete_node(string name)
{
struct customer
*deleted,*start=head;
deleted=search(name,head);
if(deleted==NULL)
{
return 1;
}
else
{//
cout<<deleted->name<<endl;
if(deleted!=head)
{
while(start->next!=deleted)
{
start=start->next;
}
start->next=deleted->next;
free(deleted);
}
else
{
head=deleted->next;
free(deleted);
}
return 0;
}
}
struct customer * search(string
name,struct customer *start)
{
if(start==NULL)
return
NULL;
else
{
if(name.compare(start->name)==0)
{
return start;
}
else
{
return
search(name,start->next);
}
}
}
struct customer *
serve_customer()
{
struct customer
*start;
start=head;
while(start->next != last)
{
start=start->next;
}
free(start->next);
start->next =
NULL;
return
start;
}
void list_all(struct customer
*start)
{
if(start==NULL)
return ;
list_all(start->next);
cout<<start->sequence_number<<"
"<<start->name<<"
"<<start->day<<"//"<<start->month<<"
"<<start->year<<"//"<<start->hour<<"::"<<start->minute<<endl;
}
};
int main()
{
int choice,temp;
unsigned int sequence_number;
int
month,day,year,hour,minute;
string name,service_required;
task object1;
while(1)
{
cout<<endl;
cout<<"Enter the choice\n";
cout<<"1)
New customer arrival \n2) Serve Customer\n3) Customer left remove
from waiting list\n4) List all customers waiting for service\n5) To
exit";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter
name\n";
cin>>name;
cout<<"Enter date as
day,month,year\n";
cin>>day>>month>>year;
cout<<"Enter time as
hour and minute\n";
cin>>hour>>minute;
object1.insert_node(name,day,month,year,hour,minute);
break;
case 2:
object1.serve_customer();
break;
case 3:
cout<<"enter the name
of customer\n";
cin>>name;
temp=object1.delete_node(name);
(temp==1)?cout<<"Already Served":cout<<"Deleted";
break;
case 4:
object1.list_all(object1.head);
break;
case 5:
return 0;
break;
}
}
}
CS 215 Program Design, Abstraction, and Problem Solving Programming Project #3 INTRODUCTION The goal of this...
This is a c programming problem.
Would you please help me to write this problem???
I really appreciate it if you add comments for explanation step
by step.
Thank you.
Reverse a Doubly linked list using recursion: Given a doubly linked list. Reverse it using recursion. Original Doubly linked list: next pointer - DDHIHI Null prev painter Reversed Doubly linked list: next pointer Start Pointer Null prev pointer Include: a) A struct for a node of the doubly linked list....
You are given a pointer to a singly linked list. The singly linked list has cycles due to a programming error. Write a C program to detect whether the linked list has cycles without storing all the pointers to the nodes. The function detect_cycles should return 1 when a cycle is found and 0 when there are no cycles. Your code should handle all corner cases carefully and should not cause segmentation fault. Figure shows various examples of cycles for...
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
C++ program, item.cpp implementation.
Implementation: You are supposed to write three classes, called Item, Node and Inventory respectively Item is a plain data class with item id, name, price and quantity information accompanied by getters and setters Node is a plain linked list node class with Item pointer and next pointer (with getters/setters) Inventory is an inventory database class that provides basic linked list operations, delete load from file / formatted print functionalities. The majority of implementation will be done...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
C++ Compsci 165: For your twelfth programming assignment you will be implementing a program that uses a linked list.You will be implementing the following structure and functions: struct LinkedList { int value; LinkedList *next; }; Note that with a singly linked list, you need to maintain a head pointer (pointer to the beginning of the list). Typically a tail pointer (pointer to the end of the list) is not maintained in a singly linked list (because you can only iterate...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
I need this in C++. This is all
one question
Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...
you’ll write a program to illustrate how Linked list and structure are used in practice, we’ll develop a program that maintains a database of information about parts stored in a warehouse. The program is built around the database stored in linked list and structures, with each structure containing information - part number, name, and quantity – about one part. • The program tracks parts stored in a warehouse. • Contents of each structure: – Part number – Name – Quantity...