Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here are the linked list code LL.h #include using namespace std; // Node class class Node { public: int data; Node* next; Node() { next

image text in transcribed
image text in transcribed
Here are the linked list code
LL.h
#include
using namespace std;
// Node class
class Node {
public:
int data;
Node* next;
Node() { next = NULL; }
Node(int u) { data = u; }
void SetData(int aData) { data = aData; }
void SetNext(Node* aNext) { next = aNext; }
int getData() { return data; }
Node* getNext() { return next; }
};
// List class
class List {
public:
Node *head;
List() { head = NULL; }
~List() {
//cout
deletehead();
}
//get head
Node* getHead() { return head; }
void deletehead() {
head = NULL;
}
//get specific node
Node* getNode(int d);
void Print();
void Append(int data); //add at the end of the list
void Delete(int data); //delete a specific node
bool isempty();
void insert(Node *, int n); //insert node after prev, with data d
int search(Node *);
int max();
};
LL.cpp
include"LL.h"
//print list
void List::Print() {
Node *temp = head;
while (temp != NULL)
{
cout data
temp = temp->next;
}
cout
}
//append at the end of the list
void List::Append(int d) {
Node *nnode = new Node();
nnode->data = d;
nnode->next = NULL;
//if this is the head
if (head == NULL) {
head = nnode;
}
else /ot the head
{
Node *prev = head;
Node *temp = prev->next;
while (temp != NULL)
{
prev = temp; //order is very important
temp = temp->next;
}
/ow insert node
prev->next = nnode;
}
}
//delete data d(first d found will be deleted)
void List::Delete(int d) {
Node *prev = head;
Node *temp = prev->next;
//if the deleted node is the head
if (prev->data == d) {
delete head;
head = temp;
}
else
{
while ((temp != NULL) && (temp->data != d)) {
prev = temp;
temp = temp->next;
}
if (temp != NULL)
{ //make sure the node was found
prev->next = temp->next;
delete temp;
}
else
cout
}
}
//test if list is empty
bool List::isempty() {
if (head == NULL) return true;
else return false;
}
//insert after prev, data d
void List::insert(Node *prev, int d) {
Node *temp = head;
Node *ne = new Node;
ne->data = d;
if (temp == NULL) {
cout
exit(1);
}
else
while (temp->data != prev->data) {
temp = temp->next;
}
temp = temp->next;
ne->next = temp;
prev->next = ne;
}
//Search for a node and return the position where it was found
//or -1 if it wasn't found
int List::search(Node *n)
{
Node *temp = head;
int i = 0;
if (n != NULL) {
if (isempty()) {
cout
return -1;
}
else
{
while (temp != NULL) {
if (temp->data == n->data)
return i;
temp = temp->next;
i = i + 1;
}
}
if (temp == NULL)
return -1;
else
return i;
}
else
cout
return -1;
}
//Return the node if it exists.
Node* List::getNode(int d) {
Node *temp = head;
if (head == NULL) {
cout
}
else
{
while (temp != NULL&&temp->data != d)
temp = temp->next;
}
if (temp == NULL) {
cout
}
else
return temp;
}
//find the max of a list
int List::max() {
Node *temp = head;
if (head == NULL) {
cout
}
else
{
int m = temp->data;
temp = temp->next;
while (temp != NULL) {
if (m data)
m = temp->data;
temp = temp->next;
}
return m;
}
}
I have finished the part1, you need to do the part 2 and 3.
Address.h
#pragma once
#include
#include
using namespace std;
class Address {
private:
string street_name;
int street_number;
string city;
string zip_code;
public:
Address() {
street_name = "";
street_number = 0;
city = "";
zip_code = "";
}
Address(string sn, string c, string zp,int snum) {
street_name = sn;
city = c;
zip_code = zp;
street_number = snum;
}
void setstreetname(string sn) {
street_name = sn;
}
void setcity(string c) {
city = c;
}
void setzipcode(string zp) {
zip_code = zp;
}
void setstreetnumber(int num) {
street_number = num;
}
string getzipcode() {
return zip_code;
}
string getstreetname(){
return street_name;
}
string getcity() {
return city;
}
int getstreetnumber() {
return street_number;
}
void print() {
cout
cout
}
bool operator==(Address &other) {
if (other.street_name == street_name && other.street_number == street_number) {
if (other.city == city && other.zip_code == zip_code) {
return true;
}
return false;
}
return false;
}
friend ostream& operator
out
out
return out;
}
friend istream& operator>>(istream &in, Address &oth) {
string c, sn, zp;
int sc;
cout
in >> c;
cout
in >> sn;
cout
in >> sc;
cout
in >> zp;
oth.setcity(c);
oth.setstreetname(sn);
oth.setstreetnumber(sc);
oth.setzipcode(zp);
return in;
}
};
TicketOrder.h
#pragma once
#include
#include
#include"Address.h"
using namespace std;
int numTickets = 0;
class TicketOrder {
private:
string name;
Address adr;
int number_of_ticket;
public:
TicketOrder() {
adr = Address();
name = "";
number_of_ticket = 0;
}
TicketOrder(string n, Address ad, int num) {
adr = ad;
name = n;
number_of_ticket = num;
}
void setAddress(Address ad) {
adr = ad;
}
void setName(string n) {
name = n;
}
void setNumberOfTicket(int num) {
number_of_ticket = num;
}
string getName() {
return name;
}
Address getAddress() {
return adr;
}
int getNumberOfTicket() {
return number_of_ticket;
}
void print() {
cout
cout
cout
}
friend ostream& operator
out
out
out
return out;
}
friend istream& operator>>(istream &In, TicketOrder &Odr)
{
cout
In >> Odr.name;
In >> Odr.adr;
do
{
cout
In >> Odr.number_of_ticket;
} while ((Odr.number_of_ticket 4));
if (Odr.number_of_ticket + numTickets > 100)
{
cout
}
numTickets += Odr.number_of_ticket;
return In;
}
bool operator==(TicketOrder &oth) {
if (name == oth.name && adr == oth.adr) {
return true;
}
return false;
}
};
Test.cpp
#include
#include
#include"Address.h"
#include"TicketOrder.h"
using namespace std;
int main()
{
cout
cout
TicketOrder tOrder1;
cout
cin >> tOrder1;
TicketOrder tOrder2;
cout
cin >> tOrder2;
TicketOrder tOrder3;
cout
cin >> tOrder3;
int numTickets;
numTickets = tOrder1.getNumberOfTicket() + tOrder2.getNumberOfTicket() + tOrder3.getNumberOfTicket();
cout
cout
cout
cout
cout
cout
cout
cout
if (tOrder1 == tOrder2)
{
cout
}
else
{
cout
}
if (tOrder1.getAddress() == tOrder3.getAddress())
{
cout
}
else
{
cout
}
return 0;
}
PS. To count the object don't use iterator use the static.
PROBLEMS: Part 1: Design a- (5 pts) Create an Address class that contains the name and number of street, city, and zip code. Write all constructors, getters, setters and a Print functions for it b- (1o pts) Your class should provide input (overload the operator >>), output (operator >prototype is similar to that of > (istream& os, Address& a) (inside the function ask the user to enter the info, using cin or getline). The operator > should ask the user to enter a complete address and return a reference to it. The rock group "Marron 5" is giving a concert in your town and you have been hired by the night club where they are playing. The club seats 100 people, and tickets will be sold in advance. Ticket requests are to be filled in the order in which they are received, with a maximum of four tickets per person a- (5 pts) Write a ticketOrder class that stores a person name, address (use your class address that you created in part a), and number of tickets in a ticket order. Write all constructors, getters, setters and a Print functions for it. b- (10 pts) Your class should provide input function (do not overload the operator >> here), output (overload the operator > you created in class Address to enter an address

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

What is American Polity and Governance ?

Answered: 1 week ago