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

PLEASE answer the assignment in c++ PLEASE ADD COMMENTS FOR THE CODE( so that i

ID: 672357 • Letter: P

Question

PLEASE answer the assignment in c++

PLEASE ADD COMMENTS FOR THE CODE( so that i can follow and understand) AND SEPERATE BY FILE, AND TITLE THE FILES.

please only post a complete answer (multiple files: 4) and the comments are very important please dont forget them.

thank you so much for your help!!

* will happily give a thumbs up 5 stars for a helpful answer*

thanks!!

The data for this lab can be found here: https://github.com/fredcmpe126/DoublyLinkedList/blob/master/stock.txt

This assignment is going to be the same as your last lab (last lab can be found here https://www.chegg.com/homework-help/questions-and-answers/please-answer-assignment-c-please-add-comments-code-follow-understand-seperate-file-title--q8272323 , please use the code in the answer to write the new one ) with a few changes.

1. Instead of a singly linked list you will be making a doubly linked list.

This means inside of the node class you need to create an extra member called Node* prev to keep track of the previous node.

2. In your linked list class you will be adding an additional member called tail which keeps track of the last node. This is similar to the head but instead of keeping track of the first node, it keeps track of the last node.

3. Lastly, in the node class the data from last week was an int. This week the data will be a Stock. You will need to create an extra class called Stock which handles the data from the input file. (TickerSymbol and StockPrice).

So just like the last lab, you will need to make functions that can:

1. append to end

2. append to beginning

3. remove last

4. remove first

5. find halfway

6. split the list.

Explanation / Answer

//Node.h

#ifndef LINKEDLIST_NODE_H
#define LINKEDLIST_NODE_H

#include<iostream>
using namespace std;
class Node {
public:
Node();
Node(string,double);
string TickerSymbol;
double StockPrice;
Node* next;
Node* prev;
};

#endif
-----------------------------------------
//Node.cpp
#include "Node.h"
using namespace std;
Node::Node(){
TickerSymbol = "";
StockPrice=0.0;
next = NULL;
prev=NULL;
}

Node::Node(string tk,double sp)){
TickerSymbol = tk;
StockPrice=sp;
next = NULL;
prev = NULL;
}
----------------------------------------------
//LinkedList.h
#ifndef LINKEDLIST_LINKEDLIST_H
#define LINKEDLIST_LINKEDLIST_H

#include "Node.h"
using namespace std;
class LinkedList {
public:
LinkedList();
void AppendToEnd(string,double);
void AppendToBeginning(string,double);
void RemoveLast();
void RemoveFirst();
//void SplitList(LinkedList&, LinkedList&);
void findhalfway();
void PrintList();
int IsEmpty();
private:
Node* head;
};
#endif

------------------------------------------------
//LinkedList.cpp
#include "LinkedList.h"

LinkedList::LinkedList(){
head = NULL;
}

//append a element at the end of the list
void LinkedList::AppendToEnd(string ts,double sp){
if(head == NULL){
head = new Node(ts,sp);
}
else{
Node* trav = head;
while(trav->next != NULL){
trav = trav->next;
}
trav->next = new Node(ts,sp);
trav->prev=trav;
}
PrintList();
}
//insert a element at the beginning of the list
void LinkedList::AppendToBeginning(string ts,double sp)
{
   if(head == NULL){
head = new Node(ts,sp);
}
else
{
   Node* trav = head;
   head=new Node(ts,sp);
   head->next=trav;
   trav->prev=head;
   }
   PrintList();
}
int LinkedList::IsEmpty()
{
if(head == NULL){
cout<<endl<<"List Empty";
return 1;
}  
}
void LinkedList::PrintList(){
       if(!IsEmpty()){
Node* trav = head;
cout<<endl<<"Linked list:"<<endl;
while(trav != NULL){
cout << trav->TickerSymbol<<","<<trav->StockPrice << endl;
trav = trav->next;
}
}
}


void LinkedList::RemoveLast()
{
   if(!IsEmpty()){
Node* trav = head;
while(trav->next != NULL){
trav = trav->next;
}  
Node*temp=trav->next;
trav->next=NULL;
delete temp;
PrintList();
}
}
void LinkedList::RemoveFirst()
{
   if(!IsEmpty()){
   Node * temp;
   temp=head->next;
   head=temp;
   PrintList();
   }
}
//void LinkedList::SplitList(LinkedList&, LinkedList&);
  
// Find the middle element in the list
// if number of elements are even, n/2+1 th element. else n/2 th element
void LinkedList::findhalfway()
{
   if(!IsEmpty()){
Node* trav = head;
int i=0;
int n=0; // to store number of elements in the list
//finding total number of elements in the list
PrintList();
while(trav != NULL){
trav = trav->next;
n++;
}
  
   while(trav != NULL&& (i<(n/2)+1)){
trav = trav->next;
i++;
}   
cout<<endl<<"Mid element:"<<endl;
cout<<"Ticker Symbol:"<<trav->TickerSymbol;
cout<<"StockPrice"<<trav->StockPrice;
}
}

----------------------------------------------------------
// Stock.cpp
#include <iostream>
#include "LinkedList1.cpp"
#include <fstream> //for input and output files

using namespace std;

int main()
{
   string tk;
   double price;
   ifstream infile; //input file stream variable
infile.open("stock.txt");
LinkedList List; // error here
while(!infile.eof())
{
    infile>>tk;
infile>>price;
List.AppendToEnd(tk,price);
}
List.PrintList();
List.findhalfway();
List.RemoveLast();
List.RemoveLast();
cout<<endl<<"Enter Ticker symbol, price to insert at end:";
cin>>tk>>price;
List.AppendToEnd(tk,price);
cout<<endl<<"Enter Ticker symbol, price to insert at beginning:";
cin>>tk>>price;
List.AppendToBeginning(tk,price);
   return 0;
}

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

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