Question

IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...

IntList Lab Specifications

You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement more than 1 or 2 member functions without fulling testing them with your own test harness.

IntNode struct

I am providing the IntNode class you are required to use. Place this class definition within the IntList.h file exactly as is. Make sure you place it above the definition of your IntList class. Notice that you will not code an implementation file for the IntNode class. The IntNode constructor has been defined inline (within the class declaration). Do not write any other functions for the IntNode class. Use as is.

struct IntNode {
    int data;
    IntNode *next;
    IntNode(int data) : data(data), next(0) {}
};

ntList class

Encapsulated (Private) Data Fields

head: IntNode *

tail: IntNode *

Public Interface (Public Member Functions)

IntList(): Initializes an empty list.

~IntList(): Deallocates all remaining dynamically allocated memory (all remaining IntNodes).

void display() const: Displays to a single line all of the int values stored in the list, each separated by a space. This function does NOT output a newline or space at the end.

void push_front(int value): Inserts a data value (within a new node) at the front end of the list.

void pop_front(): Removes the value (actually removes the node that contains the value) at the front end of the list. Does nothing if the list is already empty.

bool empty() const: Returns true if the list does not store any data values (does not have any nodes), otherwise returns false.

The remaining functions may only be developed in your private workspace. Copy the 3 files from lab 7 into your private workspace before beginning on these functions:

IntList(const IntList &cpy): the copy constructor. Make sure this performs deep copy.

IntList & operator=(const IntList &rhs): the overloaded assignment operator. Make sure this performs deep copy.

void push_back(int value): Inserts a data value (within a new node) at the back end of the list.

void clear(): Removes (deallocates) all IntNodes in the IntList. Don't forget to set both head and tail to appropriate values for an empty list.

void selection_sort(): Sorts the integers in the list into ascending order. Do NOT move the nodes, just the integers.

void insert_ordered(int value): Inserts a data value (within a new node) in an ordered list. Assumes the list is already sorted in ascending order (i.e., Do not sort the list first, assume the list is already is sorted.) This function loops through the list until if finds the correct position for the new data value and then inserts the new IntNode in that location. This function may NOT ever sort the list.

void remove_duplicates(): Removes all duplicate data values (actually removes the nodes that contain the values) within the list. Always remove just the later value within the list when a duplicate is found. This function may NOT ever sort the list.

friend ostream & operator<<(ostream &out, const IntList &rhs): A global friend function that outputs to the stream all of the integer values within the list on a single line, each separated by a space. This function does NOT send to the stream a newline or space at the end.

main.cpp test harness for PROGRAM

Use this main.cpp file for testing your IntList.

#include "IntList.h"

#include <iostream>
using namespace std;

