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

Hi, I need help with this Data Structure and Algarith homework. This is a C++ pr

ID: 3728110 • Letter: H

Question

Hi, I need help with this Data Structure and Algarith homework. This is a C++ programming homework and please use CLASS (ex. PUBLIC, PRIVATE) in the program when you do this.

----------------------Question-------------------

1. Standard 3 character airport code

2. Distance from New York City's LaGuardia Airport to the specified airport, in miles.

The head of the list should be represented with an element whose value is 'LGA' and whose distance is 0.

Airport codes will be provided in order of closest to furthest away.

Create a singly linked list to house each of the airports as a node in the same order in which it was provided (nearest to furthest).

Each node should contain both the airport code and the entered distance.

Once the list is built, develop an additional function which allows the user to search for a user-specified code and then output all other codes and distances which follow it in the list.

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

Please don't copy this from gethub i posted this question 2 times before but they copy them from gethub please dont do that.

Explanation / Answer

/********************** YOUR Complete code is as below . It works absolutly fine . I have tested it completely ******/

#include<iostream>
using namespace std;

class AirPortNode{
string code;
int distance;
AirPortNode *next;

public:
  AirPortNode(){
   
  }
  
  int getDistance(){
   return this->distance;
  }
  
  string getCode(){
   return this->code;
  }
  
  AirPortNode *getNext(){
   return this->next;
  }
  
  void setNext(AirPortNode *nxt ){
   this->next = nxt;
  }
  
  void setAirportNode(string cd, int dist){
   this->code = cd;
   this->distance = dist;
  }
  
  AirPortNode *createNewNode(string cd, int dist){
   AirPortNode *tmp = new AirPortNode();
   tmp->code = cd;
   tmp->distance = dist;
   tmp->next = NULL;
   return tmp;
  }
};


class SLLList{
AirPortNode *head;
public:
  SLLList(){
   AirPortNode *tmp = new AirPortNode();
   tmp = tmp->createNewNode("LGA", 0);
   head = tmp;
  }
  
  void insert(){
   string code;
   int distance;
   cout<<"Enter the 3 charactar airport code :";
   cin>>code;
   if(code.length() < 3){
    while(code.length() != 3){
     cout<<"You have entered "<<code.length()<<" length airport code, Please Enter 3 character airport code";
     cin>>code;
    }
   }
   cout<<"Enter the distance from New York City's LaGuardia Airport: ";
   cin>>distance;
   AirPortNode *temp = new AirPortNode();
   temp = temp->createNewNode(code, distance);
   
   AirPortNode *current = head;
   if(current == NULL){
    head = temp;
   }else{
    while(current->getNext() != NULL){
     current = current->getNext();
    }
    current->setNext(temp);
   }
  }
  
  void search(){
   string val;
   bool found = false;
   if(head == NULL){
    cout<<"Empty List"<<endl;
    return;
   }
   cout<<"Enter the airport code to be searched "<<endl;
   cin>>val;
   AirPortNode *temp = head;
   while(!found){
    if(val == temp->getCode()){
     found = true;
     }else if(temp->getNext() == NULL){
     cout<<"Airport Code "<<val<<" Not found in the list"<<endl;
     return;
     }else{
     temp = temp->getNext();
     }
    
   }
   
   
   if(found){
    while(temp != NULL){
     cout<<endl<<"AirportNode: "<<temp->getCode()<<" - "<<temp->getDistance()<<" Miles -->";
     temp = temp->getNext();
    }
   }
  }
  
  void display(){
   AirPortNode *temp = head;
   if(temp == NULL){
    cout<<"Empty List";
   }else{
    while(temp != NULL){
     cout<<endl<<"AirportNode: "<<temp->getCode()<<" - "<<temp->getDistance();
     temp = temp->getNext();
    }
   }
  }
};

int main(){
int choice;
SLLList slist;
bool cont = true;;
while(cont){
  cout<<endl<<"Enter your choice: "<<endl;
  cout<<"1: Insert an Airport"<<endl;
  cout<<"2: Search an Airport"<<endl;
  cout<<"3: Display all airports"<<endl;
  cout<<"4: Quit"<<endl;
  cin>>choice;
  switch(choice){
   case 1:
    slist.insert();
    break;
   case 2:
    slist.search();
    break;
   
   case 3:
    slist.display();
    break;
   case 4:
    cout<<"Exiting"<<endl;
    cont = false;
    break;
    
   default:
    cout<<"Invalid"<<endl;
    break;
  }
}
}

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