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

Linked list class.h #include <iostream> using namespace std; // Node class class

ID: 3726706 • Letter: L

Question

Linked list class.h #include <iostream> 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 << "Inside destructor" << endl; 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();


}; #include <iostream> 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 << "Inside destructor" << endl; 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();


};
Linked list.cpp #include"LL.h"
//print list void List::Print() {
Node *temp = head; while (temp != NULL) { cout << temp->data << " "; temp = temp->next; } cout << endl; }
//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 //not the head { Node *prev = head; Node *temp = prev->next;
while (temp != NULL) { prev = temp; //order is very important temp = temp->next;

} //now 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 << "Can't find the value to delete. List didn't change." << endl; }
}

//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 << "previous is null, exiting" << endl; 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 << "Empty list, Not found" << endl; 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 << "Searching for non-existent node, exiting now....." << endl; return -1; }
//Return the node if it exists. Node* List::getNode(int d) { Node *temp = head; if (head == NULL) { cout << "Empty list, exiting"; return NULL; } else { while (temp != NULL&&temp->data != d) temp = temp->next; } if (temp == NULL) { cout << "Trying to get a node that does not exist. Exiting" << endl; return NULL; } else return temp; }

//find the max of a list int List::max() { Node *temp = head; if (head == NULL) { cout << "Empty list, exiting" << endl; exit(1); }
else { int m = temp->data; temp = temp->next; while (temp != NULL) { if (m < temp->data) m = temp->data; temp = temp->next; }
return m; } }
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- (10 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. class that stores a person name, address (use (5 pts) Write a ticketorder 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. a- b- (1o pts) Your class should provide input function (do not overload the operator >> here), output (overload the operator

Explanation / Answer

part 1 of your program : -------------->>>>>>>>

#include<iostream>

using namespace std;

class Address{
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 setStreetNumber(int num){
   street_number = num;
  }
  void setCity(string c){
   city = c;
  }
  void setZipCode(string zp){
   zip_code = zp;
  }
  string getZipCode()const{
   return zip_code;
  }
  string getStreetName()const{
   return street_name;
  }
  string getCity()const{
   return city;
  }
  int getStreetNumber()const{
   return street_number;
  }
  void print(){
   cout<<" Address = "<<street_name<<" "<<street_number<<" City = "<<city;
   cout<<" Zip-Code = "<<zip_code;
  }
  bool operator==(const 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<<(ostream &out,const Address &oth){
   out<<" Address = "<<oth.getStreetNumber()<<" "<<oth.getStreetNumber()<<" City = "<<oth.getCity();
   out<<" Zip-Code = "<<oth.getZipCode();
   
   return out;
  }
  friend istream& operator>>(istream &in,Address &oth){
   string c,sn,zp;
   int sc;
   cout<<" Enter city : ";
   in>>c;
   cout<<" Enter Street name : ";
   in>>sn;
   cout<<" Enter Street Number : ";
   in>>sc;
   cout<<" Enter Zip Code : ";
   in>>zp;
   oth.setCity(c);
   oth.setStreetName(sn);
   oth.setStreetNumber(sc);
   oth.setZipCode(zp);
   return in;
  }
};

class TicketOrder{
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()const{
   return name;
  }
  Address getAddress()const{
   return adr;
  }
  int getNumberOfTicket()const{
   return number_of_ticket;
  }
  
  void print(){
   cout<<" Name = "<<name;
   cout<<adr;
   cout<<" Number Of Ticket = "<<number_of_ticket;
  }
  
  friend ostream& operator<<(ostream& out,const TicketOrder &oth){
   out<<" Name = "<<oth.getName();
   out<<oth.getAddress();
   out<<" Number Of Ticket = "<<oth.getNumberOfTicket();
   
   return out;
  }
  
  void takeInput(){
   cout<<" Enter Name : ";
   cin>>name;
   cin>>adr;
   cout<<" Enter Number Of Ticket : ";
   cin>>number_of_ticket;
  }
  
  bool operator==(const TicketOrder &oth){
   if(name == oth.name && adr == oth.adr){
    return true;
   }
   
   return false;
  }
};

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