Posts

225: Test post

#include < iostream > using namespace std ; class Node { private :     int value ;     Node * nextNode ;     Node * prevNode ; public :     Node () { value = 0 , nextNode = nullptr, prevNode = nullptr; }     Node ( int value ) { this-> value = value , nextNode = nullptr, prevNode = nullptr; }     void setValue ( int value ) { this-> value = value ; }     void setNextNode ( Node * nextNode ) { this-> nextNode = nextNode ; }     void setPrevNode ( Node * prevNode ) { this-> prevNode = prevNode ; }     int getValue () { return value ; }     Node * getNextNode () { return nextNode ; }     Node * getPrevNode () { return prevNode ; } }; class DoublyLinkedList { private :     int size ;     Node * headNode ;     Node * currentNode ; public :     DoublyLinkedLi...

224: Recursions

Image
1. Calculate base ^ pow through recursions: #include < iostream > using namespace std ; int power ( int base , int pow ) {     if ( pow == 0 )     {         return 1 ;     }     int prevAns = power ( base , pow - 1 );     return base * prevAns ; } int main () {     int base = 2 ;     int pow = 5 ;     cout << base << ' ^ ' << pow << " : " << power ( base , pow ) << endl ; } /* 2 * 2 * 2 * 2 * 2 base ^ pow = base * (base ^ power - 1) */   2: Calculate factorial through recursion: #include < iostream > using namespace std ; int factorial ( int num ) {     if ( num == 1 )     {         return 1 ;     }     int prev = factorial ( num - 1 );     return num * prev ;     // or return num * factorial(num - 1) } int ma...

223: Algorithm to generate array of random numbers entirely different from each other

  // algorithm to generate array of random numbers entirely different from each other #include < iostream > #include < ctime > using namespace std ; int getNumber ( int size ) {     int random = rand () % size + 1 ;     return random ; } int * random ( int size ) {     int * temp = new int [ size ];     int num = 0 ;     while ( num < size )     {         int number = getNumber ( size );         bool isInArray = false;         for ( int i = 0 ; i < num ; i ++)         {             if ( temp [ i ] == number )             {                 isInArray = true;                 break ;             }       ...

222: Build an employee management system that dynamically manages an employee database.Create a class representing an employee with attributes like name, ID, and salary.Implement a dynamic array to store and manipulate employee records, including adding new employees, removing employees, and displaying the details of all employees.

  // Build an employee management system that dynamically manages an employee database.Create a class // representing an employee with attributes like name, ID, and salary.Implement a dynamic array to store and // manipulate employee records, including adding new employees, removing employees, and displaying the // details of all employees. #include < iostream > using namespace std ; class Employee { private :     string name , ID ;     int salary ; public :     Employee ( string n = "" , string id = "" , int s = 0 ) { name = n , ID = id , salary = s ; }     void setName ( string n = "" ) { name = n ; }     void setID ( string id = "" ) { ID = id ; }     void setSalary ( int s = 0 ) { salary = s ; }     string getName () { return name ; }     string getID () { return ID ; }     int getSalary () { return salary ; } ...