SlideShare a Scribd company logo
1 of 3
Download to read offline
Start from the sample code on the pdf
Change struct to class
Make all the members private
Add get_size , get_capacity and get_array methods
Add remove , index_of and operator+ methods
Add oprator< method, and together with other five ( > , >= , <= , == , != )
Complete and debug all the other methods in the sample code, such as insert
Write some testing code in the main function
Here is all the sample code that was provided in the pdf.
Program1.cpp:
int main()
{
int m = 9;
float n = 2.7;
int arr[6] = { 5,8,3,4,0,0 };
for ( int i = 5; i > 1; i-- )
arr[i] = arr[i-1];
arr[1] = 2;
// arr: { 5,2,8,3,4,0 }
return 0;
}
LinkedList.cpp:
void LinkedList::append(int d)
{
Node* newNode = new Node();
newNode->data = d;
tail->next = newNode;
tail = newNode;
length++;
}
void prepend(int d)
{
Node* newNode = new Node();
newNode->data = d;
newNode->next = head->next;
head->next = newNode;
length++;
}
void LinkedList::print()
{
Node* curNode = head->next;
while ( curNode )
{
cout << curNode->data << endl;
curNode = curNode->next;
}
}
void LinkedList::insert(int d)
{
Node* preNode = head;
Node* curNode = head->next;
while ( curNode )
{
if ( curNode->data > d ) break;
preNode = curNode;
curNode = curNode->next;
}
Node* newNode = new Node();
newNode->data = d;
preNode->next = newNode;
newNode->next = curNode;
length++;
}
int main()
{
LinkedList list;
list.append(5);
list.append(8);
list.append(9);
list.insert(6);
list.print(); // output: 5 6 8 9
return 0;
}
Node.cpp:
struct Node
{
int data;
Node* next;
};
int main()
{
Node* node_A = new Node();
node_A->data = 5;
Node* node_B = new Node();
node_B->data = 3;
Node* node_C = new Node();
node_C->data = 8;
node_A->next = node_B;
node_B->next = node_C;
// ...
LinkedList.h:
struct LinkedList
{
Node* head = new Node();
Node* tail = head;
int length = 0;
void append(int d);
void prepend(int d);
void print();
void insert(int d);
// ...
};

More Related Content

Similar to Start from the sample code on the pdf Change struct to clas.pdf

C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
FUNCTIONINPYTHON.pptx
FUNCTIONINPYTHON.pptxFUNCTIONINPYTHON.pptx
FUNCTIONINPYTHON.pptxSheetalMavi2
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdflailoesakhan
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptxNileshBorkar12
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiMuhammed Thanveer M
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptxkrushnaraj1
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming ProjectSage Jacobs
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docxrafbolet0
 

Similar to Start from the sample code on the pdf Change struct to clas.pdf (20)

Xamarin: C# Methods
Xamarin: C# MethodsXamarin: C# Methods
Xamarin: C# Methods
 
CPP Assignment Help
CPP Assignment HelpCPP Assignment Help
CPP Assignment Help
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 
C
CC
C
 
C
CC
C
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
FUNCTIONINPYTHON.pptx
FUNCTIONINPYTHON.pptxFUNCTIONINPYTHON.pptx
FUNCTIONINPYTHON.pptx
 
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdfProgFund_Lecture_4_Functions_and_Modules-1.pdf
ProgFund_Lecture_4_Functions_and_Modules-1.pdf
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
Functions_in_Python.pptx
Functions_in_Python.pptxFunctions_in_Python.pptx
Functions_in_Python.pptx
 
14 operator overloading
14 operator overloading14 operator overloading
14 operator overloading
 
Linux_C_LabBasics.ppt
Linux_C_LabBasics.pptLinux_C_LabBasics.ppt
Linux_C_LabBasics.ppt
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
09. Methods
09. Methods09. Methods
09. Methods
 
The Final Programming Project
The Final Programming ProjectThe Final Programming Project
The Final Programming Project
 
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docxSpring 2014 CSCI 111 Final exam   of 1 61. (2 points) Fl.docx
Spring 2014 CSCI 111 Final exam of 1 61. (2 points) Fl.docx
 
C function
C functionC function
C function
 

More from babitasingh698417

Sukis utility function is Where C1 is consumpt.pdf
Sukis utility function is     Where C1 is consumpt.pdfSukis utility function is     Where C1 is consumpt.pdf
Sukis utility function is Where C1 is consumpt.pdfbabitasingh698417
 
Subject Organizational Behaviour This is a long essay quest.pdf
Subject Organizational Behaviour This is a long essay quest.pdfSubject Organizational Behaviour This is a long essay quest.pdf
Subject Organizational Behaviour This is a long essay quest.pdfbabitasingh698417
 
successfully converting a 1point conversion is 10 The pro.pdf
successfully converting a 1point conversion is 10 The pro.pdfsuccessfully converting a 1point conversion is 10 The pro.pdf
successfully converting a 1point conversion is 10 The pro.pdfbabitasingh698417
 
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdf
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdfSubtopic 3 Demonstrate awareness of own cultural bias Stude.pdf
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdfbabitasingh698417
 
Subject Marketing Management Questions 1 Explain Four st.pdf
Subject Marketing Management Questions 1 Explain Four st.pdfSubject Marketing Management Questions 1 Explain Four st.pdf
Subject Marketing Management Questions 1 Explain Four st.pdfbabitasingh698417
 
Subject Data Structures and Algorithm Analysis for Python.pdf
Subject Data Structures and Algorithm Analysis for Python.pdfSubject Data Structures and Algorithm Analysis for Python.pdf
Subject Data Structures and Algorithm Analysis for Python.pdfbabitasingh698417
 
Sub Alternative research paradigm Do not copy from chatgp.pdf
Sub Alternative research paradigm  Do not copy from chatgp.pdfSub Alternative research paradigm  Do not copy from chatgp.pdf
Sub Alternative research paradigm Do not copy from chatgp.pdfbabitasingh698417
 
Study the following scenario and discuss and determine the i.pdf
Study the following scenario and discuss and determine the i.pdfStudy the following scenario and discuss and determine the i.pdf
Study the following scenario and discuss and determine the i.pdfbabitasingh698417
 
Su grupo de laboratorio debe identificar la clase de un cnid.pdf
Su grupo de laboratorio debe identificar la clase de un cnid.pdfSu grupo de laboratorio debe identificar la clase de un cnid.pdf
Su grupo de laboratorio debe identificar la clase de un cnid.pdfbabitasingh698417
 
Study figure 65 after reading the accompanying text Restat.pdf
Study figure 65 after reading the accompanying text Restat.pdfStudy figure 65 after reading the accompanying text Restat.pdf
Study figure 65 after reading the accompanying text Restat.pdfbabitasingh698417
 
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdf
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdfStun verilerinin satrlarda ve satr verilerinin stunlarda g.pdf
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdfbabitasingh698417
 
Study the following scenario and discuss and determine the a.pdf
Study the following scenario and discuss and determine the a.pdfStudy the following scenario and discuss and determine the a.pdf
Study the following scenario and discuss and determine the a.pdfbabitasingh698417
 
Students from 2011 showed that about 25 of all Vancouver re.pdf
Students from 2011 showed that about 25 of all Vancouver re.pdfStudents from 2011 showed that about 25 of all Vancouver re.pdf
Students from 2011 showed that about 25 of all Vancouver re.pdfbabitasingh698417
 
Study all the materials in Chapter 2 of an introduction to p.pdf
Study all the materials in Chapter 2 of an introduction to p.pdfStudy all the materials in Chapter 2 of an introduction to p.pdf
Study all the materials in Chapter 2 of an introduction to p.pdfbabitasingh698417
 
Students at a major university in Southern California are co.pdf
Students at a major university in Southern California are co.pdfStudents at a major university in Southern California are co.pdf
Students at a major university in Southern California are co.pdfbabitasingh698417
 
Students at a local university have the option of taking fre.pdf
Students at a local university have the option of taking fre.pdfStudents at a local university have the option of taking fre.pdf
Students at a local university have the option of taking fre.pdfbabitasingh698417
 
Student Learning Objectives 1 Identify the regions of the d.pdf
Student Learning Objectives 1 Identify the regions of the d.pdfStudent Learning Objectives 1 Identify the regions of the d.pdf
Student Learning Objectives 1 Identify the regions of the d.pdfbabitasingh698417
 
Student debt Financial aid staff at a local university are .pdf
Student debt Financial aid staff at a local university are .pdfStudent debt Financial aid staff at a local university are .pdf
Student debt Financial aid staff at a local university are .pdfbabitasingh698417
 
struct S double x int ip int a12 Assuming.pdf
struct S    double x   int ip   int a12    Assuming.pdfstruct S    double x   int ip   int a12    Assuming.pdf
struct S double x int ip int a12 Assuming.pdfbabitasingh698417
 
Stripetastic grasshoppers are black with stripes A red stri.pdf
Stripetastic grasshoppers are black with stripes A red stri.pdfStripetastic grasshoppers are black with stripes A red stri.pdf
Stripetastic grasshoppers are black with stripes A red stri.pdfbabitasingh698417
 

More from babitasingh698417 (20)

Sukis utility function is Where C1 is consumpt.pdf
Sukis utility function is     Where C1 is consumpt.pdfSukis utility function is     Where C1 is consumpt.pdf
Sukis utility function is Where C1 is consumpt.pdf
 
Subject Organizational Behaviour This is a long essay quest.pdf
Subject Organizational Behaviour This is a long essay quest.pdfSubject Organizational Behaviour This is a long essay quest.pdf
Subject Organizational Behaviour This is a long essay quest.pdf
 
successfully converting a 1point conversion is 10 The pro.pdf
successfully converting a 1point conversion is 10 The pro.pdfsuccessfully converting a 1point conversion is 10 The pro.pdf
successfully converting a 1point conversion is 10 The pro.pdf
 
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdf
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdfSubtopic 3 Demonstrate awareness of own cultural bias Stude.pdf
Subtopic 3 Demonstrate awareness of own cultural bias Stude.pdf
 
Subject Marketing Management Questions 1 Explain Four st.pdf
Subject Marketing Management Questions 1 Explain Four st.pdfSubject Marketing Management Questions 1 Explain Four st.pdf
Subject Marketing Management Questions 1 Explain Four st.pdf
 
Subject Data Structures and Algorithm Analysis for Python.pdf
Subject Data Structures and Algorithm Analysis for Python.pdfSubject Data Structures and Algorithm Analysis for Python.pdf
Subject Data Structures and Algorithm Analysis for Python.pdf
 
Sub Alternative research paradigm Do not copy from chatgp.pdf
Sub Alternative research paradigm  Do not copy from chatgp.pdfSub Alternative research paradigm  Do not copy from chatgp.pdf
Sub Alternative research paradigm Do not copy from chatgp.pdf
 
Study the following scenario and discuss and determine the i.pdf
Study the following scenario and discuss and determine the i.pdfStudy the following scenario and discuss and determine the i.pdf
Study the following scenario and discuss and determine the i.pdf
 
Su grupo de laboratorio debe identificar la clase de un cnid.pdf
Su grupo de laboratorio debe identificar la clase de un cnid.pdfSu grupo de laboratorio debe identificar la clase de un cnid.pdf
Su grupo de laboratorio debe identificar la clase de un cnid.pdf
 
Study figure 65 after reading the accompanying text Restat.pdf
Study figure 65 after reading the accompanying text Restat.pdfStudy figure 65 after reading the accompanying text Restat.pdf
Study figure 65 after reading the accompanying text Restat.pdf
 
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdf
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdfStun verilerinin satrlarda ve satr verilerinin stunlarda g.pdf
Stun verilerinin satrlarda ve satr verilerinin stunlarda g.pdf
 
Study the following scenario and discuss and determine the a.pdf
Study the following scenario and discuss and determine the a.pdfStudy the following scenario and discuss and determine the a.pdf
Study the following scenario and discuss and determine the a.pdf
 
Students from 2011 showed that about 25 of all Vancouver re.pdf
Students from 2011 showed that about 25 of all Vancouver re.pdfStudents from 2011 showed that about 25 of all Vancouver re.pdf
Students from 2011 showed that about 25 of all Vancouver re.pdf
 
Study all the materials in Chapter 2 of an introduction to p.pdf
Study all the materials in Chapter 2 of an introduction to p.pdfStudy all the materials in Chapter 2 of an introduction to p.pdf
Study all the materials in Chapter 2 of an introduction to p.pdf
 
Students at a major university in Southern California are co.pdf
Students at a major university in Southern California are co.pdfStudents at a major university in Southern California are co.pdf
Students at a major university in Southern California are co.pdf
 
Students at a local university have the option of taking fre.pdf
Students at a local university have the option of taking fre.pdfStudents at a local university have the option of taking fre.pdf
Students at a local university have the option of taking fre.pdf
 
Student Learning Objectives 1 Identify the regions of the d.pdf
Student Learning Objectives 1 Identify the regions of the d.pdfStudent Learning Objectives 1 Identify the regions of the d.pdf
Student Learning Objectives 1 Identify the regions of the d.pdf
 
Student debt Financial aid staff at a local university are .pdf
Student debt Financial aid staff at a local university are .pdfStudent debt Financial aid staff at a local university are .pdf
Student debt Financial aid staff at a local university are .pdf
 
struct S double x int ip int a12 Assuming.pdf
struct S    double x   int ip   int a12    Assuming.pdfstruct S    double x   int ip   int a12    Assuming.pdf
struct S double x int ip int a12 Assuming.pdf
 
Stripetastic grasshoppers are black with stripes A red stri.pdf
Stripetastic grasshoppers are black with stripes A red stri.pdfStripetastic grasshoppers are black with stripes A red stri.pdf
Stripetastic grasshoppers are black with stripes A red stri.pdf
 

Recently uploaded

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 

Recently uploaded (20)

Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 

Start from the sample code on the pdf Change struct to clas.pdf

  • 1. Start from the sample code on the pdf Change struct to class Make all the members private Add get_size , get_capacity and get_array methods Add remove , index_of and operator+ methods Add oprator< method, and together with other five ( > , >= , <= , == , != ) Complete and debug all the other methods in the sample code, such as insert Write some testing code in the main function Here is all the sample code that was provided in the pdf. Program1.cpp: int main() { int m = 9; float n = 2.7; int arr[6] = { 5,8,3,4,0,0 }; for ( int i = 5; i > 1; i-- ) arr[i] = arr[i-1]; arr[1] = 2; // arr: { 5,2,8,3,4,0 } return 0; } LinkedList.cpp: void LinkedList::append(int d) { Node* newNode = new Node(); newNode->data = d; tail->next = newNode; tail = newNode; length++; } void prepend(int d) { Node* newNode = new Node(); newNode->data = d; newNode->next = head->next; head->next = newNode; length++; } void LinkedList::print() { Node* curNode = head->next; while ( curNode )
  • 2. { cout << curNode->data << endl; curNode = curNode->next; } } void LinkedList::insert(int d) { Node* preNode = head; Node* curNode = head->next; while ( curNode ) { if ( curNode->data > d ) break; preNode = curNode; curNode = curNode->next; } Node* newNode = new Node(); newNode->data = d; preNode->next = newNode; newNode->next = curNode; length++; } int main() { LinkedList list; list.append(5); list.append(8); list.append(9); list.insert(6); list.print(); // output: 5 6 8 9 return 0; } Node.cpp: struct Node { int data; Node* next; }; int main() { Node* node_A = new Node(); node_A->data = 5; Node* node_B = new Node(); node_B->data = 3;
  • 3. Node* node_C = new Node(); node_C->data = 8; node_A->next = node_B; node_B->next = node_C; // ... LinkedList.h: struct LinkedList { Node* head = new Node(); Node* tail = head; int length = 0; void append(int d); void prepend(int d); void print(); void insert(int d); // ... };