Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading

Container Classes and Integrators

Data Structures using C ++ Program

Container Class is designed to hold and organize multiple instances of another class.

Container Classes and Integrators

Definition : Container Class is designed to hold and organize multiple instances of another class.

Container class has predefined behavior and a well known interface.

Various operations associated with container class are

1. Create an empty container

2. Insert an object inside the container

3. Remove an object from the container

4. Find the number of objects in the container

5. Sort the objects within the container

There are two varieties of container classes ‒ value containers and reference containers. The value containers store the actual values of the objects whereas the reference containers contain the references or pointers to the other objects.

In C++, normally the container holds only one type data. The containers usually does not allow to mix the objects of different data types.

 

Example of Array Container Class

#include<iostream>

using namespace std;

class bag

{

public:

   void insert(int);

   void show();

   int size();

   bag(){count=0;}

private:

   int data[20];

   int count;

};

void bag::insert(int val)

{

   data[count]=val;

   count++;

}

void bag show()

{

   for(int i=0;i<count;i++)

   cout<<""<<data[i];

}

int bag:size()

{

   return count:

}

void main()

{

   bag obj

   cout<<"\n The items in Container are...\n";

   obj insert(10);

   obj insert(20);

   obj.insert(30);

   obj.show();

   cout<<"\n The size of container is: "<<obj.size();

   cout<<"\n The items in Container are...\n";

   obj.insert(40);

   obj.insert(50);

   obj.show();

   cout<<"\n The size of container is: "<<<obj.size();

   cout<<"\n";

}

Output

The items in Container are...

10 20 30

The size of container is: 3

The items in Container are...

10 20 30 40 50

The size of container is: 5

 

Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading : Tag: Data Structure, C++, C Programing : Data Structures using C ++ Program - Container Classes and Integrators


Data Structures using C PlusPlus: Chapter 1: Data Abstraction and Overloading



Under Subject


Data Structures using CPlusPlus

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Electron Devices

EC25C01 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures using CPlusPlus

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Circuits and Network Analysis

EC25C02 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Engineering Drawing - Laboratory

ME25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Data Structures using CPlusPlus - Laboratory

CS25C05 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Devices and Circuits Laboratory

EC25C03 2nd Semester ECE Dept | 2025 Regulation | 2nd Semester 2025 Regulation