diff --git a/C++/Program-30/README.md b/C++/Program-30/README.md new file mode 100644 index 00000000..a4dea477 --- /dev/null +++ b/C++/Program-30/README.md @@ -0,0 +1 @@ +Program to convert number in characters. diff --git a/C++/Program-30/program.c b/C++/Program-30/program.c new file mode 100644 index 00000000..0943f1d4 --- /dev/null +++ b/C++/Program-30/program.c @@ -0,0 +1,57 @@ +//Program to convert number in characters +#include +using namespace std; +int main() +{ +long int n,sum=0,r; +cout<<"Enter the Number= "; +cin>>n; +while(n>0) +{ +r=n%10; +sum=sum*10+r; +n=n/10; +} +n=sum; +while(n>0) +{ +r=n%10; +switch(r) +{ +case 1: +cout<<"one "; +break; +case 2: +cout<<"two "; +break; +case 3: +cout<<"three "; +break; +case 4: +cout<<"four "; +break; +case 5: +cout<<"five "; +break; +case 6: +cout<<"six "; +break; +case 7: +cout<<"seven "; +break; +case 8: +cout<<"eight "; +break; +case 9: +cout<<"nine "; +break; +case 0: +cout<<"zero "; +break; +default: +cout<<"tttt "; +break; +} +n=n/10; +} +} diff --git a/C++/See wifi pass.cpp b/C++/See wifi pass.cpp new file mode 100644 index 00000000..7eda1854 --- /dev/null +++ b/C++/See wifi pass.cpp @@ -0,0 +1,17 @@ +#include +#include +using namespace std; +string x; +int y; +int main() +{ +system("color e"); +cout<< ("\nsamz>\t"); +system("netsh wlan show profile"); +cout << ("WHICH ONE?--"); +string z = "netsh wlan show profile\t \""; +string n = "\"\tkey=clear"; +cin >> x; +z = z + x + n; +system(z.c_str()); +} diff --git a/C++/program_30/operator_overloading.cpp b/C++/program_30/operator_overloading.cpp new file mode 100644 index 00000000..8426dd45 --- /dev/null +++ b/C++/program_30/operator_overloading.cpp @@ -0,0 +1,50 @@ + +/* +cpp program for operator overloading +Author: Anil Kumar +Date modified:21-10-2021 +*/ + + +#include +using namespace std; + +class complex +{ +private: + float a,b; +public: + + void set(float x, float y){ + a=x; + b=y; + } + complex operator+(complex c){ + complex t; + t.a=a+c.a; + t.b=b+c.b; + return t; + } + complex operator-(){ + complex t; + t.a=-a; + t.b=-b; + return t; + } + + void display(){ + cout< +#includeR int main() { /*initialization */ + clrscr(); int n,i,j; - printf("enter the number of rows"); /*Input the number of rows */ - scanf("%d",&n); + printf("Enter the number of rows"); /*Input the number of rows */ + scanf("%d",&i); + print("Enter the number of columns"); + scanf("%d",&j); for(i=1;i<=n;i++) /*condition */ { for(j=1;j<=i;j++) - { - printf(" %d",j); /*output */ + { + printf("%d",n); /*output */ } printf("\n"); }return 0; diff --git a/C/program-8/program.c b/C/program-8/program.c index 0ce8b9cc..3a1c062c 100644 --- a/C/program-8/program.c +++ b/C/program-8/program.c @@ -1,7 +1,7 @@ #include int main() { - + clrscr(); int y,n,m,d,j; printf("enter the input"); scanf("%d",&n); @@ -12,4 +12,5 @@ int main() printf("year=%d",y); printf("months =%d",j); printf("days=%d",d); + getch(); } diff --git a/C/program-84/program.c b/C/program-84/program.c new file mode 100644 index 00000000..914722d6 --- /dev/null +++ b/C/program-84/program.c @@ -0,0 +1,16 @@ +#include +int main(){ +char str[100]; +int i=0; +printf("Enter any string:"); +gets(str); +//converting to uppercase +while(str[i]!= '\0'){ +if(str[i]>=97&&str[i]<=122){ + str[i]=str[i]-32; +} +i++; +} +printf("\nThe converted string is:%s", str); +return 0; +} diff --git a/C/program-84/program84.c b/C/program-84/program84.c new file mode 100644 index 00000000..6cc9bafb --- /dev/null +++ b/C/program-84/program84.c @@ -0,0 +1,182 @@ +#include +#include +#include +#include +#include +int gdriver=DETECT,gmode,x1=0,y1=0,k=0,c,a; +int bufx[150],bufy[150],dist=7,dspeed; +int rndx,rndy,tail=2,size,dash=0,score=0; +int choice; +char name[20]; +void gameover(); +void randomnumber(); +void checkcollision(int x1,int y1); +void checkcapture(int x1,int y1); +void move(); +void welcome(); +void statusbar(); +void record(); +void main(){ + // registerfarbgidriver(EGAVGA_driver_far); + initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi"); + size=tail; + welcome(); + re: + cleardevice(); + gotoxy(1,15); + printf("1 for easy\n2 for medium\n3 for hard\nEnter difficult:"); + scanf("%d",&choice); + switch(choice){ + case 1321: dspeed=200;break; + case 1: dspeed=160;break; + case 2: dspeed=60;break; + case 3: dspeed=20;break; + default: goto re; + }; + cleardevice(); + statusbar(); + while((c=getch())!='\033'){ + if (c=='\115'&&a!=2) a=1; + if (c=='\113'&&a!=1) a=2; + if (c=='\120'&&a!=4) a=3; + if (c=='\110'&&a!=3) a=4; + dash=0; + move(); + } +} +void move(){ + while(!kbhit()){ + k=++k%size; + //prints body + setfillstyle(1,10); + setcolor(0); + bar3d(x1,y1,x1+dist,y1+dist,0,0); + setfillstyle(0,0);//emptyfill + setcolor(0);//black border + bar3d(bufx[k],bufy[k],bufx[k]+dist,bufy[k]+dist,0,0);//erases tail + bufx[k]=x1; + bufy[k]=y1; + setcolor(15); + checkcapture(x1,y1); + if(a==1) x1=x1+dist;//if right + if(a==2) x1=x1-dist;//if left + if(a==3) y1=y1+dist;//if down + if(a==4) y1=y1-dist;//if up + checkcollision(x1,y1); + /*prints head the same if no direction is obtained, + prints new head if direction altered*/ + setfillstyle(1,2); + bar3d(x1,y1,x1+dist,y1+dist,0,0); + sound(300); + delay(dspeed); + nosound(); + delay(dspeed); + } +} + +void checkcollision(int x1,int y1){ + int i; + for(i=1;i<=size;i++){ + if((bufx[i]==x1)&&(bufy[i]==y1)) dash=1; + } + if((x1<0)||(x1>=400)||(y1<0)||(y1>400)) dash=1; + if(dash){ + delay(300); + gameover(); + } + statusbar(); +} + +void checkcapture(int x1,int y1){ + if((x1==rndx)&&(y1==rndy)){ + size++;score++; + sound(500); + delay(100); + randomnumber(); + } + setfillstyle(1,4); + setcolor(4); + bar3d(rndx,rndy,rndx+dist,rndy+dist,0,0); +} +void statusbar(){ + setcolor(15); + setcolor(14); + rectangle(0,0,400,410); + gotoxy(55,2); + printf("Score: %d",score); + gotoxy(55,5); + printf("Down: "); + putchar(31); + printf("\tUP"); + putchar(30); + gotoxy(55,6); + printf("RIGHT :"); + putchar(16); + printf("\tLEFT :"); + putchar(17); + gotoxy(55,7); + printf("Press esc to exit"); + settextstyle(4,0,3); + outtextxy(410,250,"KhwopaSnake"); +} +void randomnumber(){ + rndx=rand()%40*dist; + rndy=rand()%40*dist; + } +void gameover(){ + sound(400); + delay(200); + nosound(); + cleardevice(); + delay(400); + setcolor(12); + settextstyle(5,0,5); + outtextxy(230,200,"You Died!"); + gotoxy(25,23); + printf("%s scored %d ",name,score); + delay(500); + + record(); + fflush(stdin); + getch(); + exit(0); +} +void record(){ + char c; + FILE *info; + cleardevice(); + info=fopen("record.txt","a+"); + fprintf(info,"Playername:%-20s\tScore=%3d\n",name,score); + fclose(info); + + gotoxy(25,5); + printf("List of players\n"); + info=fopen("record.txt","r"); + do{ + putchar(c=getc(info));} + while(c!=EOF); + fclose(info); + printf("Press any key to exit"); + delay(5000); + } +void welcome(){ + gotoxy(25,25); + printf("Enter your name:"); + gets(name); + cleardevice(); + delay(100); + printf("Hello %s!",name); + delay(300); + setcolor(14); + settextstyle(10,0,3); + outtextxy(20,150,"Welcome to"); + delay(400); + outtextxy(250,150," khwopa"); + delay(300); + outtextxy(430,150," snake"); + delay(200); + printf("Press any key to continue...\n"); + printf("Dont eat yourself"); + getch(); + +} diff --git a/C/program-84/readme.md b/C/program-84/readme.md new file mode 100644 index 00000000..08de8520 --- /dev/null +++ b/C/program-84/readme.md @@ -0,0 +1 @@ +# snake game in c \ No newline at end of file diff --git a/C/program-86/README.md b/C/program-86/README.md new file mode 100644 index 00000000..1eaf01a7 --- /dev/null +++ b/C/program-86/README.md @@ -0,0 +1,3 @@ +program 86 + +C program to create and list of N fibonacci terms \ No newline at end of file diff --git a/C/program-86/fibonacci.c b/C/program-86/fibonacci.c new file mode 100644 index 00000000..a291947f --- /dev/null +++ b/C/program-86/fibonacci.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +main() { + + + + int a, b, aux, i, n; + + a = 0; + b = 1; + + printf("type a number: "); + scanf("%d", &n); + printf("\nFibonacci:\n"); + printf("%d\n", b); + + for(i = 0; i < n; i++) { + + aux = a + b; + a = b; + b = aux; + + printf("%d\n", aux); + } +} diff --git a/C/samzmaths.c b/C/samzmaths.c new file mode 100644 index 00000000..6ad4ca04 --- /dev/null +++ b/C/samzmaths.c @@ -0,0 +1,51 @@ +#include +#include + +int main() +{ + + system("color 4"); + printf("\nSamz math>\t"); + + + float a,d,p=1,i; + char operator; + + scanf("%f", &a); + scanf("%c", &operator); + scanf("%f", &d); + + for(i=1;i<=d;i++) + p=p*a; + + switch(operator) + { + + case '+': + printf("=%.2f\n\n", a+d); + break; + + case '-': + printf("=%.2f\n\n", a-d); + break; + + case '*': + printf("=%.2f\n\n", a*d); + break; + + case '/': + printf("=%.2f\n\n", a/d); + break; + + case '^': + printf("=%.2f\n\n", p); + break; + + + } + + + main(); + getch(); + +} diff --git a/Java/Program-21/K_Equal_Sum_Subset.java b/Java/Program-21/K_Equal_Sum_Subset.java new file mode 100644 index 00000000..ff93fa3e --- /dev/null +++ b/Java/Program-21/K_Equal_Sum_Subset.java @@ -0,0 +1,39 @@ +public class K_Equal_Sum_Subset { + //helper function + boolean helpInPartition(int nums[],boolean visited[],int start,int k,int currentSum,int targetSum) + { + //when there are no more subsets left to make + if(k==0) + return true; + if(currentSum>targetSum) + return false; + //if current sum equals target sum,we are left with k-1 subsets to make + if(currentSum==targetSum) + return helpInPartition(nums,visited,0,k-1,0,targetSum); + for(int j=start;j diff --git a/colorgame.py b/colorgame.py new file mode 100644 index 00000000..6bece3b6 --- /dev/null +++ b/colorgame.py @@ -0,0 +1,95 @@ +# Importing necessary packages +import random +import tkinter as tk +from tkinter import * +from tkinter import messagebox + +# Declaring global variables +timeleft = 60 +score = 0 + +#--- + +# Defining a function to create widgets for the game +def CreateWidgets(): + + instLabel = Label(root, text = "ENTER COLOR OF THE TEXT", + font = ('Helvetica',30),background = 'WHITE') + instLabel.grid(row = 0, column = 0, columnspan = 3, padx=5, pady=15) + + startButton = Button(root, text = "START GAME", width = 20, + font = ('Helvetica',15), command = StartGame, background='WHITE') + startButton.grid(row = 1, column = 0,padx = 5,pady = 15, columnspan = 3 ) + + root.timeLabel = Label(root, text="TIME LEFT : ", font = ('Helvetica',30), + background='WHITE') + root.timeLabel.grid(row=2, column=0, padx=5, pady=15) + + root.scoreLabel = Label(root, text="SCORE : "+str(score), + font = ('Helvetica',30),background = 'WHITE') + root.scoreLabel.grid(row=2, column=1, padx=5, pady=15) + + root.gameLabel = Label(root, font = ('Comic Sans MS',60),background = 'WHITE') + root.gameLabel.grid(row = 3, column = 0, padx=5, pady=15, columnspan = 2) + + root.answerEntry = Entry(root,width = 50, font =30,background = 'SILVER') + root.answerEntry.grid(row=4, column=0, padx=5, pady=15, columnspan = 2) + root.answerEntry.focus() + +#--- + +# Defining function to start the game +def StartGame(): + # Calling the above declared global variables + global timeleft, score + + # Checking if the timeleft is greater than 0. If yes do the following + if timeleft > 0: + # Decrementing the timeleft by 1 + timeleft -= 1 + # Displaying the time left in above created label for time left + root.timeLabel.config(text="TIME LEFT : " + str(timeleft)) + + # Creating a list of random colors + randomColor = ['RED', 'GREEN', 'BLUE', 'VIOLET', 'PINK', 'BROWN', 'BLACK'] + # Shuffling the list + random.shuffle(randomColor) + + # Selecting two colors from the shuffled randomColor list and setting + # One Color as Label Text and the Other Color as Font Color of the text + root.gameLabel.config(text=str(randomColor[0]), fg=randomColor[1]) + +#--- + + # Check if the user's input is equal to the Font Color of the text + if root.answerEntry.get().lower() == randomColor[1].lower(): + #If yes increment the score value by 1 + score += 1 + # Displaying the score + root.scoreLabel.config(text = "SCORE : "+str(score)) + # Clearing the user's entry + root.answerEntry.delete(0, END) + + # Calling the StartGame function again after 1 second + root.timeLabel.after(1000, StartGame) + + # If timeleft is equal to 0, then stop the game and display the users's score + else: + messagebox.showinfo("TIME UP !","YOUR SCORE IS : "+str(score)) + +#--- + +# Creating object of tk class +root = tk.Tk() + +# Setting the title and background color +# disabling the resizing property +root.title("PyColor Game") +root.configure(background = 'WHITE') +root.resizable(False, False) + +# Calling the CreateWidgets() function +CreateWidgets() + +# Defining infinite loop to run application +root.mainloop() diff --git a/currencyconvertor.py b/currencyconvertor.py new file mode 100644 index 00000000..7f4a3548 --- /dev/null +++ b/currencyconvertor.py @@ -0,0 +1,123 @@ +# PYTHON GUI TO CONVERT AMOUNT USER-INPUT FROM SELECTED CURRENCY VALUE TO SELECTED CURRENCY +# BASED ON REAL-TIME CURRECNY RATES +# +# GET YOUR FREE API KEY FROM : https://www.alphavantage.co + +# Importing necessary packages +import json +import requests +import tkinter as tk +from tkinter import * + +# Making a list of currencies. You can add more items (currencies) to the list +currencyList = ['US', 'INR', 'USD', 'AED', 'AUD', 'BHD', 'BRL', 'CAD', 'CNY', 'EUR', 'HKD','NRS' ] + +# Defining CreateWidgets() to create necessary widgets for the GUI +def CreateWidgets(): + inputAMT_Label = Label(root, text="ENTER AMOUNT TO CONVERT : ", bg="deepskyblue4") + inputAMT_Label.grid(row=1, column=0, padx=5, pady=5, columnspan=2) + inputAMT_Entry = Entry(root, width=14, textvariable=getAMT, bg="snow3", + font=('',20), justify="center") + inputAMT_Entry.grid(row=1, column=2, padx=5, pady=5) + + fromLabel = Label(root, text="FROM : ", bg="deepskyblue4") + fromLabel.grid(row=2, column=0, padx=5, pady=5) + root.fromList = Listbox(root, width=20, height=len(currencyList), exportselection=False, + bg="snow3") + root.fromList.grid(row=3, column=0, columnspan=2, padx = 5, pady = 5) + + # Populating the ListBox with the currencies values from currencyList + for c in range(len(currencyList)): + root.fromList.insert(c, currencyList[c]) + # Binding onFromCurrencySelect() event to the ListBox Widget + root.fromList.bind('<>', onFromCurrencySelect) + + toLabel = Label(root, text="TO : ", bg="deepskyblue4") + toLabel.grid(row=2, column=2, padx=5, pady=5) + root.toList = Listbox(root, width=20, height=len(currencyList), exportselection=False, + bg="snow3") + root.toList.grid(row=3, column=2, columnspan=2, padx=5, pady=5) + + # Populating the ListBox with the currencies values from currencyList + for c in range(len(currencyList)): + root.toList.insert(c, currencyList[c]) + # Binding onToCurrencySelect() event to the ListBox Widget + root.toList.bind('<>', onToCurrencySelect) + + convertButton = Button(root, text="CONVERT", width=25, command=Convert) + convertButton.grid(row=4, column=0, columnspan=3, padx=5, pady=5) + + exrateLabel = Label(root, text="EXCHANGE RATE : ",bg="deepskyblue4") + exrateLabel.grid(row=5, column=0, padx=5, pady=5, columnspan=2) + root.exrate = Label(root, width=14, font=('',20), bg='snow3', justify="center") + root.exrate.grid(row=5, column=2, padx=5, pady=5) + + outputLabel = Label(root, text="CONVERTED AMOUNT:", bg="deepskyblue4") + outputLabel.grid(row=6, column=0,padx=5, pady=5, columnspan=2) + root.outputAMT = Label(root, width=14, font=('',20), bg="snow3", justify="center") + root.outputAMT.grid(row=6, column=2, padx=5, pady=5, columnspan=2) + +# Defining onFromCurrencySelect() to fetch the currency selected from the ListBox +# and store it fromCurrecny variable +def onFromCurrencySelect(evt): + fromCurrencySelection = root.fromList.get(root.fromList.curselection()) + fromCurrency.set(fromCurrencySelection) + +# Defining onToCurrencySelect() to fetch the currency selected from the ListBox +# and store it toCurrency variable +def onToCurrencySelect(evt): + toCurrencySelection = root.toList.get(root.toList.curselection()) + toCurrency.set(toCurrencySelection) + +# Defining Convert() function for converting the curreny +def Convert(): + # Fetching & storing user-inputs in resepective variables + # Converting user-input amount which is a string into float type + inputAmt = float(getAMT.get()) + f_Currency = fromCurrency.get() + t_Currency = toCurrency.get() + + # Storing the API Key from https://www.alphavantage.co/ + apiKey = "YOUR API KEY" + # Storing the base URL + baseURL = r"https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE" + # Storing the complete URL + inputURL = baseURL+"&from_currency="+f_Currency+"&to_currency="+t_Currency+"&apikey="+apiKey + + # Sending the request to URL & Fetching and Storing the response in response variable + response = requests.get(inputURL) + # Returning the JSON object of the response and storing it in result + result = response.json() + print(json.dumps(result, indent=2)) + + # Getting the exchange rate (Required Information) + exchangeRate = float(result["Realtime Currency Exchange Rate"]['5. Exchange Rate']) + + # Displaying exchange rate in respective label after rounding to 2 decimal places + root.exrate.config(text=str(round(exchangeRate, 2))) + + # Calculating the converted amount and rounding the decimal to 2 places + calculateAmt = round(inputAmt * exchangeRate, 2) + # Displaying the converted amount in the respective label + root.outputAMT.config(text=str(calculateAmt)) + +# Creating object of tk class +root = tk.Tk() + +# Setting title, background color & size of tkinter window +# & disabling the resizing property +root.geometry("450x400") +root.resizable(False, False) +root.title("PythonCurrenyConverter") +root.config(bg = "deepskyblue4") + +# Creating tkinter variables +getAMT = StringVar() +fromCurrency = StringVar() +toCurrency = StringVar() + +# Calling the CreateWidgets() function +CreateWidgets() + +# Defining infinite loop to run application +root.mainloop() \ No newline at end of file