Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction In this assignment you will write a program to maintain a waiting l

ID: 3748414 • Letter: I

Question

Introduction

In this assignment you will write a program to maintain a waiting list of appointments.

The list is not maintained entirely on a "first come, first served" basis. If a monetary incentive (i.e. bribe) is received, the person goes ahead of all other persons who either had not "contributed" or had given a smaller "contribution." However, if the bribe equaled that previously given by another person, the person who first gave the bribe would be higher on the list.

You will be given the driver program to maintain the waiting list. The application displayed a menu which permits the user three choices: (1) add a student to the waiting list (by name and amount of the "contribution"; (2) view a list of the students, by name and amount of contribution, in the order stated above; or (3) exit the program. See sample output.

NOTE: You do not need to do any error checking to determine if the user typed in a legal menu choice (1, 2 or 3), a name, or a positive whole number for a bribe.

Files

The class will be written using header and implementation files. Your program also will include a driver file, so your multi-file project will have these three files and no others:

Your Job

The code/output handout already provides all the code for the test.cpp file, and that code should not be changed. Your tasks are:

1. Complete the the personlist.h file. The code/output handout provides all the code for this file except for any private member functions you decide to add. However, you cannot add any additional member variables or public member functions than those already provided in the code/output handout.

2. Write the personlist.cpp file.

CODE/OUTPUT HANDOUT

This handout provides (1) all the code for the personlist.h file except for any private member functions you decide to add, (2) the test.cpp file and (3) sample output. As explained in the assignment, your job is to complete the personlist.h file with any private member functions you decide to add and to write the personlist.cpp file.

1. personlist.h

#ifndef PERSON_H
#define PERSON_H

struct PersonRec;

class PersonList {

public:
PersonList();
~PersonList();
void ViewList();
void AddToList ();

private:
PersonRec* head;
/*

insert here other private member functions as you

see the need for them. However, you cannot add

any additional member variables or public

member functions than the four listed above

*/
};
#endif

2. test.cpp

#include "personlist.h"
#include <iostream>

using namespace std;

int displayMenu (void);
void processChoice(int, PersonList&);

int main ( )
{
int num;

PersonList myList;
do
{
num = displayMenu();
if (num != 3)
processChoice(num, myList);
} while (num != 3);

return 0;
}

int displayMenu (void)
{
int choice;
cout << " Menu ";
cout << "============================== ";
cout << "1. Add student to waiting list ";
cout << "2. View waiting list ";
cout << "3. Exit program ";
cout << "Please enter choice: ";
cin >> choice;

cin.ignore();
return choice;
}

void processChoice(int choice, PersonList& p)
{
switch (choice)
{
case 1: p.AddToList();
break;
case 2: p.ViewList();
break;
}
}

3. Sample Output


Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 2

List is empty

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 1
Enter the person's name: Terry Two
Enter the person's contribution: 2

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 2

# Name Contribution
=======================================

1 Terry Two $2

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 1
Enter the person's name: Oswald One
Enter the person's contribution: 1

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 2

# Name Contribution
=======================================

1 Terry Two $2
2 Oswald One $1

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 1
Enter the person's name: Fred Four
Enter the person's contribution: 4

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 2

# Name Contribution
=======================================

1 Fred Four $4
2 Terry Two $2
3 Oswald One $1

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 1
Enter the person's name: Too Late
Enter the person's contribution: 2

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 2

# Name Contribution
=======================================

1 Fred Four $4
2 Terry Two $2
3 Too Late $2
4 Oswald One $1

Menu
==============================

1. Add student to waiting list
2. View waiting list
3. Exit program

Please enter choice: 3
Press any key to continue

File Name Purpose personlist.h Declaration file for PersonList class personlist.cpp Implementation file for PersonList class test.cpp Driver file

Explanation / Answer

//personlist.h

#pragma once

#include<string>

#include<iostream>

using namespace std;

#ifndef PERSON_H

#define PERSON_H

struct PersonRec

{

string name;

double amount;

PersonRec *next;

};

class PersonList {

public:

PersonList();

~PersonList();

void ViewList();

void AddToList();

private:

PersonRec * head;

/*

insert here other private member functions as you

see the need for them. However, you cannot add

any additional member variables or public

member functions than the four listed above

*/

void input();

void output();

};

#endif

--------------------------------------------

//personlist.cpp

#include"personlist.h"

//ionimap for formatted output

#include<iomanip>

PersonList::PersonList()

{

head = NULL;

}

PersonList::~PersonList()

{

PersonRec *cur = head,*tmp;

while (cur != NULL)

{

tmp = cur->next;

delete cur;

cur = tmp;

}

}

void PersonList::ViewList()

{

output();

}

void PersonList::AddToList()

{

input();

}

void PersonList::input()

{

string str;

double amt;

cout << "Enter the person's name: ";

getline(cin, str);

cout << "Enter the person's contribution: ";

cin >> amt;

//create new node

PersonRec *newNode, *cur = head;

newNode = new PersonRec;

newNode->name = str;

newNode->amount = amt;

newNode->next = NULL;

if (head == NULL || head->amount <=amt)

{

newNode->next = head;

head = newNode;

return;

}

else

{

while (cur->next != NULL && cur->next->amount >amt)

{

cur = cur->next;

}

newNode->next = cur->next;

cur->next = newNode;

}

}

void PersonList::output()

{

PersonRec *cur = head;

int count = 1;

if (cur == NULL)

{

cout << "List is empty ";

return;

}

cout << setw(20) << setw(10) << endl;

cout << "# Name Contribution ";

cout << "======================================= ";

while (cur != NULL)

{

cout << count++ << " "<<cur->name << " $" << cur->amount << endl;

cur = cur->next;

}

}

-------------------------------------------------

//test.cpp

#include "personlist.h"

#include <iostream>

using namespace std;

int displayMenu(void);

void processChoice(int, PersonList&);

int main()

{

int num;

PersonList myList;

do

{

num = displayMenu();

if (num != 3)

processChoice(num, myList);

} while (num != 3);

return 0;

}

int displayMenu(void)

{

int choice;

cout << " Menu ";

cout << "============================== ";

cout << "1. Add student to waiting list ";

cout << "2. View waiting list ";

cout << "3. Exit program ";

cout << "Please enter choice: ";

cin >> choice;

cin.ignore();

return choice;

}

void processChoice(int choice, PersonList& p)

{

switch (choice)

{

case 1: p.AddToList();

break;

case 2: p.ViewList();

break;

}

}

/*output

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 2

List is empty

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 1

Enter the person's name: Terry Two

Enter the person's contribution: 2

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 1

Enter the person's name: Oswald One

Enter the person's contribution: 1

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 2

# Name Contribution

=======================================

1 Terry Two $2

2 Oswald One $1

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 1

Enter the person's name: Fred Four

Enter the person's contribution: 4

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 2

# Name Contribution

=======================================

1 Fred Four $4

2 Terry Two $2

3 Oswald One $1

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 1

Enter the person's name: Too Late

Enter the person's contribution: 2

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 2

# Name Contribution

=======================================

1 Fred Four $4

2 Too Late $2

3 Terry Two $2

4 Oswald One $1

Menu

==============================

1. Add student to waiting list

2. View waiting list

3. Exit program

Please enter choice: 3

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote