# Destructor

C++ Programming

C++ Programming

- Introduction
- Hello World
- Calculation
- Grade Calculation
- Multiplication Table
- Even Odd
- Armstrong Number
- Prime Composite
- Perfect Number
- Fibonacci Series
- Factorial
- Recursive Factorial
- Palindrome Number
- Palindrome String
- Random Alphanumeric
- GCD
- LCM
- Function Overloading
- Class Object
- Constructor
- Destructor
- Constructor Overloading
- Copy Constructor
- Array in Class
- Matrix Addition
- Matrix Multiplication
- Object Array
- Inheritance
- Public Inheritance
- Multiple Inheritance
- Multilevel Inheritance
- Virtual Inheritance
- Swapping
- Object Pointer
- Runtime Polymorphism
- Write File
- Copy File
- Read File
- File Pointer
- Binary File
- Word Break
- String Interleave
- Template Class
- Template Function
- Virtual Template
- Linear Search
- STL Binary Search
- STL Sort
- Bubble Sort
- Insertion Sort
- Selection Sort
- Quick Sort
- Merge Sort
- STL Heap Sort
- STL Merge
- List
- Singly Linked list
- Doubly Linked list
- Stack
- Queue
- Double Ended Queue
- Binary Tree
- Map
- Multimap
- STL Min Max

/* Count Number of Coins/Notes */
#include<iostream>
using namespace std;
class counter {
int thousand, fivehundred, hundred, fifty, twenty, ten, five, two, one, remaining;
public:
/* Constructor prototype declaration */
counter(int);
void display() {
cout << "Number of Coins/Notes" << endl;
cout << "Thousand - " << thousand << endl;
cout << "Five Hundred - " << fivehundred << endl;
cout << "Hundred - " << hundred << endl;
cout << "Fifty - " << fifty << endl;
cout << "Twenty - " << twenty << endl;
cout << "Ten - " << ten << endl;
cout << "Five - " << five << endl;
cout << "Two - " << two << endl;
cout << "One - " << one << endl;
}
/* Destructor for class 'counter' */
~counter() {
cout << "Object of the class destroyed!" << endl;
}
};
/* Constructor definition outside class */
counter :: counter(int amount) {
thousand = fivehundred = hundred = fifty = twenty = ten = five = two = one = remaining = 0;
thousand = amount / 1000;
remaining = amount - thousand * 1000;
fivehundred = remaining / 500;
remaining -= fivehundred * 500;
hundred = remaining / 100;
remaining -= hundred * 100;
fifty = remaining / 50;
remaining -= fifty * 50;
twenty = remaining / 20;
remaining -= twenty * 20;
ten = remaining / 10;
remaining -= ten * 10;
five = remaining / 5;
remaining -= five * 5;
two = remaining / 2;
remaining -= two * 2;
one = remaining;
}
int main() {
int amount;
cout << "Enter your amount to count Coins/Notes:" << endl;
cin >> amount;
/* Constructor called explicitly */
counter ctr = counter(amount);
ctr.display();
return 0;
}
/****** Output ******/
Enter your amount to count Coins/Notes:

51230

Number of Coins/Notes

Thousand - 51

Five Hundred - 0

Hundred - 2

Fifty - 0

Twenty - 1

Ten - 1

Five - 0

Two - 0

One - 0

Learn more about Destructor in C++