C++ Your neighbor is an agent for a group of magicians. People call her to book
ID: 3715865 • Letter: C
Question
C++
Your neighbor is an agent for a group of magicians. People call her to book magicians for holidays. She would like to use her new computer to keep track of the jobs she schedules for the magicians she manages, so she hires you
The program must process the commands described below. You may determine the details of the user interface; it must be relatively "friendly" and usable.
BOOKINGS
Prompt the user for the name of the customer who wants to schedule a magician and for the name of the holiday to be scheduled. Check to see if there is a magician free for this holiday. You should sequence through the magicians in the order in which you read them in. If a magician is available, book the magician (add to bookings list and file); then print out the name of the magician, the holiday, and the name of the customer. If a magician is not available, print out a message indicating that the customer and holiday have been put on a waiting list.
CANCEL
Prompt the user for the customer name and holiday. Delete the booking of a magician for the listed holiday. Update the booking of the magician who was going to perform for the occasion. NOTE: I recommend rebuilding the bookings file whenever you cancel a booking. Open the file for output and rebuild it from the bookings linked list.
SIGNUP (new magician)
Prompt the user for the name of the new magician who is signing up with the agent. Append to the file containing the names and add to the Magician linked list.
STATUS
Prompt the user for the name of either a magician or holiday. Print out the appropriate schedule, appropriately formatted and labeled.
REPLACE
Prompt for enough information to find the booking in question and replace the current Magician with the next available Magician from the list. NOTE: I recommend rebuilding the bookings file whenever you replace a magician. Open the file for output and rebuild it from the bookings linked list.
QUIT
Explanation / Answer
Hello as per your requirement i have written overall code along with comments please follow it step by step
application.cpp
// Here we will declare header files
#include <iostream>
#include <fstream>
#include "adt1.h"
#include <string.h>
#include "linkedList.h"
using namespace std;
// The start of function protocols
int displaysMenuOptions();
bool full(bookingObject hol[], char* holidayElement, int magicianSize, int holidaySize);
void readInFiles(bookingObject magicians[], bookingObject holidayElements[], int&, int&);
void outputSchedule(char *, bookingObject magicians[], int magicianSize);
void readSchedule(char* filename, bookingObject magicians[], int& magicianSize, bookingObject holidayElements[], int& holiSize);
void stringcpy(char*, char*);
// The Start of Main program
int main()
{
//declare the needed variables
int responseStatus;
int checkStatus;
bool runProgramFlag = true;
char magicianName[20];
char customerName[20];
char holidayElementname[20];
bookingObject temp;
item tempItem;
char scheduleTXT[]="Schedule.txt";
char transactionElement[] ="transactionElementaction.txt";
char empty[] = "empty";
bookingObject magicians[10];
int magicianSize = 0;
bookingObject holidayElements[10];
int holidayElementSize = 0;
//here code for waiting list
linkedList list1;
char temporaryName[10][20];
int index = 0, ctr=0, holidayElementIndex = 0;
readInFiles(magicians, holidayElements, magicianSize, holidayElementSize);
readSchedule(scheduleTXT, magicians, magicianSize, holidayElements, holidayElementSize);
ofstream tout;
tout.clear();
tout.open(transactionElement);
//code for Main menu
do
{responseStatus = displaysMenuOptions();
switch( responseStatus )
{case 1:
cout << "Enter the name of the magician: " <<endl;
cin >> magicianName;
if(magicianSize + 1 <= 10){
// here code snippet to add a magician here
temp.setID(magicianName);
if(addbookingObject(magicians, temp, magicianSize)){
magicianSize++;
}
tout << magicianName << " added to magician bookingObject." << endl;
}
else{cout << "Magician bookingObjects full" << endl;}
break;
case 2: // schedule holidayElement, customer
cout << "Enter the name of the customer: " << endl;
cin >> customerName;
cout << "Enter the name of the holidayElement: " << endl;
cin >> holidayElementname;
if(!full(holidayElements, holidayElementname, magicianSize, holidayElementSize)){
holidayElementIndex = searchId(holidayElementname, holidayElements, holidayElementSize);
index = 0;
while(index<magicianSize){
stringcpy(temporaryName[index], magicians[index].id);
index++;
}
for(index = 0; index < magicianSize; index++){
//if there is no match end loop with magician name
if(!holidayElements[holidayElementIndex].searchSpecial(temporaryName[index])){
ctr = index;
index = magicianSize;}
}
stringcpy(tempItem.specialName, holidayElementname);
stringcpy(tempItem.customerName, customerName);
index = searchId(temporaryName[ctr],magicians, magicianSize);
holidayElementSize++;
magicians[index].insert(tempItem);
stringcpy(tempItem.specialName, temporaryName[ctr]);
holidayElements[holidayElementIndex].insert(tempItem);
tout << customerName << " was scheduled for " << holidayElementname << " with " << temporaryName[ctr] << '.' <<endl;}
else{list1.addRear( customerName, holidayElementname );
// here we will update transactionElementactions.txt
tout << customerName << " was added to the back of the waiting list." << endl;
}break;
case 3: // print status of scheduled event
cout << "Enter the name of the magician or holidayElement" << endl;
cin >> magicianName;
checkStatus = searchId(magicianName, magicians, magicianSize);
if(checkStatus != -1){
magicians[checkStatus].status();
// update transactionElementactions.txt
tout << "The status of " << magicianName << " was viewed." << endl;}
else{checkStatus = searchId(magicianName, holidayElements, holidayElementSize);
if(checkStatus != -1){
holidayElements[checkStatus].status();
// update transactionElementactions.txt
tout << "The status of " << magicianName << " was viewed." << endl;}
else{cout << "No magician or holidayElement with the name " << magicianName << " found." << endl;}
}break;
case 4: // cancel scheduled event
cout << "Enter the name of the holidayElement" << endl;
cin >> holidayElementname;
cout << "Enter the name of the customer" << endl;
cin >> customerName;
// move magician back to "available" status
checkStatus = searchId(holidayElementname, holidayElements, holidayElementSize);
if( checkStatus!= -1 ){
holidayElements[checkStatus].search(customerName);
holidayElements[checkStatus].getItem(tempItem);
holidayElements[checkStatus].deleteItem();
holidayElementSize--;
holidayElementIndex = checkStatus;
checkStatus = searchId(tempItem.specialName, magicians, magicianSize);
stringcpy(magicianName,magicians[checkStatus].id);
magicians[checkStatus].deleteItem();
magicianSize--;
// we will checkStatus wait list for first customer on that holidayElementname waiting list
list1.getFront( customerName, holidayElementname );
if( !compareString(customerName,empty) )
{
// if there is one, set new scheduled event
//holidayElement isn't full
if( !full( holidayElements, holidayElementname, magicianSize, holidayElementSize ) )
{stringcpy(tempItem.specialName, holidayElementname);
stringcpy(tempItem.customerName, customerName);
index = searchId(magicianName,magicians, magicianSize);
holidayElementSize++;
magicians[index].insert(tempItem);
stringcpy(tempItem.specialName, magicianName);
holidayElements[holidayElementIndex].insert(tempItem);
//code snippet for update transactionElementactions.txt
tout << customerName << " was scheduled for " << holidayElementname << " with " << magicianName << '.' <<endl;
}}
}else {cout << "Event not found" << endl;}
break;
case 5: // remove magician from roster
cout << "Enter the name of the magician: ";
cin >> magicianName;
checkStatus = searchId(magicianName, magicians, magicianSize);
if(checkStatus != -1){
temp = magicians[checkStatus];
//shuffle down the rest of the magicians
while(checkStatus < magicianSize - 1){
magicians[checkStatus] = magicians[checkStatus+1];
checkStatus++;}
//decrement magicianSize
magicianSize--;
temp.resetCursor();
while(temp.getLength() > 0){
//grab item
temp.getItem(tempItem);
stringcpy(tempItem.specialName, holidayElementname);
//checkStatus for possible replacement
//if not, add tempItem to front of the waiting list
//holidayElement isn't full
if(!full(holidayElements, holidayElementname, magicianSize, holidayElementSize)){
//initialize array of all possible magician names
holidayElementIndex = searchId(holidayElementname, holidayElements, holidayElementSize);
index = 0;
while(index<magicianSize){
stringcpy(temporaryName[index], magicians[index].id);
index++;
}
for(index = 0; index < magicianSize; index++){
//if there is no match end loop with magician name
if(!holidayElements[holidayElementIndex].searchSpecial(temporaryName[index])){
ctr = index;
index = magicianSize;
}}
stringcpy(tempItem.specialName, holidayElementname);
stringcpy(tempItem.customerName, customerName);
index = searchId(temporaryName[ctr],magicians, magicianSize);
holidayElementSize++;
magicians[index].insert(tempItem);
stringcpy(tempItem.specialName, temporaryName[ctr]);
holidayElements[holidayElementIndex].insert(tempItem);
//update transactionElementactions.txt
tout << customerName << " was scheduled for " << holidayElementname << " with " << temporaryName[ctr] << '.' <<endl;
}
//holidayElement is full
else{
// move customer to wait list if schedule full// update transactionElementactions.txt
tout << customerName << " was added to the back of the waiting list." << endl;}
//delete item from temp
temp.deleteItem();}
}else{cout << magicianName << " not found." << endl;}
break;
case 6:
if( responseStatus == 6 ){
//UPDATE Schedule.txt(using outputToFile for bookingObjects)
outputSchedule(scheduleTXT, magicians, magicianSize);
runProgramFlag = false;
tout.close();}
break;
default:
cout << "incorrect entry, try again..............." << endl << endl;
}
}
while( runProgramFlag == true );
return 0;
}
// Here where FUNCTION IMPLEMENTATION will done
int displaysMenuOptions()
{
int num;
cout << endl << endl << endl;
cout << " Welcome to the MAGICIAN SCHEDULER" << endl << endl << endl;
cout << "1. SIGN UP..........sign up here if you are a magician" << endl << endl;
cout << "2. SCHEDULE.........schedule a magician for your holidayElement event" << endl << endl;
cout << "3. STATUS...........checkStatus the status of your bookingObject" << endl << endl;
cout << "4. CANCEL...........cancel a previoiusly booked event" << endl << endl;
cout << "5. DROP OUT.........drop out here if you are a magician quitting the service" << endl << endl;
cout << "6. QUIT.............exit the magician scheduler" << endl << endl;
cout << endl << endl << endl;
cin >> num;
return num;
}
bool full(bookingObject hol[], char* holidayElement, int magicianSize, int holidaySize)
{
int hID = searchId(holidayElement, hol, holidaySize);
int i = hol[hID].getLength();
if(i > magicianSize){
return true;
}
else
return false;
}
void readInFiles(bookingObject magicians[], bookingObject holidayElements[], int& magicianSize, int& holiSize){
//variables
char magFile[] = "Magician.txt";
char holidayElementFile[] = "holidayElements.txt";
char name[20];
ifstream fin;
fin.clear();
fin.open(magFile);
if(fin.good()){
fin >> name;
while(fin.good() && magicianSize <= 10){
cout << name << endl;
magicians[magicianSize].setID(name);
magicianSize++;
fin >> name;
}
fin.close();
}
fin.clear();
fin.open(holidayElementFile);
if(fin.good()){
fin >> name;
while(fin.good() && holiSize <= 10){
holidayElements[holiSize].setID(name);
holiSize++;
fin >> name;
}
fin.close();
}
}
void readSchedule(char* filename, bookingObject magicians[], int& magicianSize, bookingObject holidayElements[], int& holiSize){
//initialize variables
int index = 0;
int place, size, i, size2;
int holidayElementPlace;
item temp;
char id[20];
bool continueAdd = true;
ifstream fin;
fin.clear();
fin.open(filename);
if(fin.good()){
//read in mag size
fin >> size;
while(index < size && size != 0){
//read in initial magician id
fin >> id;
//search for magician id in array
place = searchId(id, magicians, magicianSize);
if(place == -1){
//checkStatus if enough space to add magician
if(magicianSize+1 > 10){
cout << "TOO MANY MAGICIANS, Schedule.txt and Magician.txt excede limit" << endl;
continueAdd = false;
}
else{
place = magicianSize;
magicianSize++;
}
}
//We will ADDING THE MAGICIAN ITEMS
if(continueAdd){
//read in amount of items under magician
fin >> size2;
for(i = 0; i < size2; i++){
fin >> temp.specialName >> temp.customerName;
magicians[place].insert(temp);
//find holidayElement in holidayElement list
holidayElementPlace = searchId(temp.specialName, holidayElements, holiSize);
//checkStatus if found
if(holidayElementPlace == -1){
if(holiSize+1 > 10){
cout << "TOO MANY holidayElements, Schedule.txt and holidayElement.txt excede limit" << endl;
}
else{
holidayElementPlace = holiSize;
holiSize++;
}
}
//add info to holidayElement list
stringcpy(temp.specialName, id);
holidayElements[holidayElementPlace].insert(temp);
}
}
else{
//set continue to true for next iteration of loop
cout << "Reading in starter files aborted" << endl;
size = 0;
}
//increment loop
index++;
}
fin.close();
}
}
void outputSchedule(char* filename, bookingObject magicians[], int magicianSize){
int i;
ofstream fout;
fout.clear();
fout.open(filename);
fout.clear();
if(fout.good()){
//output number of magicians
fout << magicianSize << endl;
//output each magician
for(i = 0; i < magicianSize; i++){
magicians[i].outputToFile(fout);
}
//close file
fout.close();
}
}
void stringcpy(char* name, char* newname){
int i;
for (i = 0; newname[i] !='';i++){
name[i] = newname[i];
}
name[i] = '';
}
adt1.h
using namespace std;
//structs
struct item{
char customerName[20];
char specialName[20];
};
//classes
class bookingObject{
public:
bookingObject();
~bookingObject();
//inserts the item into bookingObject alphabetically by customer name
bool insert(item);
//gets item at cursor
bool getItem(item&);
//clears the bookingObject list setting rear and cursor to 0
void clear();
/*sets the cursor to the item with the matching customer name, if not sets cursor back to original location*/
bool search(char array[20]);
/*sets the cursor to the item with the matching special name, if not sets cursor back to original location*/
bool searchSpecial(char array[20]);
//checkStatuss if full
bool isFull();
//returns the amount of items in archive(rear+1)
int getLength();
//deletes item at cursor and shuffles everything appropriately
bool deleteItem();
//outputs archive to screen
void status();
//writes to filename the entire archive
bool outputToFile(ofstream&);
//overloaded operator =
void operator=(const bookingObject&);
//Sets the id(used when dealing with arrays of bookingObjects)
void setID(char* id);
//this variable is only used when calling an array of bookingObjects
char* id;
void resetCursor();
bool moveNext();
private:
//copies item to cursor
void copyItem(item);
item* archive;
int cursor;
int rear;
};
//Protoypes for arrays of bookingObjects
bool addbookingObject(bookingObject array[], bookingObject newList, int size);
int searchId(char*, bookingObject array[], int size);
/*checkStatuss to see if the newString is suppose to be sorted before the original string (alphabetically)*/
bool sortStringBefore(char* original, char* newString);
//checkStatuss to make sure strings are identical
bool compareString(char* original, char* rhs);
adt1.cpp
//INCLUDE FILES
#include <iostream>
#include <fstream>
#include "adt1.h"
//CONSTRUCTORS
bookingObject::bookingObject(){
archive = new item[10];
cursor = -1;
rear = -1;
id = new char[21];
id[0] = '';
}
bookingObject::~bookingObject(){
//automatic destruction
}
//PUBLIC FUNCTIONS
void bookingObject::resetCursor(){
if(cursor != -1){
cursor = 0;
}
}
bool bookingObject::moveNext(){
if(cursor+1 > rear){
return false;
}
cursor++;
return true;
}
bool bookingObject::insert(item temp){
//if inventory is empty
if( rear == -1){
//set cursor and rear to 0
cursor = 0;
rear = 0;
//copy item at cursor
copyItem(temp);
//return true
return true;
}
//if inventory is full
else if(isFull()){
return false;
}
//if inventory is neither empty nor full
else{
int start = 0;
while(start <= rear){
//if the item needs to be sorted before the current position
if(sortStringBefore(archive[start].customerName, temp.customerName)){
cursor = rear+1;
while(cursor > start){
//copy item at cursor
copyItem(archive[cursor-1]);
cursor--;
}
//after loop cursor is at start, copy temp at cursor
copyItem(temp);
rear++;
return true;
}
start++;
}
//insert item at the end of array
rear++;
cursor = rear;
copyItem(temp);
//return true
return true;
}
}
void bookingObject::clear(){
/*this function doesn't care about overwriting data so it sets rear and cursor to -1*/
cursor =-1;
rear = -1;
}
bool bookingObject::search(char array[20]){
int i = cursor;
//checkStatus if cursor is -1
if(cursor == -1){
//return false so user knows the search failed
return false;
}
//set cursor to 0
cursor = 0;
/*loop through array until A) customer name is found or B) cursor > rear*/
while(cursor <= rear){
if(compareString(archive[cursor].customerName, array)){
return true;
}
cursor++;
}
//cout << "NOT FOUND IN SEARCH" << endl;
cursor = i;
return false;
}
bool bookingObject::searchSpecial(char array[20]){
int i = cursor;
//checkStatus if cursor is -1
if(cursor == -1){
//return false so user knows the search failed
return false;
}
//set cursor to 0
cursor = 0;
/*loop through array until A) customer name is found or B) cursor > rear*/
while(cursor <= rear){
if(compareString(archive[cursor].specialName, array)){
return true;
}
cursor++;
}
//cout << "NOT FOUND IN SEARCH" << endl;
cursor = i;
return false;
}
bool bookingObject::getItem(item& temp){
//initialize i
int i=0;
//copy customer name
while(archive[cursor].customerName[i] != '' ){
temp.customerName[i] = archive[cursor].customerName[i];
i++;
}
if(i != 21){
//add magicianSize char
temp.customerName[i] = '';
}
//copy special name
i=0;
while(archive[cursor].specialName[i] != '' ){
temp.specialName[i] = archive[cursor].specialName[i];
i++;
}
if(i != 21){
//add magicianSize char
temp.specialName[i] = '';
}
}
bool bookingObject::isFull(){
if(rear == 9){
return true;
}
return false;
}
int bookingObject::getLength(){
return rear+1;
}
void bookingObject::status(){
if(rear >=0){
//initialize variables
int i = 0;
//output id name:
if(id != magicianSize && id[0] !=''){
cout << id << endl << "--------------------"<<endl<< endl;
}
//loop through all the items
while(i <= rear){
cout << archive[i].specialName << endl;
cout << archive[i].customerName<<endl;
cout << "--------------------"<<endl;
i++;
}
}
else{
if(id != magicianSize && id[0] !=''){
cout << id << endl << "--------------------"<<endl<< endl;
}
cout << "No events scheduled." << endl;
}
}
bool bookingObject::deleteItem(){
//declare temps
int i;
int cursorStart = cursor;
//checkStatus if empty
if(rear == -1){
//do nothing
return false;
}
//checkStatus if last in array
else if( cursor == rear){
rear --;
cursor --;
return true;
}
//else overwrite at cursor position and shuffle down
else{
rear--;
for(i=cursor+1;cursor <=rear;i++){
copyItem(archive[i]);
cursor++;
}
cursor = cursorStart;
return true;
}
}
bool bookingObject::outputToFile(ofstream& fout){
int index = 0;
if(fout.good()){
if(id != magicianSize && id[0] != ''){
fout << id << ' ' << getLength() << endl;
}
while(index <= rear){
fout << archive[index].specialName <<' '<<archive[index].customerName << endl;
index++;
}
return true;
}
else
return false;
}
void bookingObject::operator=(const bookingObject& rhs){
if(this != &rhs){
cursor = 0;
int i;
rear = rhs.rear;
for(i = 0; i <= rear; i++){
copyItem(rhs.archive[i]);
cursor++;
}
cursor = rhs.cursor;
}
else{
rear = -1;
cursor = -1;
}
}
//only used when using arrays of bookingObjects
void bookingObject::setID(char* newID){
{
//initialize function
int i = 0;
char* home;
home = id;
//run the loop copying each char over one by one
while(i < 20 && *newID != '')
{
*id = *newID;
newID++;
id++;
i++;
}
if(i == 20 && *newID!= ''){
*id = *newID;
}
*id = '';
id = home;
}
}
//PRIVATE
void bookingObject::copyItem(item temp){
int i = 0;
//add customer name
while(temp.customerName[i] != '' ){
archive[cursor].customerName[i] = temp.customerName[i];
i++;
}
archive[cursor].customerName[i] = '';
//add special name
i=0;
while(temp.specialName[i] != '' ){
archive[cursor].specialName[i] = temp.specialName[i];
i++;
}
archive[cursor].specialName[i] = '';
}
/*This is serves the purpose of adding a bookingObject into an array of bookingObjects and inserts it in
the correctly sorted position by alphabetical IDs.*/
bool addbookingObject(bookingObject array[], bookingObject newList, int size){
//Pre: THERE HAS TO BE ROOM IN THE ARRAY FOR THE NEWLIST
//initialize
if(size == 0){
array[0]=newList;
return true;
}
int i = 0;
while(!(sortStringBefore(array[i].id, newList.id)) && (i <= size)){
i++;
}
//checkStatus if to sort at the end of the array
if((!(sortStringBefore(array[i].id, newList.id))) && (i==size)){
array[size] = newList;
return true;
}
//sort and shuffle
else{
size++;
while(size > i +1){
array[size-1] = array[size-2];
size--;
}
array[i] = newList;
return true;
}
}
/*This functions searches for matching c style strings and returns the integer of where
in the array the bookingObject is.*/
int searchId(char* id, bookingObject array[], int size){
//pre: cannot be magicianSize and array cannot be empty.
int i;
for(i = 0; i < size; i++){
if(compareString(array[i].id, id)){
return i;
}
}
return -1;
}
//-------------------------
bool sortStringBefore(char* original, char* newString){
//Pre: both pointers cannot be magicianSize
//initialize variables
int i = 0;
//find point of no match
while((newString[i] == original[i]) && (newString[i] != '') && (original[i] != '')){
/*checkStatus if new string is smaller than original(this also will take care of the case if they are both the same string and just default to sorting the new one before the original*/
if(newString[i] == ''){
return true;
}
//Here we will checkStatus if original string is shorter than new string, sort after
if(original[i] == ''){
return false;
}
//increment index to point where the strings differ
i++;
}
//checkStatus and see if newString should be sorted before
if(newString[i] < original[i]){
return true;
}
//else return false
return false;
}
//--------------------------
bool compareString(char* original, char* rhs){
int i = 0;
while((rhs[i] == original[i]) && (rhs[i] != '') && (original[i] != '')){
i++;
}
if(rhs[i] == '' && original[i] == ''){
return true;
}
return false;
}
linkedList.h
// HEADER FILES
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
// NODE CLASS
class node
{
friend class linkedList;
private:
node();
node(const node&);
~node();
char* dataElement1;
char* dataElement2;
node* next;
};
// LINKEDLIST CLASS
class linkedList
{
public:
linkedList();
~linkedList();
void addFront( char*, char* );
void addRear( char*, char* );
void getFront( char*, char* );
void getRear( char*, char* );
void displayList();
private:
node* cursor;
node* head;
};
linkedList.cpp
// HEADER FILES
#include <iostream>
#include <fstream>
#include <string.h>
#include "linkedList.h"
using namespace std;
// constructor
node::node()
{
dataElement1 = new char[40];
dataElement2 = new char[40];
next = magicianSize;
}
// copy constructor
node::node(const node &rhs)
{
dataElement1 = rhs.dataElement1;
dataElement2 = rhs.dataElement2;
next = rhs.next;
}
// destructor
node::~node()
{
dataElement1 = magicianSize;
dataElement2 = magicianSize;
next = magicianSize;
}
// constructor
linkedList::linkedList()
{
head = magicianSize;
cursor = magicianSize;
}
// destructor
linkedList::~linkedList()
{
cursor = head;
while ( cursor != magicianSize )
{
node* temp = cursor;
cursor = cursor->next;
head = cursor;
delete temp;
}
}
// Here we will add name to rear of list
void linkedList::addRear( char* newDataElement1, char* newDataElement2 )
{
node* temp;
if( head == magicianSize )
{
head = cursor = new node;
}
else
{
cursor = head;
while( cursor->next != magicianSize )
{
cursor = cursor->next;
}
temp = new node;
cursor->next = temp;
cursor = cursor->next;
}
strcpy( cursor->dataElement1, newDataElement1 );
strcpy( cursor->dataElement2, newDataElement2 );
temp = magicianSize;
}
// And here we will add name to front of list
void linkedList::addFront( char* newDataElement1, char* newDataElement2 )
{
if( head == magicianSize )
{
head = cursor = new node;
}
else
{
cursor = new node;
cursor->next = head;
head = cursor;
}
strcpy( cursor->dataElement1, newDataElement1 );
strcpy( cursor->dataElement2, newDataElement2 );
}
// And here we will get name at front of list and remove
void linkedList::getFront( char* newDataElement1, char* newDataElement2 )
{
node* temp;
char empty[] = "empty";
if( head == magicianSize )
{
strcpy( newDataElement1, empty );
strcpy( newDataElement2, empty );
}
else{
strcpy( newDataElement1, head->dataElement1 );
strcpy( newDataElement2, head->dataElement2 );
temp = head;
head = head->next;
delete temp;
temp = magicianSize;
}
}
// Here we will get name at rear of list and remove
void linkedList::getRear( char* newDataElement1, char* newDataElement2 )
{
node* previousNodePtr;
char empty[] = "empty";
if( head == magicianSize )
{
strcpy( newDataElement1, empty );
strcpy( newDataElement2, empty );
}
else{
cursor = head;
while( cursor->next != magicianSize )
{
previousNodePtr = cursor;
cursor = cursor->next;
}
strcpy( newDataElement1, cursor->dataElement1 );
strcpy( newDataElement2, cursor->dataElement2 );
previousNodePtr->next = cursor->next;
delete cursor;
}
}
// Here we will display current list
void linkedList::displayList()
{
cursor = head;
while( cursor != magicianSize )
{
cout << cursor->dataElement1 << " " << cursor->dataElement2 << endl;
cursor = cursor->next;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.