Saturday, August 9, 2025

AMAZON ORDER

#include <iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<unordered_map>
 using namespace std;
 class inventory{
    public:
map<string,int>m;
inventory(){
m.emplace("TV",100);
m.emplace("HDTV",75);
m.emplace("HP LAPTOP",45);
m.emplace("PLAYSTATION 5",30);
m.emplace("NINTENDO SWITCH 2",60);
}
 string toUpper(string str) {
        transform(str.begin(), str.end(), str.begin(), ::toupper);
        return str;
 }
void order( ){
    while(true){
    cout<<" what do you want to order ?"<<endl;
    string s;
    cin >> ws; // remove leading spaces
        getline(cin, s); // allow spaces in product names
        s = toUpper(s);
        if(s=="EXIT"){
            cout<<" thank you for shopping "<<endl;
            exit(0);
        }
    if(m.find(s)!=m.end()){
    cout<<" your order is "<<s<<endl;
    }
    else{
        cout<<" your order is invalid "<<endl;
    }
cout<<" enter the quantity of your order "<<endl;
int q;
cin>>q;
if(q<=0){
    cout<<" invalid quantity "<<endl;
    return;
}
if(q>m[s]){
    cout<<"Sorry we have "<<m[s]<<" stock only ";
    return;
}
m[s] -= q;
            cout << "Quantity of your order is " << q << endl;
            cout << "Remaining quantity is " << m[s] << endl;

}
}
 };
 int main() {
    inventory I;
    I.order();
 return 0;
 }

Friday, August 8, 2025

STUDENT DATABASE

 #include <iostream>

#include<vector>
#include<list>
#include<map>
#include<unordered_map>
using namespace std;
template<class T1,class T2>
class students{
    public:
    int n;
    map<T1, T2> m;
    students(){
    cout<<" enter the no of students "<<endl;
    cin>>n;
    }
    void input(){
    for(int i=0;i<n;i++){
        T1 name;
        T2 value;
        cin>>name>>value;
        m[name]=value;
    }
    }
    void display(){
        for(auto&p:m){
            cout<<" name of student is "<<p.first<<endl;
             cout<<" ID of student is "<<p.second<<endl;
        }
    }
};
 
 int main() {
 students<string,int>s;
 s.input();
 s.display();
 return 0;
 }

Wednesday, August 6, 2025

CURRENCY CONVERTER 2.0

 #include <iostream>

#include<map>
#include<string>
using namespace std;
class currency{
    map<pair<string,string>,double>converter;

public:
currency(){
    converter[{"USD", "INR"}] = 83.12;
        converter[{"INR", "USD"}] = 0.012;
        converter[{"USD", "KWD"}] = 0.31;
        converter[{"KWD", "USD"}] = 3.25;
        converter[{"GBP", "INR"}] = 105.6;
        converter[{"INR", "GBP"}] = 0.0094;
        converter[{"AED", "USD"}] = 0.27;
        converter[{"USD", "AED"}] = 3.67;
}
void convert(){
    string fromCurrency,toCurrency;
    float amount;
    cout<<"\navailable currencies:USD,INR,KWD,GBP,AED\n";
    cout<<" enter from currency code "<<endl;
    cin>>fromCurrency;
    cout<<" enter to currency code "<<endl;
    cin>>toCurrency;
    cout<<" enter amount "<<endl;
    cin>>amount;
    pair<string,string>key={fromCurrency,toCurrency};
    if(converter.find(key)!=converter.end()){
        float rate=converter[key];
        float result=rate*amount;
        cout << amount << " " << fromCurrency << " = " << result << " " << toCurrency << endl;
    }else {
            cout << "Conversion rate not found.\n";
        }      
}
};
 
 int main() {

 currency c;
    char choice;

    do {
        c.convert();
        cout << "\nDo you want to convert again? (y/n): ";
        cin >> choice;
    } while (choice == 'y' || choice == 'Y');

    cout << "Thank you for using the Currency Converter.\n";
    return 0;
}
 
 

