SlideShare a Scribd company logo
1 of 7
Download to read offline
With the following class, ArrayBag, and BagInterface:
#ifndef _BAG_INTERFACE
#define _BAG_INTERFACE
#include
using namespace std;
template
class BagInterface
{
public:
/** Gets the current number of entries in this bag.
@return The integer number of entries currently in the bag. */
virtual int getCurrentSize() const = 0;
/** Sees whether this bag is empty.
@return True if the bag is empty, or false if not. */
virtual bool isEmpty() const = 0;
/** Adds a new entry to this bag.
@post If successful, newEntry is stored in the bag and
the count of items in the bag has increased by 1.
@param newEntry The object to be added as a new entry.
@return True if addition was successful, or false if not. */
virtual bool add(const ItemType& newEntry) = 0;
/** Removes one occurrence of a given entry from this bag,
if possible.
@post If successful, anEntry has been removed from the bag
and the count of items in the bag has decreased by 1.
@param anEntry The entry to be removed.
@return True if removal was successful, or false if not. */
virtual bool remove(const ItemType& anEntry) = 0;
/** Removes all entries from this bag.
@post Bag contains no items, and the count of items is 0. */
virtual void clear() = 0;
/** Counts the number of times a given entry appears in bag.
@param anEntry The entry to be counted.
@return The number of times anEntry appears in the bag. */
virtual int getFrequencyOf(const ItemType& anEntry) = 0;
/** Tests whether this bag contains a given entry.
@param anEntry The entry to locate.
@return True if bag contains anEntry, or false otherwise. */
virtual bool contains(const ItemType& anEntry) = 0;
/** Empties and then fills a given vector with all entries that
are in this bag.
@return A vector containing all the entries in the bag. */
virtual vector toVector() const = 0;
virtual void display() const = 0;
virtual ItemType getElement(int index) const = 0;
}; // end BagInterface
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////
#ifndef _ARRAY_BAG
#define _ARRAY_BAG
#include "BagInterface.h"
template
class ArrayBag : public BagInterface
{
private:
static const int DEFAULT_CAPACITY = 6; // Small size to test for a full bag
ItemType items[DEFAULT_CAPACITY]; // Array of bag items
int itemCount; // Current count of bag items
int maxItems; // Max capacity of the bag
// Returns either the index of the element in the array items that
// contains the given target or -1, if the array does not contain
// the target.
int getIndexOf(const ItemType& target);
public:
ArrayBag();
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType& newEntry);
bool remove(const ItemType& anEntry);
void clear();
bool contains(const ItemType& anEntry);
int getFrequencyOf(const ItemType& anEntry);
vector toVector() const;
void display() const;
ItemType getElement(int index) const;
}; // end ArrayBag
template
ArrayBag::ArrayBag() : itemCount(0), maxItems(DEFAULT_CAPACITY)
{
} // end default constructor
template
int ArrayBag::getCurrentSize() const
{
return itemCount;
} // end getCurrentSize
template
bool ArrayBag::isEmpty() const
{
return itemCount == 0;
} // end isEmpty
template
bool ArrayBag::add(const ItemType& newEntry)
{
bool hasRoomToAdd = (itemCount < maxItems);
if (hasRoomToAdd)
{
items[itemCount] = newEntry;
itemCount++;
} // end if
return hasRoomToAdd;
} // end add
/*
// STUB
template
bool ArrayBag::remove(const ItemType& anEntry)
{
return false; // STUB
} // end remove
*/
template
bool ArrayBag::remove(const ItemType& anEntry)
{
int locatedIndex = getIndexOf(anEntry);
bool canRemoveItem = !isEmpty() && (locatedIndex > -1);
if (canRemoveItem)
{
itemCount--;
items[locatedIndex] = items[itemCount];
} // end if
return canRemoveItem;
} // end remove
/*
// STUB
template
void ArrayBag::clear()
{
// STUB
} // end clear
*/
template
void ArrayBag::clear()
{
itemCount = 0;
} // end clear
template
int ArrayBag::getFrequencyOf(const ItemType& anEntry)
{
int frequency = 0;
int curIndex = 0; // Current array index
while (curIndex < itemCount)
{
if (items[curIndex] == anEntry)
{
frequency++;
} // end if
curIndex++; // Increment to next entry
} // end while
return frequency;
} // end getFrequencyOf
template
bool ArrayBag::contains(const ItemType& anEntry)
{
return getIndexOf(anEntry) > -1;
} // end contains
/* ALTERNATE 1: First version
template
bool ArrayBag::contains(const ItemType& target) const
{
return getFrequencyOf(target) > 0;
} // end contains
// ALTERNATE 2: Second version
template
bool ArrayBag::contains(const ItemType& anEntry) const
{
bool found = false;
int curIndex = 0; // Current array index
while (!found && (curIndex < itemCount))
{
if (anEntry == items[curIndex])
{
found = true;
} // end if
curIndex++; // Increment to next entry
} // end while
return found;
} // end contains
*/
template
vector ArrayBag::toVector() const
{
vector bagContents;
for (int i = 0; i < itemCount; i++)
bagContents.push_back(items[i]);
return bagContents;
} // end toVector
// private
template
int ArrayBag::getIndexOf(const ItemType& target)
{
bool found = false;
int result = -1;
int searchIndex = 0;
// If the bag is empty, itemCount is zero, so loop is skipped
while (!found && (searchIndex < itemCount))
{
if (items[searchIndex] == target)
{
found = true;
result = searchIndex;
}
else
{
searchIndex++;
} // end if
} // end while
return result;
} // end getIndexOf
template
void ArrayBag::display() const
{
for (int count = 0; count < getCurrentSize(); count++) {
cout << items[count] << ",";
}//end for
cout << endl;
} //end display
template
ItemType ArrayBag::getElement(int index) const {
return items[index];
}
#endif
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////
1.Define a class named Term that has two attributes:
-coef: Hold the coefficient int data type of the term.
-exp: Hold the exponent int data type of the term.
-Overload the Stream Extraction/ Insertion) operators ( >>,<<).
-Overload the binary operator (+=) that sums two terms.
2.Define a class named Polynomial that has one attribute:
-poly: Hold the polynomial of ArrayBag data type.
-Overload the binary operator ( + ) to Compute the sum of two polynomials.
-Perform the rest of the operations described in the problem.
3. Create a polynomial with five terms.

More Related Content

Similar to With the following class, ArrayBag, and BagInterface#ifndef _BAG_.pdf

Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdftxkev
 
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdfBANSALANKIT1077
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
 
Write a class that implements the BagInterface. BagInterface should .pdf
Write a class that implements the BagInterface.  BagInterface should .pdfWrite a class that implements the BagInterface.  BagInterface should .pdf
Write a class that implements the BagInterface. BagInterface should .pdffashiongallery1
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdffashiongallery1
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdfaarifi9988
 
#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdfaashwini4
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfvicky309441
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxcurwenmichaela
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docxajoy21
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdfNicholasflqStewartl
 
template-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdftemplate-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdfashokadyes
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming LanguageAnıl Sözeri
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docxVictorXUQGloverl
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxalanfhall8953
 
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdfImplement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdfinfo961251
 
A generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfA generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfADITIHERBAL
 
A generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfA generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfadhityafashion
 
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docx
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList    se.docxSinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList    se.docx
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docxjennifer822
 

Similar to With the following class, ArrayBag, and BagInterface#ifndef _BAG_.pdf (20)

Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdfCharacter.cpphpp givenCharacter.cpp#include Character.hp.pdf
Character.cpphpp givenCharacter.cpp#include Character.hp.pdf
 
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
#include -algorithm- #include -cstdlib- #include -iostream- #include -.pdf
 
Please help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdfPlease help me to make a programming project I have to sue them today- (1).pdf
Please help me to make a programming project I have to sue them today- (1).pdf
 
Write a class that implements the BagInterface. BagInterface should .pdf
Write a class that implements the BagInterface.  BagInterface should .pdfWrite a class that implements the BagInterface.  BagInterface should .pdf
Write a class that implements the BagInterface. BagInterface should .pdf
 
Chapt03
Chapt03Chapt03
Chapt03
 
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdfUsing c++Im also using a the ide editor called CodeLiteThe hea.pdf
Using c++Im also using a the ide editor called CodeLiteThe hea.pdf
 