int main()
{
   cout << "Enter a test number(1-5): ";
    int test;
    cin >> test;
    cout << endl;
   //tests constructor, destructor, push_front, pop_front, display
   if (test == 1) {
      cout << "\nlist1 constructor called";
      IntList list1;
      cout << "\npushfront 10";
      list1.push_front( 10 );
      cout << "\npushfront 20";
      list1.push_front( 20 );
      cout << "\npushfront 30";
      list1.push_front( 30 );
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << endl;
   }
   if (test == 1) {
      cout << "list1 destructor called" << endl;
   }

   //tests push_back
   if (test == 2) {
      cout << "\nlist2 constructor called";
      IntList list2;
      cout << "\npushback 10";
      list2.push_back( 10 );
      cout << "\npushback 20";
      list2.push_back( 20 );
      cout << "\npushback 30";
      list2.push_back( 30 );
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << endl;
   }
   if (test == 2) {
      cout << "list2 destructor called" << endl;
   }

   //tests selection_sort
   if (test == 3)
   {
      cout << "\nlist3 constructor called";
      IntList list3;
      cout << "\npushfront 10";
      list3.push_front( 10 );
      cout << "\npushfront 20";
      list3.push_front( 20 );
      cout << "\npushfront 30";
      list3.push_front( 30 );
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npop";
      list3.pop_front();
      cout << "\npop";
      list3.pop_front();
      cout << "\npop";
      list3.pop_front();
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npushfront 10";
      list3.push_front( 10 );
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npushfront 20";
      list3.push_front( 20 );
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << endl;
   }
   if (test == 3) {
      cout << "list3 destructor called" << endl;
   }

   //tests insert_sorted
   if (test == 4) {
      cout << "\nlist4 constructor called";
      IntList list4;
      cout << "\ninsert 20";
      list4.insert_ordered( 20 );
      cout << "\ninsert 10";
      list4.insert_ordered( 10 );
      cout << "\ninsert 30";
      list4.insert_ordered( 30 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 50";
      list4.insert_ordered( 50 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 40";
      list4.insert_ordered( 40 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 11";
      list4.insert_ordered( 11 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 10";
      list4.insert_ordered( 10 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 11";
      list4.insert_ordered( 11 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 9";
      list4.insert_ordered( 9 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 50";
      list4.insert_ordered( 50 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 51";
      list4.insert_ordered( 51 );
      cout << "\nlist4: ";
      list4.display();
      cout << endl;
   }
   if (test == 4) {
      cout << "list4 destructor called" << endl;
   }

   //tests remove_duplicates
   if (test == 5) {
      cout << "\nlist5 constructor called";
      IntList list5;
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\npushfront 30";
      list5.push_front( 30 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npop";
      list5.pop_front();
      cout << "\npop";
      list5.pop_front();
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\npop";
      list5.pop_front();
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << endl;
   }
   if (test == 5) {
      cout << "list5 destructor called" << endl;
   }

   /*
   * Destructor will be tested by looking at code. There is no run-time 
   * test for it. Make sure your destructor actually deletes ALL nodes, not
   * just the head and/or tail.
   */

   return 0;
}

Homework Answers

Answer #1

main.cpp

#include "IntList.h"

#include <iostream>
using namespace std;

int main()
{
   cout << "Enter a test number(1-5): ";
    int test;
    cin >> test;
    cout << endl;
   //tests constructor, destructor, push_front, pop_front, display
   if (test == 1) {
      cout << "\nlist1 constructor called";
      IntList list1;
      cout << "\npushfront 10";
      list1.push_front( 10 );
      cout << "\npushfront 20";
      list1.push_front( 20 );
      cout << "\npushfront 30";
      list1.push_front( 30 );
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << "\npop";
      list1.pop_front();
      cout << "\nlist1: ";
      list1.display();
      cout << endl;
   }
   if (test == 1) {
      cout << "list1 destructor called" << endl;
   }

   //tests push_back
   if (test == 2) {
      cout << "\nlist2 constructor called";
      IntList list2;
      cout << "\npushback 10";
      list2.push_back( 10 );
      cout << "\npushback 20";
      list2.push_back( 20 );
      cout << "\npushback 30";
      list2.push_back( 30 );
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << "\npop";
      list2.pop_front();
      cout << "\nlist2: ";
      list2.display();
      cout << endl;
   }
   if (test == 2) {
      cout << "list2 destructor called" << endl;
   }

   //tests selection_sort
   if (test == 3)
   {
      cout << "\nlist3 constructor called";
      IntList list3;
      cout << "\npushfront 10";
      list3.push_front( 10 );
      cout << "\npushfront 20";
      list3.push_front( 20 );
      cout << "\npushfront 30";
      list3.push_front( 30 );
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npop";
      list3.pop_front();
      cout << "\npop";
      list3.pop_front();
      cout << "\npop";
      list3.pop_front();
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npushfront 10";
      list3.push_front( 10 );
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << "\npushfront 20";
      list3.push_front( 20 );
      cout << "\nlist3: ";
      list3.display();
      cout << "\nselection_sort()";
      list3.selection_sort();
      cout << "\nlist3: ";
      list3.display();
      cout << endl;
   }
   if (test == 3) {
      cout << "list3 destructor called" << endl;
   }

   //tests insert_sorted
   if (test == 4) {
      cout << "\nlist4 constructor called";
      IntList list4;
      cout << "\ninsert 20";
      list4.insert_ordered( 20 );
      cout << "\ninsert 10";
      list4.insert_ordered( 10 );
      cout << "\ninsert 30";
      list4.insert_ordered( 30 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 50";
      list4.insert_ordered( 50 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 40";
      list4.insert_ordered( 40 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 11";
      list4.insert_ordered( 11 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 10";
      list4.insert_ordered( 10 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 11";
      list4.insert_ordered( 11 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 9";
      list4.insert_ordered( 9 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 50";
      list4.insert_ordered( 50 );
      cout << "\nlist4: ";
      list4.display();
      cout << "\ninsert 51";
      list4.insert_ordered( 51 );
      cout << "\nlist4: ";
      list4.display();
      cout << endl;
   }
   if (test == 4) {
      cout << "list4 destructor called" << endl;
   }

   //tests remove_duplicates
   if (test == 5) {
      cout << "\nlist5 constructor called";
      IntList list5;
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\npushfront 30";
      list5.push_front( 30 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 10";
      list5.push_front( 10 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\npushfront 20";
      list5.push_front( 20 );
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()";
      list5.remove_duplicates();
      cout << "\nlist5: ";
      list5.display();
      cout << "\npop";
      list5.pop_front();
      cout << "\npop";
      list5.pop_front();
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\npush_front(30)";
      list5.push_front(30);
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << "\npop";
      list5.pop_front();
      cout << "\nlist5: ";
      list5.display();
      cout << "\nremove_duplicates()" << flush;
      list5.remove_duplicates();
      cout << "\nlist5: " << flush;
      list5.display();
      cout << endl;
   }
   if (test == 5) {
      cout << "list5 destructor called" << endl;
   }

   /*
   * Destructor will be tested by looking at code. There is no run-time
   * test for it. Make sure your destructor actually deletes ALL nodes, not
   * just the head and/or tail.
   */

   return 0;
}

IntList.cpp

#include <iostream>
// #include <algorithm>
using namespace std;

#include "IntList.h"

IntList::IntList(): head(0), tail(0) {}

IntList::~IntList(){
    while (!empty()) {
        pop_front();
    }
}

void IntList::display() const{
    //cout << "Display called." << endl;
    if(empty()) {
        return;
    }
    else {
        IntNode* currentNode = head;
        // currentNode = head->next;
        cout << currentNode->data;
        while(currentNode->next != 0) {
            currentNode = currentNode->next;
            cout << ' ' << currentNode->data;
        }
    }
  
    //tests head and tail addresses, next, and data;
}

void IntList::push_front(int value){
  
    IntNode* temp = new IntNode(value);
  
    temp->next = head;
    head = temp;
    if(tail == 0) {   //if initially empty node
        tail = temp;
    }
}

void IntList::pop_front(){
    if(empty()) {
        return;
    }
    else {
        IntNode* temp = head;
        head = head->next;
        delete temp;
    }
    if(head == 0) { //if go to empty node
        tail = 0;
        // cout << "THIS HAPPENS" << endl;
    }
  
}

bool IntList::empty() const{
    if(head == 0 && tail == 0) {
        return true;
    }
    return false;
}


//if list1=list1, that's self assignment, so just do nothing! >:D

IntList::IntList(const IntList &cpy) {
    // if(cpy.empty()) {
    //     head = 0;
    //     tail = 0;
    // }
    head = 0;
    tail = 0;
    //TODO what if there's only one node????????????
    if(!cpy.empty()) {
        IntNode* curr = cpy.head;
        // cout << endl;
        while(curr != 0) {
            // data = curr->data;
            // next = curr->next;
            push_back(curr->data);
            curr = curr->next;
        }
    }

}

IntList & IntList::operator=(const IntList &rhs) {
    if (this == &rhs) {
        return *this;
    }
    else if(rhs.empty()) {
        head = 0;
        tail = 0;
    }
    else {
        clear();
        IntNode* curr = rhs.head;
        while(curr != 0) {
            // data = curr->data;
            // next = curr->next;
            push_back(curr->data);
            curr = curr->next;
        }
    }
    return *this;
}

void IntList::push_back(int value) {
  
    IntNode* temp = new IntNode(value);

    if (empty()) {
      
        //IntNode* temp = new IntNode(value);
        head = temp;
        tail = temp;
    }
    else {
      
        //IntNode* temp = new IntNode(value);
        tail->next = temp;
        tail = temp;
    }
}
  
void IntList::clear() {
    while (!empty()) {
        pop_front();
    }
}

void IntList::selection_sort() {
    if (empty()) {
        return;
    }
    else {
        IntNode* min = head;   //CHANGED 0 TO HEAD!!!!!!****!*!!*!*!**!
        int temp = 0;
        for (IntNode* i = head; i->next != 0; i = i->next) {
            min = i;
            for(IntNode* j = i->next; j != 0; j = j->next) {
          
                if (min->data > j->data) {
                    min = j;
                }
            }
            temp = i->data;
            i->data = min->data;
            min->data = temp;
        }
    }
}

void IntList::insert_ordered(int value) {//TODO
    if(empty()) {
        push_front(value);
    }
    else if (value <= head->data) { //equal to?????????
        push_front(value);
    }
    else if (value >= tail->data) { //equal to too??????
        push_back(value);
    }
    else {
        IntNode* prev = head;
        IntNode* curr = head->next;
        IntNode* temp = new IntNode(value);
        while(curr != 0) {
          
            if(value < curr->data) {
                prev->next = temp;
                temp->next = curr;
                return; //break????
            }
          
            prev = prev->next;
            curr = curr->next;
        }
    }
  
}

void IntList::remove_duplicates() { //TODO
    if(empty() || head == tail) {
        return;
    }
    else {
        IntNode* prev = 0;
        // int ite9ration = 0;
        // int jiter = 0;
        for(IntNode* i = head; i != 0; i = i->next) { //FIXME seg fault! maybe issue with the deleting??
            prev = i;
            for(IntNode* j = i->next; j != 0; j = prev->next) {
              
                if(i->data == j->data) {
                    if (j == tail) {
                        delete j;
                        tail = prev;
                        tail->next = 0;
                        //cout << "tail" << endl;
                        //cout << "j " << j->next << '/' << j->data << endl;
                        if (head == tail) {
                            //cout << "alsdhalsdkh" << endl;
                            return;
                        }
                    }
                    else {
                        prev->next = j->next;
                        delete j;
                        //j = prev->next;  
                        //cout << "match found" << endl;
                    }
                }
              
              
                // if (j == tail && i->data == j->data) { //working with last node, WORKS!! :D (i think)
                //     delete j;
                //     tail = prev;
                //     tail->next = 0;
                //     cout << "tail" << endl;
                //     if (head == tail) {
                //         //cout << "alsdhalsdkh" << endl;
                //         return;
                //     }
                //     // else {
                //     //     j = tail;
                //     // }
                // }
                // else if(i->data == j->data) {

                //     prev->next = j->next;
                //     delete j;
                //     //j = prev->next;  
                //     cout << "match found" << endl;
                // }
                else {
                    prev = prev->next;
                }
            }
            cout << "J LOOPed" << endl;
        }
    }
}
  
ostream & operator<<(ostream &out, const IntList &rhs) {
    if(rhs.empty()) {
        return out;
    }
    else {
        IntNode* currentNode = rhs.head;
        // currentNode = head->next;
        out << currentNode->data;
        while(currentNode->next != 0) {
            currentNode = currentNode->next;
            out << ' ' << currentNode->data;
        }
    }
    return out;
}

IntList.h

#ifndef INTLIST_H
#define INTLIST_H

#include <iostream>
using namespace std;

struct IntNode {
    int data;
    IntNode *next;
    IntNode(int data) : data(data), next(0) {}
};

class IntList {
    IntNode* head;
    IntNode* tail;
public:
    IntList();
    ~IntList();
    void display() const;
    void push_front(int value);
    void pop_front();
    bool empty() const;
    IntList(const IntList &cpy); //the copy constructor.
    IntList & operator=(const IntList &rhs); //the overloaded assignment operator.
    void push_back(int value); //Inserts a data value (within a new node) at the back end of the list.
    void clear(); //Removes (deallocates) all IntNodes in the IntList.
    void selection_sort(); //Sorts the integers in the list into ascending order.
    void insert_ordered(int value); //Inserts a data value (within a new node) in an ordered list.
    void remove_duplicates(); //Removes all duplicate data values (actually removes the nodes that contain the values) within the list.
    friend ostream & operator<<(ostream &out, const IntList &rhs); //A global friend function that outputs to the stream all of the integer values within the list on a single line, each separated by a space. the end.
};

#endif

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Programming Exercise 2: implement the member function moveToNth(...) that removes the item marked by the cursor...
Programming Exercise 2: implement the member function moveToNth(...) that removes the item marked by the cursor and inserts it as the nth element of the list; test your implementation by turning the flag LAB3_TEST2 from 0 to 1 in config.h; - Programming Exercise 3: implement the ListArray member function find(...) that searches for the element given as a parameter; the search starts at the cursor and stops when it finds the element or at the end of the list; the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the...
Can someone please edit my code so that it satisfies the assignments' requirements? I pasted the codes below. Requirement: Goals for This Project:  Using class to model Abstract Data Type  OOP-Data Encapsulation You are asked to write an app to keep track of a relatively small music library. The app should load song information from a data file once the app is started. It should allow user to view, add, remove, and search for songs. The app should...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's...
Lab: RectClass (constructor) Code in C++ This program creates a Rectangle object, then displays the rectangle's length, width, and area Define an overloaded constructor and use it when creating the Rectangle object instead of using the setters. Change this program to calculate and display the rectangle's perimeter. Example: In feet, how wide is your house? 20 In feet, how long is your house? 25 The house is 20.00 feet wide. The house is 25.00 feet long. The house has 500.00...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below)...
Given the following specifications for an array-based unsorted list, implement all of the functions (declared below) and a write a driver code to test all of your implementations. // Define a structure to use as the list item struct ListItem { int key; int Data; }; #define MAX_SIZE 50 // Define maximum length of the list class UnsortedArray { private: int head; // Index to head of the list ListItem theList[MAX_SIZE]; // The list public: UnsortedArray(); // Class constructor ~...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are...
Functions displayGrades and addGrades must be rewritten so that the only parameters they take in are pointers or constant pointers. Directions: Using the following parallel array and array of vectors: // may be declared outside the main function const int NUM_STUDENTS = 3; // may only be declared within the main function string students[NUM_STUDENTS] = {"Tom","Jane","Jo"}; vector <int> grades[NUM_STUDENTS] {{78,98,88,99,77},{62,99,94,85,93}, {73,82,88,85,78}}; Be sure to compile using g++ -std=c++11 helpWithGradesPtr.cpp Write a C++ program to run a menu-driven program with the...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I...
C++ PROGRAMMING Hi! I have to make a program that adds fractions and simplifies them. I feel like I know how to write that. What I'm having trouble with is implementing two files the professer gave us. I would appreicate any help in understanding their purpose as in if Im supposed to take information from those files or give it information. Thank you! I have attatched the homework instructions and the two files given. Implementation The main program, called calculator.cpp...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any...
Write a template-based class that implements a template-based implementation of Homework 3 that allows for any type dynamic arrays (replace string by the template in all instances below). • The class should have: – A private member variable called dynamicArray that references a dynamic array of type string. – A private member variable called size that holds the number of entries in the array. – A default constructor that sets the dynamic array to NULL and sets size to 0....
C++ ONLY -- PRACTICE ASSIGNMENT For our practice assignment we have to turn in 2 files...
C++ ONLY -- PRACTICE ASSIGNMENT For our practice assignment we have to turn in 2 files - Driver.cpp and StringQueue.h Driver.cpp is provided for us, but if there are any changes needed to be made to that file please let me know. Based on the instructions below, what should the code look like for StringQueue.h ? Create a class named StringQueue in a file named StringQueue.h. Create a QueueNode structure as a private member of the class. The node should...