Tuesday, August 5, 2025

CURRENCY CONVERTER IN C++

#include <iostream>

 using namespace std;
 class currency{
    float Amount;
int choice;
    public:
currency(float c  ){
    Amount=c;
    cout<<" the money in your account is "<<Amount<<endl;
    if(Amount<0){
cout<<"invalid amount entered"<<endl;
exit(0);
}
}

void selection(){
    cout<<" select your currency "<<endl;
    cout<<" available currencies are -: \n 1.Dollar\n 2.rupee\n 3.pound\n4.Dinar\n5.Dirham\n ";
    cin>>choice;
    if(choice==1){
        cout<<" you have "<<Amount<<" dollars "<<endl;
        DOLLAR();
    }
    if(choice==2){
        cout<<" you have "<<Amount<<" rupees "<<endl;
        RUPEES();
    }
    if(choice==3){
        cout<<" you have "<<Amount<<" pounds "<<endl;
        POUNDS();
    }
    if(choice==4){
        cout<<" you have "<<Amount<<" dinars "<<endl;
        DINARS();
    }
    if(choice==5){
        cout<<" you have "<<Amount<<" darahim "<<endl;
        DIRHAM();
    }
}
void DOLLAR(){
    int a;
    cout<<" select currency to convert into \n1.Rupees\n2.Pounds\n3.Dinar\n4.Dirham\n";
    cin>>a;
    if(a==1){
        cout<<" you have "<<Amount*87.81<<" rupees "<<endl;
    }
    if(a==2){
        cout<<" you have "<<Amount*0.75<<" pounds "<<endl;
    }
    if(a==3){
        cout<<" you have "<<Amount*0.306<<" dinar "<<endl;
    }
if(a==4){
        cout<<" you have "<<Amount*3.67<<" dirham "<<endl;
    }
}
void RUPEES(){
    int b;
    cout<<" select currency to convert into \n1.Dollar\n2.Pounds\n3.Dinar\n4.Dirham\n";
    cin>>b;
    if(b==1){
        cout<<" you have "<<Amount*0.011<<" dollars "<<endl;
    }
    if(b==2){
        cout<<" you have "<<Amount*0.0086<<" pounds "<<endl;
    }
    if(b==3){
        cout<<" you have "<<Amount*0.0035<<" dinar "<<endl;
    }
if(b==4){
        cout<<" you have "<<Amount*0.042<<" dirham "<<endl;
    }
}
void POUNDS(){
    int c;
    cout<<" select currency to convert into \n1.Dollars\n2.Rupees\n3.Dinar\n4.Dirham\n";
    cin>>c;
    if(c==1){
        cout<<" you have "<<Amount*1.33<<" dollars "<<endl;
    }
    if(c==2){
        cout<<" you have "<<Amount*116.82<<" rupees "<<endl;
    }
    if(c==3){
        cout<<" you have "<<Amount*0.41<<" dinar "<<endl;
    }
if(c==4){
        cout<<" you have "<<Amount*4.88<<" dirham "<<endl;
    }
}
void DINARS(){
    int d;
    cout<<" select currency to convert into \n1.Dollars\n2.Rupees\n3.Pounds\n4.Dirham\n";
    cin>>d;
    if(d==1){
        cout<<" you have "<<Amount*3.27<<" dollars "<<endl;
    }
    if(d==2){
        cout<<" you have "<<Amount*287.29<<" rupees "<<endl;
    }
    if(d==3){
        cout<<" you have "<<Amount*2.46<<" pounds "<<endl;
    }
if(d==4){
        cout<<" you have "<<Amount*12.02<<" dirham "<<endl;
    }}
void  DIRHAM(){
    int e;
    cout<<" select currency to convert into \n1.Dollar\n2.Rupees\n3.Pounds\n4.Dinar\n";
    cin>>e;
    if(e==1){
        cout<<" you have "<<Amount*0.27<<" dollar "<<endl;
    }
    if(e==2){
        cout<<" you have "<<Amount*23.91<<" rupees "<<endl;
    }
    if(e==3){
        cout<<" you have "<<Amount*0.20<<" pounds "<<endl;
    }
if(e==4){
        cout<<" you have "<<Amount*0.083<<" dirham "<<endl;
    }
}
 };
 int main() {
    currency A(5);
    A.selection();

 return 0;
 
 }

