SlideShare a Scribd company logo
1 of 7
Download to read offline
I need help completing this C++ code with these requirements.
instructions: IN C++ LANGUAGE PLEASE
Update the comments for each prototype by filling in the pre and post conditions.
Remember that pre conditions indicate what conditions must be met BEFORE the user calls the
function. The function will not work properly unless the pre conditions are met.
Post conditions indicate what will be the result of the function call. In other words, what
conditions will exist after the function is called.
See class notes from Thursday on pre and post conditions for some examples and further
explanation.
Code begins here:
#include //for NULL
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List();
//Default constructor; initializes and empty list
//Postcondition:
~List();
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst();
//Returns the first element in the list
//Precondition:
int getLast();
//Returns the last element in the list
//Precondition:
bool isEmpty();
//Determines whether a list is empty.
int getSize();
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast();
//Removes the value of the last element in the list
//Precondition:
//Postcondition:
void removeFirst();
//Removes the value of the first element in the list
//Precondition:
//Postcondition:
void insertLast(int data);
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
void insertFirst(int data);
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
/**Additional List Operations*/
void printList();
//Prints to the console the value of each element in the list sequentially
//and separated by a blank space
//Prints nothing if the list is empty
};
Solution
PROGRAM CODE:
#include
#include //for NULL
using namespace std;
class List
{
private:
struct Node
{
int data;
Node* next;
Node(int data): data(data), next(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
int size;
public:
/**Constructors and Destructors*/
List()
{
first = (Node*) malloc(sizeof(Node));
last = (Node*) malloc(sizeof(Node));
size = 0;
}
//Default constructor; initializes and empty list
//Postcondition:
~List()
{
delete first;
delete last;
}
//Destructor. Frees memory allocated to the list
//Postcondition:
/**Accessors*/
int getFirst()
{
return first->data;
}
//Returns the first element in the list
//Precondition:
int getLast()
{
return last->data;
}
//Returns the last element in the list
//Precondition:
bool isEmpty()
{
if(first == NULL)
return true;
else return false;
}
//Determines whether a list is empty.
int getSize()
{
return size;
}
//Returns the size of the list
/**Manipulation Procedures*/
void removeLast()
{
last = NULL;
}
//Removes the value of the last element in the list
//Precondition:
//Postcondition:
void removeFirst()
{
Nodeptr temp = first;
first = temp->next;
size--;
}
//Removes the value of the first element in the list
//Precondition:
//Postcondition:
void insertLast(int data)
{
if(first->data == 0)
{
first = new Node(data);
last = new Node(data);
}
else
{
Nodeptr temp = last;
last = new Node(data);
temp->next = last;
last = temp;
}
//size++;
}
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
void insertFirst(int data)
{
if(first->data == 0)
{
first = new Node(data);
last = new Node(data);
}
else
{
Nodeptr temp = first;
first = new Node(data);
first->next = temp;
}
size++;
}
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:
/**Additional List Operations*/
void printList()
{
Nodeptr temp = first;
while(temp != NULL)
{
cout<data<<" ";
temp = temp->next;
}
cout<

More Related Content

Similar to I need help completing this C++ code with these requirements.instr.pdf

C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfaashisha5
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfaaseletronics2013
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfaioils
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfcontact41
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfarihantkitchenmart
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1IIUM
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
Use C++class Node{public   Node ( int = 0 );       constru.pdf
Use C++class Node{public   Node ( int = 0 );        constru.pdfUse C++class Node{public   Node ( int = 0 );        constru.pdf
Use C++class Node{public   Node ( int = 0 );       constru.pdfoptokunal1
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfvinaythemodel
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdfKUNALHARCHANDANI1
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfnitinarora01
 
My question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfMy question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfjeetumordhani
 
for initializer_list include ltinitializer_listgt .pdf
 for initializer_list include ltinitializer_listgt .pdf for initializer_list include ltinitializer_listgt .pdf
for initializer_list include ltinitializer_listgt .pdfajay1317
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfARCHANASTOREKOTA
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfshanki7
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesXiao Qin
 

Similar to I need help completing this C++ code with these requirements.instr.pdf (20)

C++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdfC++ Please test your program before you submit the answer.pdf
C++ Please test your program before you submit the answer.pdf
 
Background Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdfBackground Circular Linked List A circular linked list is .pdf
Background Circular Linked List A circular linked list is .pdf
 
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdfPlease do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
Please do Part A, Ill be really gratefulThe main.c is the skeleto.pdf
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 
When we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdfWhen we test your Fraction.java we will use the given FractionTester.pdf
When we test your Fraction.java we will use the given FractionTester.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1Csc1100 lecture06 ch06_pt1
Csc1100 lecture06 ch06_pt1
 
In C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdfIn C++Write a recursive function to determine whether or not a Lin.pdf
In C++Write a recursive function to determine whether or not a Lin.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
Use C++class Node{public   Node ( int = 0 );       constru.pdf
Use C++class Node{public   Node ( int = 0 );        constru.pdfUse C++class Node{public   Node ( int = 0 );        constru.pdf
Use C++class Node{public   Node ( int = 0 );       constru.pdf
 
can someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdfcan someone fix the errors in this code- the name needs to be Fraction.pdf
can someone fix the errors in this code- the name needs to be Fraction.pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
My question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdfMy question is pretty simple, I just want to know how to call my ope.pdf
My question is pretty simple, I just want to know how to call my ope.pdf
 
for initializer_list include ltinitializer_listgt .pdf
 for initializer_list include ltinitializer_listgt .pdf for initializer_list include ltinitializer_listgt .pdf
for initializer_list include ltinitializer_listgt .pdf
 
StackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdfStackInterface An interface for the ADT stack. Do not modif.pdf
StackInterface An interface for the ADT stack. Do not modif.pdf
 
Please read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdfPlease read the comment ins codeExpressionTree.java-------------.pdf
Please read the comment ins codeExpressionTree.java-------------.pdf
 
COMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercisesCOMP2710: Software Construction - Linked list exercises
COMP2710: Software Construction - Linked list exercises
 

More from eyeonsecuritysystems

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfeyeonsecuritysystems
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfeyeonsecuritysystems
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfeyeonsecuritysystems
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfeyeonsecuritysystems
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfeyeonsecuritysystems
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfeyeonsecuritysystems
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfeyeonsecuritysystems
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfeyeonsecuritysystems
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfeyeonsecuritysystems
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfeyeonsecuritysystems
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfeyeonsecuritysystems
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfeyeonsecuritysystems
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfeyeonsecuritysystems
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfeyeonsecuritysystems
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfeyeonsecuritysystems
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfeyeonsecuritysystems
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfeyeonsecuritysystems
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfeyeonsecuritysystems
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfeyeonsecuritysystems
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfeyeonsecuritysystems
 

More from eyeonsecuritysystems (20)

For each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdfFor each step of DNA replication, predict the outcome if • concen.pdf
For each step of DNA replication, predict the outcome if • concen.pdf
 
Explain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdfExplain why a virus cant infect every cell Explain why a viru.pdf
Explain why a virus cant infect every cell Explain why a viru.pdf
 
Explain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdfExplain advantages and disadvantages of designing an OS kernel in la.pdf
Explain advantages and disadvantages of designing an OS kernel in la.pdf
 
Explain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdfExplain three similarities and two diffrences in anaerobic and aerob.pdf
Explain three similarities and two diffrences in anaerobic and aerob.pdf
 
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdfExercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
Exercise 7-8 Kickapoo Company uses an imprest petty cash system. The .pdf
 
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdfDiscussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
Discussions Grades people Syllabus Modules Google Drive D Question 1 .pdf
 
Discuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdfDiscuss the range of interactions that occur between human beings an.pdf
Discuss the range of interactions that occur between human beings an.pdf
 
Critique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdfCritique the customer contact model. What are its strengths and weak.pdf
Critique the customer contact model. What are its strengths and weak.pdf
 
Case Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdfCase Study Synlait Milk is an innovative dairy processing company th.pdf
Case Study Synlait Milk is an innovative dairy processing company th.pdf
 
An entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdfAn entity with two multivalued attributes will be mapped as how many.pdf
An entity with two multivalued attributes will be mapped as how many.pdf
 
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdfAssume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
Assume you are the new CEO of the Delta Phi Corporation. When the Bo.pdf
 
A manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdfA manager typically spends the least amount of time Communicating Mo.pdf
A manager typically spends the least amount of time Communicating Mo.pdf
 
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdfWrite message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
Write message.cpp and priorityq.cpp. The code in message.cpp and pri.pdf
 
Will a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdfWill a Pigovian tax always be equal to the marginal external cost of.pdf
Will a Pigovian tax always be equal to the marginal external cost of.pdf
 
Would you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdfWould you identify UTC’s approach to supply chain managemet as ce.pdf
Would you identify UTC’s approach to supply chain managemet as ce.pdf
 
White collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdfWhite collar crimes are best defined as a wide variety of nonviolent.pdf
White collar crimes are best defined as a wide variety of nonviolent.pdf
 
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdfWhy do we diverge from the Rational Choice Paradigm when identifying.pdf
Why do we diverge from the Rational Choice Paradigm when identifying.pdf
 
Why is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdfWhy is lactose much more soluble in water than in ethanolSolu.pdf
Why is lactose much more soluble in water than in ethanolSolu.pdf
 
Which of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdfWhich of the following is a technology that takes an Internet sig.pdf
Which of the following is a technology that takes an Internet sig.pdf
 
What aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdfWhat aspect of Ethernet can be a problem for security What mechanis.pdf
What aspect of Ethernet can be a problem for security What mechanis.pdf
 

Recently uploaded

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptxPoojaSen20
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...Nguyen Thanh Tu Collection
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 

Recently uploaded (20)

ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
ANTI PARKISON DRUGS.pptx
ANTI         PARKISON          DRUGS.pptxANTI         PARKISON          DRUGS.pptx
ANTI PARKISON DRUGS.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 

I need help completing this C++ code with these requirements.instr.pdf

  • 1. I need help completing this C++ code with these requirements. instructions: IN C++ LANGUAGE PLEASE Update the comments for each prototype by filling in the pre and post conditions. Remember that pre conditions indicate what conditions must be met BEFORE the user calls the function. The function will not work properly unless the pre conditions are met. Post conditions indicate what will be the result of the function call. In other words, what conditions will exist after the function is called. See class notes from Thursday on pre and post conditions for some examples and further explanation. Code begins here: #include //for NULL class List { private: struct Node { int data; Node* next; Node(int data): data(data), next(NULL){} }; typedef struct Node* Nodeptr; Nodeptr first; Nodeptr last; int size; public: /**Constructors and Destructors*/ List(); //Default constructor; initializes and empty list
  • 2. //Postcondition: ~List(); //Destructor. Frees memory allocated to the list //Postcondition: /**Accessors*/ int getFirst(); //Returns the first element in the list //Precondition: int getLast(); //Returns the last element in the list //Precondition: bool isEmpty(); //Determines whether a list is empty. int getSize(); //Returns the size of the list /**Manipulation Procedures*/ void removeLast(); //Removes the value of the last element in the list //Precondition: //Postcondition: void removeFirst(); //Removes the value of the first element in the list
  • 3. //Precondition: //Postcondition: void insertLast(int data); //Inserts a new element at the end of the list //If the list is empty, the new element becomes both first and last //Postcondition: void insertFirst(int data); //Inserts a new element at the start of the list //If the list is empty, the new element becomes both first and last //Postcondition: /**Additional List Operations*/ void printList(); //Prints to the console the value of each element in the list sequentially //and separated by a blank space //Prints nothing if the list is empty }; Solution PROGRAM CODE: #include #include //for NULL using namespace std; class List { private: struct Node { int data; Node* next; Node(int data): data(data), next(NULL){}
  • 4. }; typedef struct Node* Nodeptr; Nodeptr first; Nodeptr last; int size; public: /**Constructors and Destructors*/ List() { first = (Node*) malloc(sizeof(Node)); last = (Node*) malloc(sizeof(Node)); size = 0; } //Default constructor; initializes and empty list //Postcondition: ~List() { delete first; delete last; } //Destructor. Frees memory allocated to the list //Postcondition: /**Accessors*/ int getFirst() { return first->data;
  • 5. } //Returns the first element in the list //Precondition: int getLast() { return last->data; } //Returns the last element in the list //Precondition: bool isEmpty() { if(first == NULL) return true; else return false; } //Determines whether a list is empty. int getSize() { return size; } //Returns the size of the list /**Manipulation Procedures*/ void removeLast() { last = NULL; } //Removes the value of the last element in the list //Precondition:
  • 6. //Postcondition: void removeFirst() { Nodeptr temp = first; first = temp->next; size--; } //Removes the value of the first element in the list //Precondition: //Postcondition: void insertLast(int data) { if(first->data == 0) { first = new Node(data); last = new Node(data); } else { Nodeptr temp = last; last = new Node(data); temp->next = last; last = temp; } //size++; } //Inserts a new element at the end of the list //If the list is empty, the new element becomes both first and last //Postcondition: void insertFirst(int data) { if(first->data == 0) {
  • 7. first = new Node(data); last = new Node(data); } else { Nodeptr temp = first; first = new Node(data); first->next = temp; } size++; } //Inserts a new element at the start of the list //If the list is empty, the new element becomes both first and last //Postcondition: /**Additional List Operations*/ void printList() { Nodeptr temp = first; while(temp != NULL) { cout<data<<" "; temp = temp->next; } cout<