Thursday, August 21, 2025

ARRAY ADT

#include <iostream>
#include<algorithm>
 using namespace std;
 class ArrayADT{
int *arr;
int capacity;
int size;
public:
ArrayADT(int cap){
    capacity=cap;
arr=new int[capacity];

cout<<" you created an array with capacity "<<cap<<endl;
size=0;
}
 void insert(int value) {
        if (size == capacity) {
            cout << "Array is full! Cannot insert.\n";
            return;
        }
        arr[size++] = value;
       
    }
     void Insert(int value,int index){
        if(index<0||index>size){
            cout<<" invalid index\n ";
        }
        arr[index]=value;
     }
     void Delete(int index){
     }
    void print(){
        for(int i=0;i<size;i++){
            cout<<arr[i]<<endl;
        }
        cout<<" size of array is "<<size<<endl;
    }
    void SortAscending(){
sort(arr,arr+size);
}
void SortDescending(){
sort(arr,arr+size,greater<int>());
}

int binarySearch(int n){
    int low=0;
    int high=size-1;
    int mid;
    while(low<=high){
mid=low+(high-low)/2;
if(arr[mid]==n){
    return mid;
}
if(arr[mid]<n){
    low=mid+1;
}
else
high=mid-1;

    }
    return -1;
}
 };
 int main() {
ArrayADT A(5);
A.insert(3);
A.insert(7);
A.insert(4);
A.print();
A.Insert(5,0);
A.print();
 return 0;
 }

Monday, August 18, 2025

GCD

 #include <iostream>

 using namespace std;
 void gcd(int n1,int n2){
    int gcd;
   while(n1>0&&n2>0){
    if(n1>n2)n1=n1%n2;
    else n2=n2%n1;
   }
   if(n1==0)gcd=n2;
   gcd=n1;
   cout<<gcd<<endl;
 }
 int main() {
 //Write your C++ code here
 cout << "Hello, World!" << endl;
 gcd(6,12);
 return 0;
 }

Sunday, August 17, 2025

PALINDROME

 #include <iostream>

#include<bits/stdc++.h>
 using namespace std;
 bool f(int i,string&s){
    if(i>=s.size()/2)return true;
   if(s[i]!=s[s.size()-i-1])return false;
   return f(i+1,s);
 }
 int main() {
 string s="msdam";
 cout<<f(0,s);
 return 0;
 }

SWAP

 #include <iostream>

#include<bits/stdc++.h>
 using namespace std;
 void f(int i,int arr[],int n){
    if(i>=n/2)return;
    swap(arr[i],arr[n-i-1]);
    f(i+1,arr,n);
 }
 int main() {
 int n;
 cin>>n;
 int arr[n];
 for(int i=0;i<n;i++)cin>>arr[i];
 f(0,arr,n);
 return 0;
 }

Saturday, August 16, 2025

CASINO GAME

 #include <iostream>

#include<cstdlib>
#include<ctime>
 using namespace std;
 void rules(){
    cout<<"\n\t WELCOME TO NUMBER GUESSING GAME ";
    cout<<" \n\t 1. YOU CHOOSE A NUMBE BETWEEN  1 AND 10 ";
cout<<"\n\t2. IF YOU GUESS THE CORRECT NUMBER ,YOU WILL GET 10X BET ";
cout<<"\n3. 3. IF YOU GUESS WRONG , YOU WILL LOSE ALL YOUR BET ";
 }
 int main() {
    string name;
    int balance;
    int bettingAmount;
    int guess;
    int dice;
    srand(time(0));
    cout<<" WELCOME TO CASINO "<<endl;
    cout<<" ENTER YOUR NAME "<<endl;
    cin>>name;
    cout<<" enter your balance"<<endl;
    cin>>balance;
 return 0;
 }

LOGIN PAGE

 #include <iostream>

 using namespace std;
 class registration{
    public:
string userName;
string passWord;
registration(){
cout<<" Enter your username to register "<<endl;
cin>>userName;
cout<<" Enter your password to register "<<endl;
cin>>passWord;
}
 };
 class login:public registration{
public:
string a;
string b;
login(){
cout<<" enter username to login "<<endl;
cin>>a;
cout<<"enter password to login "<<endl;
cin>>b;
if(a==userName && b==passWord){
    cout<<" welcome sir "<<endl;
}else{
    cout<<" Invalid user id or password "<<endl;
}
}

 };

 int main() {
    login l;
 return 0;
 }

Monday, August 11, 2025

MORSE CODE

#include <iostream>
#include <map>
#include <string>
using namespace std;

class MorseCode {
    map<string, string> morse;

public:
    MorseCode() {
        morse.emplace(".-", "A");
        morse.emplace("-...", "B");
        morse.emplace("-.-.", "C");
        morse.emplace("-..", "D");
        morse.emplace(".", "E");
        morse.emplace("..-.", "F");
        morse.emplace("--.", "G");
        morse.emplace("....", "H");
        morse.emplace("..", "I");
        morse.emplace(".---", "J");
        morse.emplace("-.-", "K");
        morse.emplace(".-..", "L");
        morse.emplace("--", "M");
        morse.emplace("-.", "N");
        morse.emplace("---", "O");
        morse.emplace(".--.", "P");
        morse.emplace("--.-", "Q");
        morse.emplace(".-.", "R");
        morse.emplace("...", "S");
        morse.emplace("-", "T");
        morse.emplace("..-", "U");
        morse.emplace("...-", "V");
        morse.emplace(".--", "W");
        morse.emplace("-..-", "X");
        morse.emplace("-.--", "Y");
        morse.emplace("--..", "Z");
    }

    string decode(const string &code) {
        auto it = morse.find(code);
        if (morse.find(code)!= morse.end()) {
            return it->second;
        } else {
            return "?";
        }
    }
};
class reverseMorse:public virtual MorseCode{












};

int main() {
    MorseCode m;
    cout << m.decode("--") << endl; // M
    cout << m.decode(".-") << endl; // A
    cout << m.decode("....") << endl; // H
    cout << m.decode("invalid") << endl; // ?

    return 0;
}

MergeSort

  #include < iostream >   using namespace std ;   void merge ( vector < int >& n , int low , int mid , int high ){   ...