Thursday, July 31, 2025

HYBRID CALCULATOR WITH TEMPLATES(C++)

#include <iostream>
#include<cmath>
 using namespace std;
 template <class T>
  class calculator{//making base class
public:
T sum(T a,T b){
return a+b;
}
T difference(T a,T b){
   
    return a-b;
}
T product(T a,T b){
    return a*b;
}
T quotient(T a,T b){
   
    return a/b;
}
T remainder(T a,T b){
   
return a%b;
}
 virtual void display(T a,T b){//displaying main arithemetic operations-addition,subtraction,division and multiplication
    cout<<" the sum of two numbers "<<a<<" and " <<b<<" is "<<sum(a,b)<<endl;
    cout<<" the difference of two numbers " <<a<<" and "<< b<< " is "<<difference(a,b)<<endl;
    cout<<" the product of two numbers "<<a<< " and "<< b<<" is "<<product(a,b)<<endl;
    cout<<" the quotient of two numbers "<<a<<" and "<< b<<" is  "<<quotient(a,b)<<endl;
    cout<<" the remainder of two numbers "<<a<<" and "<< b<<" is "<<remainder(a,b)<<endl;
}
 };
 template <class T>
 class scientificCalcualtor:virtual public calculator<T>{//making derived class
public:
T square(T a){
    return pow(a,2);
}
T cube(T a){
    return pow(a,3);
}
T squareroot(T a){
return sqrt(a);
}
void display(T a){//displaying sceintific operations implemented using cmath
cout<<" the square of "<<a<<" is "<<square(a)<<endl;
cout<<" the cube of " <<a<<" is "<<cube(a)<<endl;
cout<<" the squareroot of "<<a<< " is "<<squareroot(a)<<endl;
}
void display(T a,T b){//drawing from base class
    calculator<T>::display(a,b);
}

 };
 template <class T>
 class hybridCalc:virtual public calculator<T>,virtual public scientificCalcualtor<T>{//multilevelinheritance
    public:
void display(T a,T b){//using display function from display classes
calculator<T>::display(a,b);
scientificCalcualtor<T>::display(a);
scientificCalcualtor<T>::display(b);

}



 };
 
 int main(){
hybridCalc<int> H;
H.display(76,45);

 return 0;
 }

Sunday, July 27, 2025

CALCULATOR(WITH TEMPLATES) IN C++

 #include <iostream>

 using namespace std;
 template <class T>
class sum{
T c;
    public:
 sum (T a,T b){
     c=a+b;
   
}
T display(){
    cout<<" value of c is "<<c<<endl;
    T d=c*c;
    cout<<"Value of c's square is "<<d<<endl;
    return d ;
 }
};
template <class T>
class calculator{
T a;
T b;
public:
T sum(T c,T d){
    a=c;
    b=d;
    return a+b;
}
T difference(T c,T d){
    a=c;
    b=d;
    return a-b;
}
T product(T c,T d){
    a=c;
    b=d;
    return a*b;
}
T quotient(T c,T d){
    a=c;
    b=d;
    return a/b;
}

void display(T c,T d){
    a=c;
    b=d;
    cout<<" the sum of a and b is "<<sum(c,d)<<endl;
    cout<<" the difference of a and b is "<<difference(c,d)<<endl;
    cout<<" the product of a and b is "<<product(c,d)<<endl;
    cout<<" the quotient of a and b is "<<quotient(c,d)<<endl;
}
};
 int main() {
 calculator<double> c;
 c.display(5,6);
 return 0;
 }

TEXT ADVENTURE GAME(IN JAVA)





import java.util.*; //importing for user input




public class GAME2 {