Complete code in Java The hashtable you'll be making will use String.pdf
Complete code in Java   The hashtable you'll be making will use String.pdfComplete code in Java   The hashtable you'll be making will use String.pdf
Complete code in Java The hashtable you'll be making will use String.pdf
 
#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf#include stdafx.h#include iostreamusing namespace std;cl.pdf
#include stdafx.h#include iostreamusing namespace std;cl.pdf
 
The hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdfThe hashtable youll be making will use Strings as the keys and Obje.pdf
The hashtable youll be making will use Strings as the keys and Obje.pdf
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Write a program to find the number of comparisons using the binary se.docx
 Write a program to find the number of comparisons using the binary se.docx Write a program to find the number of comparisons using the binary se.docx
Write a program to find the number of comparisons using the binary se.docx
 
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
Given the following class in Java-  public class ThreeTenDynArray-T- {.pdfGiven the following class in Java-  public class ThreeTenDynArray-T- {.pdf
Given the following class in Java- public class ThreeTenDynArray-T- {.pdf
 
template-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdftemplate-typename T- class Array { public- ---------------------------.pdf
template-typename T- class Array { public- ---------------------------.pdf
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
 
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docxweek4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
week4_srcArrayMethods.javaweek4_srcArrayMethods.javapackage ed.docx
 
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdfImplement the sequence class from Section 3.2 of the textbook. The d.pdf
Implement the sequence class from Section 3.2 of the textbook. The d.pdf
 
A generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfA generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdf
 
A generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdfA generic queue is a general queue storage that can store an.pdf
A generic queue is a general queue storage that can store an.pdf
 
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docx
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList    se.docxSinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList    se.docx
SinglyLinkedListPseudoCode.txtCLASS SinglyLinkedList se.docx
 

More from amikoenterprises

Within MySQL Workbench, create a new table. This table will be used .pdf
Within MySQL Workbench, create a new table. This table will be used .pdfWithin MySQL Workbench, create a new table. This table will be used .pdf
Within MySQL Workbench, create a new table. This table will be used .pdfamikoenterprises
 
Within the unethical leadership presentation, I talked a lot about t.pdf
Within the unethical leadership presentation, I talked a lot about t.pdfWithin the unethical leadership presentation, I talked a lot about t.pdf
Within the unethical leadership presentation, I talked a lot about t.pdfamikoenterprises
 
Write a C program to create two user-defined functions; first functi.pdf
Write a C program to create two user-defined functions; first functi.pdfWrite a C program to create two user-defined functions; first functi.pdf
Write a C program to create two user-defined functions; first functi.pdfamikoenterprises
 
Write a C# program that demonstrate your multi-level inheritance und.pdf
Write a C# program that demonstrate your multi-level inheritance und.pdfWrite a C# program that demonstrate your multi-level inheritance und.pdf
Write a C# program that demonstrate your multi-level inheritance und.pdfamikoenterprises
 
With reference to the above case, please answer all of the followi.pdf
With reference to the above case, please answer all of the followi.pdfWith reference to the above case, please answer all of the followi.pdf
With reference to the above case, please answer all of the followi.pdfamikoenterprises
 
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdf
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdfWR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdf
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdfamikoenterprises
 
without using truth table Unit I Logic and Proofs Question 1. Is.pdf
without using truth table  Unit I Logic and Proofs Question 1. Is.pdfwithout using truth table  Unit I Logic and Proofs Question 1. Is.pdf
without using truth table Unit I Logic and Proofs Question 1. Is.pdfamikoenterprises
 
Working with Apache Web ServerTime Required 35 minutesObjective.pdf
Working with Apache Web ServerTime Required 35 minutesObjective.pdfWorking with Apache Web ServerTime Required 35 minutesObjective.pdf
Working with Apache Web ServerTime Required 35 minutesObjective.pdfamikoenterprises
 
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdf
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdfWilliam Short is chief executive officer (CEO) of Benton Memorial Ho.pdf
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdfamikoenterprises
 
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdf
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdfWord facilita el formato de texto usando negrita, cursiva y subrayad.pdf
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdfamikoenterprises
 
wo populations of beetles have different reproductive organs that ar.pdf
wo populations of beetles have different reproductive organs that ar.pdfwo populations of beetles have different reproductive organs that ar.pdf
wo populations of beetles have different reproductive organs that ar.pdfamikoenterprises
 
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdf
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdfWittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdf
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdfamikoenterprises
 
Write the necessary SQL Queries for the following functions.A,Addi.pdf
Write the necessary SQL Queries for the following functions.A,Addi.pdfWrite the necessary SQL Queries for the following functions.A,Addi.pdf
Write the necessary SQL Queries for the following functions.A,Addi.pdfamikoenterprises
 
Write the necessary SQL Queries for the following functions.A. Add.pdf
Write the necessary SQL Queries for the following functions.A. Add.pdfWrite the necessary SQL Queries for the following functions.A. Add.pdf
Write the necessary SQL Queries for the following functions.A. Add.pdfamikoenterprises
 
Write the class named Student which has the following data members.pdf
Write the class named Student  which has the following data members.pdfWrite the class named Student  which has the following data members.pdf
Write the class named Student which has the following data members.pdfamikoenterprises
 
Write program in C language to sort the given array using merge sort.pdf
Write program in C language to sort the given array using merge sort.pdfWrite program in C language to sort the given array using merge sort.pdf
Write program in C language to sort the given array using merge sort.pdfamikoenterprises
 
Write notes on the following areas as related to tax investigations .pdf
Write notes on the following areas as related to tax investigations .pdfWrite notes on the following areas as related to tax investigations .pdf
Write notes on the following areas as related to tax investigations .pdfamikoenterprises
 
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdf
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdfWrite it in Assembly codeWrite it in Assembly codeWrite it in As.pdf
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdfamikoenterprises
 
Write MATLAB code to solve this summation in general, where you can .pdf
Write MATLAB code to solve this summation in general, where you can .pdfWrite MATLAB code to solve this summation in general, where you can .pdf
Write MATLAB code to solve this summation in general, where you can .pdfamikoenterprises
 
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdf
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdfWilliam es due�o de un solo barco. El barco vale 200 millones de d�l.pdf
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdfamikoenterprises
 

More from amikoenterprises (20)

Within MySQL Workbench, create a new table. This table will be used .pdf
Within MySQL Workbench, create a new table. This table will be used .pdfWithin MySQL Workbench, create a new table. This table will be used .pdf
Within MySQL Workbench, create a new table. This table will be used .pdf
 
Within the unethical leadership presentation, I talked a lot about t.pdf
Within the unethical leadership presentation, I talked a lot about t.pdfWithin the unethical leadership presentation, I talked a lot about t.pdf
Within the unethical leadership presentation, I talked a lot about t.pdf
 
Write a C program to create two user-defined functions; first functi.pdf
Write a C program to create two user-defined functions; first functi.pdfWrite a C program to create two user-defined functions; first functi.pdf
Write a C program to create two user-defined functions; first functi.pdf
 
Write a C# program that demonstrate your multi-level inheritance und.pdf
Write a C# program that demonstrate your multi-level inheritance und.pdfWrite a C# program that demonstrate your multi-level inheritance und.pdf
Write a C# program that demonstrate your multi-level inheritance und.pdf
 
With reference to the above case, please answer all of the followi.pdf
With reference to the above case, please answer all of the followi.pdfWith reference to the above case, please answer all of the followi.pdf
With reference to the above case, please answer all of the followi.pdf
 
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdf
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdfWR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdf
WR Grace Company fue fundada por, s�, un hombre llamado WR Grace. Er.pdf
 
without using truth table Unit I Logic and Proofs Question 1. Is.pdf
without using truth table  Unit I Logic and Proofs Question 1. Is.pdfwithout using truth table  Unit I Logic and Proofs Question 1. Is.pdf
without using truth table Unit I Logic and Proofs Question 1. Is.pdf
 
Working with Apache Web ServerTime Required 35 minutesObjective.pdf
Working with Apache Web ServerTime Required 35 minutesObjective.pdfWorking with Apache Web ServerTime Required 35 minutesObjective.pdf
Working with Apache Web ServerTime Required 35 minutesObjective.pdf
 
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdf
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdfWilliam Short is chief executive officer (CEO) of Benton Memorial Ho.pdf
William Short is chief executive officer (CEO) of Benton Memorial Ho.pdf
 
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdf
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdfWord facilita el formato de texto usando negrita, cursiva y subrayad.pdf
Word facilita el formato de texto usando negrita, cursiva y subrayad.pdf
 
wo populations of beetles have different reproductive organs that ar.pdf
wo populations of beetles have different reproductive organs that ar.pdfwo populations of beetles have different reproductive organs that ar.pdf
wo populations of beetles have different reproductive organs that ar.pdf
 
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdf
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdfWittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdf
Wittes Tasty Fishes� Wittes Tasty Fishes� is an aquaculture compan.pdf
 
Write the necessary SQL Queries for the following functions.A,Addi.pdf
Write the necessary SQL Queries for the following functions.A,Addi.pdfWrite the necessary SQL Queries for the following functions.A,Addi.pdf
Write the necessary SQL Queries for the following functions.A,Addi.pdf
 
Write the necessary SQL Queries for the following functions.A. Add.pdf
Write the necessary SQL Queries for the following functions.A. Add.pdfWrite the necessary SQL Queries for the following functions.A. Add.pdf
Write the necessary SQL Queries for the following functions.A. Add.pdf
 
Write the class named Student which has the following data members.pdf
Write the class named Student  which has the following data members.pdfWrite the class named Student  which has the following data members.pdf
Write the class named Student which has the following data members.pdf
 
Write program in C language to sort the given array using merge sort.pdf
Write program in C language to sort the given array using merge sort.pdfWrite program in C language to sort the given array using merge sort.pdf
Write program in C language to sort the given array using merge sort.pdf
 
Write notes on the following areas as related to tax investigations .pdf
Write notes on the following areas as related to tax investigations .pdfWrite notes on the following areas as related to tax investigations .pdf
Write notes on the following areas as related to tax investigations .pdf
 
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdf
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdfWrite it in Assembly codeWrite it in Assembly codeWrite it in As.pdf
Write it in Assembly codeWrite it in Assembly codeWrite it in As.pdf
 
Write MATLAB code to solve this summation in general, where you can .pdf
Write MATLAB code to solve this summation in general, where you can .pdfWrite MATLAB code to solve this summation in general, where you can .pdf
Write MATLAB code to solve this summation in general, where you can .pdf
 
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdf
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdfWilliam es due�o de un solo barco. El barco vale 200 millones de d�l.pdf
William es due�o de un solo barco. El barco vale 200 millones de d�l.pdf
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
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
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
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
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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...
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . 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...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
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
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

With the following class, ArrayBag, and BagInterface#ifndef _BAG_.pdf

  • 1. With the following class, ArrayBag, and BagInterface: #ifndef _BAG_INTERFACE #define _BAG_INTERFACE #include using namespace std; template class BagInterface { public: /** Gets the current number of entries in this bag. @return The integer number of entries currently in the bag. */ virtual int getCurrentSize() const = 0; /** Sees whether this bag is empty. @return True if the bag is empty, or false if not. */ virtual bool isEmpty() const = 0; /** Adds a new entry to this bag. @post If successful, newEntry is stored in the bag and the count of items in the bag has increased by 1. @param newEntry The object to be added as a new entry. @return True if addition was successful, or false if not. */ virtual bool add(const ItemType& newEntry) = 0; /** Removes one occurrence of a given entry from this bag, if possible. @post If successful, anEntry has been removed from the bag and the count of items in the bag has decreased by 1. @param anEntry The entry to be removed. @return True if removal was successful, or false if not. */ virtual bool remove(const ItemType& anEntry) = 0; /** Removes all entries from this bag. @post Bag contains no items, and the count of items is 0. */ virtual void clear() = 0; /** Counts the number of times a given entry appears in bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ virtual int getFrequencyOf(const ItemType& anEntry) = 0;
  • 2. /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if bag contains anEntry, or false otherwise. */ virtual bool contains(const ItemType& anEntry) = 0; /** Empties and then fills a given vector with all entries that are in this bag. @return A vector containing all the entries in the bag. */ virtual vector toVector() const = 0; virtual void display() const = 0; virtual ItemType getElement(int index) const = 0; }; // end BagInterface #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////// #ifndef _ARRAY_BAG #define _ARRAY_BAG #include "BagInterface.h" template class ArrayBag : public BagInterface { private: static const int DEFAULT_CAPACITY = 6; // Small size to test for a full bag ItemType items[DEFAULT_CAPACITY]; // Array of bag items int itemCount; // Current count of bag items int maxItems; // Max capacity of the bag // Returns either the index of the element in the array items that // contains the given target or -1, if the array does not contain // the target. int getIndexOf(const ItemType& target); public: ArrayBag(); int getCurrentSize() const; bool isEmpty() const; bool add(const ItemType& newEntry); bool remove(const ItemType& anEntry); void clear();
  • 3. bool contains(const ItemType& anEntry); int getFrequencyOf(const ItemType& anEntry); vector toVector() const; void display() const; ItemType getElement(int index) const; }; // end ArrayBag template ArrayBag::ArrayBag() : itemCount(0), maxItems(DEFAULT_CAPACITY) { } // end default constructor template int ArrayBag::getCurrentSize() const { return itemCount; } // end getCurrentSize template bool ArrayBag::isEmpty() const { return itemCount == 0; } // end isEmpty template bool ArrayBag::add(const ItemType& newEntry) { bool hasRoomToAdd = (itemCount < maxItems); if (hasRoomToAdd) { items[itemCount] = newEntry; itemCount++; } // end if return hasRoomToAdd; } // end add /* // STUB template bool ArrayBag::remove(const ItemType& anEntry) {
  • 4. return false; // STUB } // end remove */ template bool ArrayBag::remove(const ItemType& anEntry) { int locatedIndex = getIndexOf(anEntry); bool canRemoveItem = !isEmpty() && (locatedIndex > -1); if (canRemoveItem) { itemCount--; items[locatedIndex] = items[itemCount]; } // end if return canRemoveItem; } // end remove /* // STUB template void ArrayBag::clear() { // STUB } // end clear */ template void ArrayBag::clear() { itemCount = 0; } // end clear template int ArrayBag::getFrequencyOf(const ItemType& anEntry) { int frequency = 0; int curIndex = 0; // Current array index while (curIndex < itemCount) { if (items[curIndex] == anEntry)
  • 5. { frequency++; } // end if curIndex++; // Increment to next entry } // end while return frequency; } // end getFrequencyOf template bool ArrayBag::contains(const ItemType& anEntry) { return getIndexOf(anEntry) > -1; } // end contains /* ALTERNATE 1: First version template bool ArrayBag::contains(const ItemType& target) const { return getFrequencyOf(target) > 0; } // end contains // ALTERNATE 2: Second version template bool ArrayBag::contains(const ItemType& anEntry) const { bool found = false; int curIndex = 0; // Current array index while (!found && (curIndex < itemCount)) { if (anEntry == items[curIndex]) { found = true; } // end if curIndex++; // Increment to next entry } // end while return found; } // end contains */ template
  • 6. vector ArrayBag::toVector() const { vector bagContents; for (int i = 0; i < itemCount; i++) bagContents.push_back(items[i]); return bagContents; } // end toVector // private template int ArrayBag::getIndexOf(const ItemType& target) { bool found = false; int result = -1; int searchIndex = 0; // If the bag is empty, itemCount is zero, so loop is skipped while (!found && (searchIndex < itemCount)) { if (items[searchIndex] == target) { found = true; result = searchIndex; } else { searchIndex++; } // end if } // end while return result; } // end getIndexOf template void ArrayBag::display() const { for (int count = 0; count < getCurrentSize(); count++) { cout << items[count] << ","; }//end for cout << endl;
  • 7. } //end display template ItemType ArrayBag::getElement(int index) const { return items[index]; } #endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////// 1.Define a class named Term that has two attributes: -coef: Hold the coefficient int data type of the term. -exp: Hold the exponent int data type of the term. -Overload the Stream Extraction/ Insertion) operators ( >>,<<). -Overload the binary operator (+=) that sums two terms. 2.Define a class named Polynomial that has one attribute: -poly: Hold the polynomial of ArrayBag data type. -Overload the binary operator ( + ) to Compute the sum of two polynomials. -Perform the rest of the operations described in the problem. 3. Create a polynomial with five terms.