C++  Given header is in image main.cpp #include "IntList.h" #include 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 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; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ 

Given header is in image

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 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;
}

13.12 Program 6: IntList
You will begin the implementation of the singly-linked list.
IntList Specifications
You are 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 may write your own test harness (within a file named main.cpp) but I provide the main.cpp that is
used for testing output on zyBooks. Never implement more than 1 or 2 member functions without fulling testing them with your own test
harness.
IntNode struct and IntList header
To simplify this project, I am providing the header file. Please see the discussion board post to obtain the file. It contains the IntNode code
that you must use. You are not allowed to alter this header file in any way whatsoever.
IntList class
You should define function stubs for all class functions to allow the program to fully compile. Recall function stubs do not have logic
implemented they are simple empty functions or functions with only a return statement that are implemented to allow compilation and
execution.
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(0 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.
• 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.
• 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 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.
Given Function That Overloads the << operator. This provided function overload should go at the bottom of your class C++ file.
• friend ostream & operator<<(ostream &out, const IntList &rhs): A global friend function that outouts 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.
ostream & operator<< (ostream sout, const IntList &rhs)
IntNode* t = rhs.head;
if (t != NULL)
{
out << t->data;
t = t->next;
}
while (t != NULL)
{
out << " " << t->data;
t = t->next;
return out;
Transcribed Image Text:13.12 Program 6: IntList You will begin the implementation of the singly-linked list. IntList Specifications You are 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 may write your own test harness (within a file named main.cpp) but I provide the main.cpp that is used for testing output on zyBooks. Never implement more than 1 or 2 member functions without fulling testing them with your own test harness. IntNode struct and IntList header To simplify this project, I am providing the header file. Please see the discussion board post to obtain the file. It contains the IntNode code that you must use. You are not allowed to alter this header file in any way whatsoever. IntList class You should define function stubs for all class functions to allow the program to fully compile. Recall function stubs do not have logic implemented they are simple empty functions or functions with only a return statement that are implemented to allow compilation and execution. 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(0 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. • 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. • 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 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. Given Function That Overloads the << operator. This provided function overload should go at the bottom of your class C++ file. • friend ostream & operator<<(ostream &out, const IntList &rhs): A global friend function that outouts 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. ostream & operator<< (ostream sout, const IntList &rhs) IntNode* t = rhs.head; if (t != NULL) { out << t->data; t = t->next; } while (t != NULL) { out << " " << t->data; t = t->next; return out;
IntList.h + X
Miscellaneous Files
Q#ifndef INTLIST_H
#define INTLIST_H
2
3
4
#include <ostream>
6.
using namespace std;
7
estruct IntNode
{
8
10
int data;
11
IntNode* next;
IntNode (int data) : data(data), next(0) { }
};
12
13
14
aclass Intlist
{
private:
IntNode* head;
IntNode* tail;
15
16
17
18
19
public:
Intlist();
Intlist(const Intlist &);
Intlist & operator=(const IntList &);
~IntList();
20
21
22
23
24
bool empty() const;
void display() const;
void push_front(int);
void push_back(int);
void pop_front();
void insert_ordered(int);
void remove_duplicates();
void clear();
friend ostream &operator<<(ostream &, const IntList &);
private:
IntNode* min(IntNode*);
25
26
27
28
29
30
31
32
33
34
35
36
};
37
38
#endif
39
40
N N N N N N
Transcribed Image Text:IntList.h + X Miscellaneous Files Q#ifndef INTLIST_H #define INTLIST_H 2 3 4 #include <ostream> 6. using namespace std; 7 estruct IntNode { 8 10 int data; 11 IntNode* next; IntNode (int data) : data(data), next(0) { } }; 12 13 14 aclass Intlist { private: IntNode* head; IntNode* tail; 15 16 17 18 19 public: Intlist(); Intlist(const Intlist &); Intlist & operator=(const IntList &); ~IntList(); 20 21 22 23 24 bool empty() const; void display() const; void push_front(int); void push_back(int); void pop_front(); void insert_ordered(int); void remove_duplicates(); void clear(); friend ostream &operator<<(ostream &, const IntList &); private: IntNode* min(IntNode*); 25 26 27 28 29 30 31 32 33 34 35 36 }; 37 38 #endif 39 40 N N N N N N
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Concept of memory addresses in pointers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education