    static Scanner s = new Scanner(System.in);


    static int playerHp;


    static String playerName;


    static String playerWeapon;


    static Random rc = new Random();


    static int monsterHp = rc.nextInt(6) + 5; // Random HP between 5 and 10


    static int siverRing;




    public static void main(String[] args) {


        playerSetup();


        TownGate(); // Start game at town gate


    }




    public static void playerSetup() {


        playerHp = 10;


        playerWeapon = "AXE"; // Remove extra spaces for string matching


        System.out.println("YOUR HP IS " + playerHp);


        System.out.println("YOUR WEAPON IS " + playerWeapon);


        System.out.println("ENTER YOUR NAME PLEASE");


        playerName = s.nextLine();


        System.out.println("Hello, " + playerName + ". Let's start your adventure!");


    }


// starting of game


    public static void TownGate() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You are at the town gate.");


        System.out.println("A guard is in front of the gate.");


        System.out.println("What do you want to do?");


        System.out.println("1. Talk to the guard");


        System.out.println("2. Attack the guard");


        System.out.println("3. Leave");




        int choice = s.nextInt();


        s.nextLine();




        if (choice == 1) {


            System.out.println("Guard: Hello there, stranger. So, your name is " + playerName + "?\nSorry, we cannot let a stranger enter our town.");


            TownGate();


        } else if (choice == 2) {


            playerHp -= 1;


            System.out.println("Guard: What the hell?! Don't be stupid!");


            System.out.println("The guard hits you hard. You lose 1 HP.");


            System.out.println("Your HP: " + playerHp);


            TownGate();


        } else if (choice == 3) {


            CrossRoad();


        } else {


            TownGate();


        }


    }


//At crossroad


    public static void CrossRoad() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You are at a crossroad.");


        System.out.println("1. Go north");


        System.out.println("2. Go south");


        System.out.println("3. Go east");


        System.out.println("4. Go west");




        int option = s.nextInt();


        s.nextLine(); // consume newline




        if (option == 1) {


            north();


        } else if (option == 2) {


            south();


        } else if (option == 3) {


            east();


        } else if (option == 4) {


            west();


        } else {


            CrossRoad();


        }


    }


//going to north and hp retaining mechanism


    public static void north() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You find a peaceful river. You rest and drink some water.");


        if (playerHp < 10) {


            playerHp += 1;


            System.out.println("You have recovered 1 HP. Your HP is now " + playerHp);


        } else {


            System.out.println("Your HP is already full.");


        }


        System.out.println("1. Go back to the crossroad");


        System.out.println("2. Stay here ");


        int choice = s.nextInt();


        s.nextLine();


        if (choice == 1) {


            CrossRoad();


        } else {


            north();


        }


    }


//go to south and visit town again


    public static void south() {


        TownGate();


    }


//finding new weapon in east 


    public static void east() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You walked into a forest and found a Long Sword!");


        playerWeapon = "Long Sword";


        System.out.println("Your new weapon is: " + playerWeapon);


        System.out.println("1. Go back to the crossroad");


        int choice = s.nextInt();


        s.nextLine();


        if (choice == 1) {


            CrossRoad();


        } else {


            east();


        }


    }


//fighting enemy in west


    public static void west() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You encounter a goblin!");


        System.out.println("1. Fight");


        System.out.println("2. Run");




        int choice = s.nextInt();


        s.nextLine();


        if (choice == 1) {


            fight();


        } else if (choice == 2) {


            CrossRoad();


        } else {


            west();


        }


    }




    public static void fight() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("Your HP: " + playerHp);


        System.out.println("Goblin HP: " + monsterHp);


        System.out.println("1. Attack");


        System.out.println("2. Run");




        int choice = s.nextInt();


        s.nextLine();


        if (choice == 1) {


            attack();


        } else if (choice == 2) {


            CrossRoad();


        } else {


            fight();


        }


    }


//attack and fighting mechanism


    public static void attack() {


        int weaponDamage = 0;


        if (playerWeapon.equals("AXE")) {


            weaponDamage = rc.nextInt(5) + 1; // 1-5


        } else if (playerWeapon.equals("Long Sword")) {


            weaponDamage = rc.nextInt(6) + 4; // 4-9

        }




        System.out.println("You attack the goblin and deal " + weaponDamage + " damage.");


        monsterHp -= weaponDamage;




        if (monsterHp < 1) {


            win();


            return;


        }




        System.out.println("Goblin HP is now: " + monsterHp);




        // Monster counterattacks


        int monsterDamage = rc.nextInt(5) + 1;


        playerHp -= monsterDamage;


        System.out.println("The goblin attacks you back and deals " + monsterDamage + " damage.");


        System.out.println("Your HP is now: " + playerHp);


        s.nextLine();




        if (playerHp < 1) {


            lose();


        } else {


            fight();


        }


    }


//on defeating goblin


    public static void win() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You defeated the goblin!");


        System.out.println("He dropped a ring");


        System.out.println("You got a siver ring");


        siverRing=1;


        System.out.println("1.go south to town");


        int choice=s.nextInt();


        if(choice==1) {


        Town();


        }else {


        win();


        }


        monsterHp = rc.nextInt(6) + 5; // Reset for another fight if needed


        CrossRoad();


    }




    


//on getting defeated by goblin


public static void lose() {


        System.out.println("\n-----------------------------------------\n");


        System.out.println("You have been defeated by the goblin...");


        System.out.println("GAME OVER");


        System.exit(0);


    }//after defeating goblin and arriving at town


public static void Town() {


System.out.println("\n-----------------------------------------\n");


System.out.println("you go to town and go to guard ");


System.out.println("Would you like to:\n1.show your ring\n2.leave");


int choice=s.nextInt();


if(choice==1) {


TownElder();


}


else if(choice==2) {


CrossRoad();


}else {


Town();


}



System.out.println("\n-----------------------------------------\n");




}




public static void TownElder() {


System.out.println("You show silver ring to guard \n he looks surprised!!!!!!!!!!!!!!!");


System.out.println("He takes you directly to TownELder,te head of town");


System.out.println("TownElder sees your ring and says\n\"this ring is very imprtant for us as it was crafted by our ancestors\nand it has been preserved by us for generations");


System.out.println("Recently,a very powerful goblin stole it from us and we could not get it back");


System.out.println("We would like you to become out town's protector,so say,what was your name again?" +playerName+ " yeah,so "+playerName+" ,would you like to be our protector");


System.out.println("what would you do?\n1.become the protector\n2.leave the town");


int choice=s.nextInt();


if(choice==1) {


ending();



}


else if(choice==2) {


CrossRoad();


}


else {


TownElder();


}


System.out.println("\n-----------------------------------------\n");




}


//ending of game


public static void ending() {


System.out.println("So,from here now you will be given your title according to your choice,choose one");


System.out.println("Choose one from them-:\n1.The Silver Lion of Valor\n2.Knight of the Eternal Oath\n3.Warden of the Broken Sigil\n4.The Crimson Bladebearer\n5.Champion of the Hollow Crown");


String playerTitle="";


int choice=s.nextInt();


switch(choice) {


case 1:playerTitle="The Silver Lion of Valor";


break;


case 2:playerTitle="Knight of the Eternal Oath";


break;


case 3:playerTitle="Warden of the Broken Sigil";


break;


case 4:playerTitle="The Crimson Bladebearer";


break;


case 5:playerTitle="Champion of the Hollow Crown";


break;


default:


System.out.println("Could not decide one,huh!,well I have a name for you,you get the title of Spadidus,meaning\"descending from sparda\" ,the warrior who founded this town  ");


playerTitle="Spadidus";


}


System.out.println("So,now you hold the title of "+playerTitle);


System.out.println("congratulations,you won " +playerName+ " with the title of "+playerTitle);


System.out.println("GAME OVER");


System.exit(0);


}


}

MergeSort

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