diff --git a/C++/C++Template.cpp b/C++/C++Template.cpp index 07b27b68..cd8bacf1 100644 --- a/C++/C++Template.cpp +++ b/C++/C++Template.cpp @@ -32,6 +32,11 @@ class Maths float result=num1/num2; return result; } + T modulo() + { + T result = num1%num2; + return result; + } }; @@ -55,4 +60,4 @@ int main() < +using namespace std; + vector fizzBuzz(int n) { + vectorans; + for(int i=1;i<=n;i++) + { + if((i)%15==0) + { + string str="FizzBuzz"; + ans.push_back(str); + } + else if((i)%5==0){ + string str="Buzz"; + ans.push_back(str); + } + else if((i)%3==0){ + string str="Fizz"; + ans.push_back(str); + } + else + ans.push_back(to_string(i)); + } + return ans; + } +int main() +{ + vector answer= fizzBuzz(5); +} \ No newline at end of file diff --git a/C++/Maximum_Subarray_Sum.cpp b/C++/Maximum_Subarray_Sum.cpp new file mode 100644 index 00000000..20975833 --- /dev/null +++ b/C++/Maximum_Subarray_Sum.cpp @@ -0,0 +1,24 @@ +//Program to find subarray with largest sum +#include +#include + +using namespace std; + +int main() { + int n; + cin >> n; + + vector nums(n); + for(int i = 0; i < n; i++) + cin >> nums[i]; + + int best = 0, sum = 0; + for(int i = 0; i < n; i++) { + sum = max(nums[i], sum + nums[i]); + best = max(best, sum); + } + + cout << best << endl; + + return 0; +} \ No newline at end of file diff --git a/C++/Program to reverse number.cpp b/C++/Program to reverse number.cpp index 0beeaa1b..ea69a3e4 100644 --- a/C++/Program to reverse number.cpp +++ b/C++/Program to reverse number.cpp @@ -1,16 +1,21 @@ #include using namespace std; -int main() -{ -int n, reverse=0, rem; -cout<<"Enter a number: "; -cin>>n; +int reverseNum(int n){ +int reverse=0,rem; while(n!=0) { rem=n%10; reverse=reverse*10+rem; n/=10; - } - cout<<"Reversed Number: "<>n; + + cout<<"Reversed Number: "< using namespace std; +void swapWithoutTemp(int &a,int &b){ +a=a*b; //a=50 (5*10) +b=a/b; //b=5 (50/10) +a=a/b; //a=10 (50/5) +} int main() { int a=5, b=10; cout<<"Before swap a= "<2){ - sum=first+second; - first=second; - second=sum; - cout< +#include using namespace std; -typedef long long ll; -int main(void) +int main() { - int n; - cin >> n; - for (int i = n - 1; i >= 0; i--) - { - for (int j = n - 1; j >= i; j--) - { - cout << "$"; - } - for (int j = 0; j < 2 * i; j++) - { - cout << " "; - } - for (int j = n - 1; j >= i; j--) - { - cout << "$"; - } - cout << endl; - } - for (int i = 0; i < n; i++) - { - for (int j = n - 1; j >= i; j--) - { - cout << "$"; - } - for (int j = 0; j < 2 * i; j++) - { - cout << " "; - } - for (int j = n - 1; j >= i; j--) - { - cout << "$"; - } - cout << endl; - } + int r,i,j; + cout<<"Enter no. of rows: "; + cin>>r; + + for(i=1;i<=r;i++) + { + for(j=1;j<=i;j++) + cout<<"*"; + for(j=1;j<=2*(r-i);j++) + cout<<" "; + for(j=1;j<=i;j++) + cout<<"*"; + cout<<"\n"; + } + for(i=r;i>=1;i--) + { + for(j=1;j<=i;j++) + cout<<"*"; + for(j=1;j<=2*(r-i);j++) + cout<<" "; + for(j=1;j<=i;j++) + cout<<"*"; + cout<<"\n"; + } + return 0; } - -// 0123 -// @ @ 0 -// @@ -// @@@@@@ 1 diff --git a/C++/patterns/rectangle.cpp b/C++/patterns/rectangle.cpp index 0f4c05f2..9ad2a713 100644 --- a/C++/patterns/rectangle.cpp +++ b/C++/patterns/rectangle.cpp @@ -3,22 +3,24 @@ // $$$$ // $$$$ // $$$$ - -#include +#include +#include using namespace std; -typedef long long ll; - -int main(void) +int main() { - int len, bre; - cin >> len; - cin >> bre; - for (int i = 0; i < len; i++) - { - for (int j = 0; j < bre; j++) - { - cout << "$"; - } - cout << endl; + int rows,columns,i,j; + cout<<"Enter the number of rows: "; + cin>>rows; + + cout<<"Enter the number of columns: "; + cin>>columns; + + for(i=1; i<=rows; i++){ + for (j=1; j<=columns; j++){ + cout<<"$"; } -} \ No newline at end of file + cout<<"\n"; +} +getch(); + return 0; +} diff --git a/C++/virtualFunction.cpp b/C++/virtualFunction.cpp new file mode 100644 index 00000000..76254932 --- /dev/null +++ b/C++/virtualFunction.cpp @@ -0,0 +1,45 @@ +// Program to implement virtual function. + +#include + +using namespace std; + +class Base { + public: + void display() { + cout<< "Display Base function.\n"; + } + + virtual void show() { + cout<< "Show Base function.\n\n"; + } +}; + +class Derived: public Base { + public: + void display() { + cout<< "Display Base function.\n"; + } + + void show() { + cout<< "Show Base function.\n"; + } +}; + +int main() { + Base B; + Derived D; + Base *bptr; + + cout<<"bptr points to Base\n"; + bptr = &B; + bptr->display(); + bptr->show(); + + cout<<"bptr points to Derived\n"; + bptr = &D; + bptr->display(); + bptr->show(); + + return 0; +} \ No newline at end of file diff --git a/C/convert binary fraction to decimal fraction.c b/C/convert binary fraction to decimal fraction.c new file mode 100644 index 00000000..0aee1639 --- /dev/null +++ b/C/convert binary fraction to decimal fraction.c @@ -0,0 +1,28 @@ +#include +#include +void main() +{ + int i,d,k,j=0,flag=0,c; + double b,x,sum=0,s=0,a; + printf("Enter a Binary fraction no:"); + scanf("%lf",&b); + d=(int)b; + for(i=b;i>0;i=i/10) + { + k=i%10; + sum=sum+k*pow(2,j); + ++j; + } + j=1; + x=b-d; + while(flag==0) + { + a=x*10; + c=a; + s=s+(c/pow(2,j++)); + x=a-c; + if(j==6 || x==0) + flag=1; + } + printf("Decimal fraction is %lf",sum+s); +} diff --git a/C/find_element_in_array.c b/C/find_element_in_array.c new file mode 100644 index 00000000..4afb90b2 --- /dev/null +++ b/C/find_element_in_array.c @@ -0,0 +1,29 @@ +//Finding an element in an array +#include +void main() +{ + int a[25],size,k,i,c=0; + printf("Enter the size of the array\t"); + scanf("%d",&size); + for(i=0;i=1) + { + printf("Element %d is present",k); + } + else if(c==0) + printf("Element %d is not present",k); + +} diff --git a/Csharp/README.md b/Csharp/README.md new file mode 100644 index 00000000..754092e5 --- /dev/null +++ b/Csharp/README.md @@ -0,0 +1 @@ +##Place questions, new topics or additions here! diff --git a/Csharp/datatypes.cs b/Csharp/datatypes.cs new file mode 100644 index 00000000..3f444433 --- /dev/null +++ b/Csharp/datatypes.cs @@ -0,0 +1,28 @@ +using System; + +namespace examples +{ + class Program + { + static void Main(string[] args) + { + //In this page we will cover some different data types you will find in C# + + //Variable declaration is similar to other languages, but we need to declare data types. + + string name = "Nash"; //string of characters, double quotes + + char letter = 'a'; //Single letter, single quotes + + bool valid = true;//false + + int number = 1; //WHOLE numbers +- -2,147,483,648 to 2,147,483,647 + + long bigNumber; //Stores large numbers, +- 9,223,372,036,854,775,808 + + float smallFraction; //FRACTIONAL 6 - 7 decimal points. + + double fraction = 1.5; //FRACTIONAL up to 15 decimal points. + } + } +} diff --git a/Csharp/helloworld.cs b/Csharp/helloworld.cs new file mode 100644 index 00000000..fd3a66f6 --- /dev/null +++ b/Csharp/helloworld.cs @@ -0,0 +1,19 @@ +using System; + +namespace examples +{ + class Program + { + static void Main(string[] args) + { + //This is a basic example of hello world and the boiler plate for C# + Console.WriteLine("Hello World!"); + //Console.WriteLine <-- prints to console on new line. + + Console.Write("Hello"); + Console.Write("World!"); + //Console.Write will also print to console, but not on a new line. + // This will still out put "Hello World!" + } + } +} diff --git a/DSA/DSA-CPP/Graphs/BFS.cpp b/DSA/DSA-CPP/Graphs/BFS.cpp new file mode 100644 index 00000000..c678035c --- /dev/null +++ b/DSA/DSA-CPP/Graphs/BFS.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +void BFS() +{ + queue q; + int a[7][7] = { + {0, 1, 1, 1, 0, 0, 0}, + {1, 0, 0, 1, 0, 0, 0}, + {1, 0, 0, 1, 1, 0, 0}, + {1, 1, 1, 0, 1, 0, 0}, + {0, 0, 1, 1, 0, 1, 1}, + {0, 0, 0, 0, 1, 0, 0}, + {0, 0, 0, 0, 1, 0, 0}}; + + for (int i = 0; i < 7; i++) + { + int visited[7] = {0, 0, 0, 0, 0, 0, 0}; + cout << "BFS through vertex " << i << ":" << endl; + cout << i << " "; + visited[i] = 1; + q.push(i); + while (!q.empty()) + { + int x = q.front(); + q.pop(); + for (int j = 0; j < 7; j++) + { + if (a[x][j] == 1 && visited[j] == 0) + { + cout << j << " "; + visited[j] = 1; + q.push(j); + } + } + } + cout << endl; + } +} + +int main() +{ + BFS(); + return 0; +} diff --git a/DSA/DSA-CPP/Graphs/DFS.cpp b/DSA/DSA-CPP/Graphs/DFS.cpp new file mode 100644 index 00000000..07753608 --- /dev/null +++ b/DSA/DSA-CPP/Graphs/DFS.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; + +int a[7][7] = { + {0, 1, 1, 1, 0, 0, 0}, + {1, 0, 0, 1, 0, 0, 0}, + {1, 0, 0, 1, 1, 0, 0}, + {1, 1, 1, 0, 1, 0, 0}, + {0, 0, 1, 1, 0, 1, 1}, + {0, 0, 0, 0, 1, 0, 0}, + {0, 0, 0, 0, 1, 0, 0}}; +int visited[7] = {0, 0, 0, 0, 0, 0, 0}; + +void DFS(int i) +{ + cout << i << " "; + visited[i] = 1; + for (int j = 0; j < 7; j++) + { + if (a[i][j] == 1 && !visited[j]) + { + DFS(j); + } + } +} + +int main() +{ + int k; + cout << "Enter vertex through which you want to find DFS (0-6): "; + cin >> k; + if (k >= 0 && k < 7) + { + cout << "DFS through vertex " << k << ":" << endl; + DFS(k); + } + else + { + cout << "Invalid vertex" << endl; + } + return 0; +} diff --git a/DSA/DSA-CPP/Queue/Circularqueue.cpp b/DSA/DSA-CPP/Queue/Circularqueue.cpp new file mode 100644 index 00000000..56a66324 --- /dev/null +++ b/DSA/DSA-CPP/Queue/Circularqueue.cpp @@ -0,0 +1,138 @@ +#include +using namespace std; + +template + +class Queue +{ + int size; + int front; + int rear; + T *arr; + +public: + Queue(int length) + { + size = length; + front = rear = 0; + arr = new T[size]; + } + + int queueSize() + { + int count = 0; + for (int i = (front + 1); i <= rear; i++) + { + count++; + } + return count; + } + + bool isEmpty() + { + return (front == rear); + } + + bool isFull() + { + return (front == ((rear + 1) % size)); + } + + void enqueue(T val) + { + if (isFull()) + { + cout << "Queue Overflow" << endl; + return; + } + rear = (rear + 1) % size; + arr[rear] = val; + cout << "Inserted element: " << val << endl; + } + + void dequeue() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + front = (front + 1) % size; + cout << "Deleted element: " << arr[front] << endl; + } + + T queueFront() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[front + 1]; + } + + T queueRear() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[rear]; + } + + void display() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + cout << "Printing..." << endl; + if (rear >= front) + { + for (int i = (front + 1); i <= rear; i++) + cout << arr[i] << " "; + } + else + { + for (int i = (front + 1); i < size; i++) + cout << arr[i] << " "; + + for (int i = 0; i <= rear; i++) + cout << arr[i] << " "; + } + cout << endl; + } +}; + +int main() +{ + Queue q(5); + q.enqueue(23); + q.enqueue(56); + q.enqueue(42); + q.enqueue(12); + // q.enqueue(1); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.dequeue(); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.enqueue(10); + q.display(); + if (q.isFull()) + { + cout << "Full" << endl; + } + if (q.isEmpty()) + { + cout << "Empty" << endl; + } + + return 0; +} diff --git a/DSA/DSA-CPP/Queue/DeQueue.cpp b/DSA/DSA-CPP/Queue/DeQueue.cpp new file mode 100644 index 00000000..4daef0e7 --- /dev/null +++ b/DSA/DSA-CPP/Queue/DeQueue.cpp @@ -0,0 +1,153 @@ +#include +using namespace std; + +template + +class Queue +{ + int size; + int front; + int rear; + T *arr; + +public: + Queue(int length) + { + size = length; + front = rear = -1; + arr = new T[size]; + } + + int queueSize() + { + int count = 0; + for (int i = (front + 1); i <= rear; i++) + { + count++; + } + return count; + } + + bool isEmpty() + { + return (front == rear); + } + + bool isFull() + { + return (front == ((rear + 1) % size)); + } + + void enqueueR(T val) + { + if (isFull()) + { + cout << "Queue Overflow" << endl; + return; + } + rear++; + arr[rear] = val; + cout << "Inserted element: " << arr[rear] << endl; + } + + void enqueueF(T val) + { + int n = -1; + if (isFull()) + { + cout << "Queue Overflow" << endl; + return; + } + while (n != front - 1) + { + n++; + } + arr[front] = val; + front = n; + cout << "Inserted element: " << val << endl; + } + + void dequeueF() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + front++; + cout << "Deleted element: " << arr[front] << endl; + } + + void dequeueR() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + int n = -1; + while (n!=rear-1) + { + n++; + } + cout << "Deleted element: " << arr[rear] << endl; + rear = n; + } + + T queueFront() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[front + 1]; + } + + T queueRear() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[rear]; + } + + void display() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + cout << "Printing..." << endl; + for (int i = (front + 1); i <= rear; i++) + { + cout << arr[i] << " "; + } + cout << endl; + } +}; + +int main() +{ + Queue q(5); + q.enqueueR(23); + q.enqueueR(56); + q.enqueueR(42); + q.enqueueR(12); + q.enqueueR(121); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.dequeueR(); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.enqueueF(1); + q.display(); + return 0; +} diff --git a/DSA/DSA-CPP/Queue/Implementation_using_Arrays.cpp b/DSA/DSA-CPP/Queue/Implementation_using_Arrays.cpp new file mode 100644 index 00000000..a424347d --- /dev/null +++ b/DSA/DSA-CPP/Queue/Implementation_using_Arrays.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; + +template + +class Queue +{ + int size; + int front; + int rear; + T *arr; + +public: + Queue(int length) + { + size = length; + front = rear = -1; + arr = new T[size]; + } + + int queueSize() + { + int count = 0; + for (int i = (front + 1); i <= rear; i++) + { + count++; + } + return count; + } + + bool isEmpty() + { + return (front == rear); + } + + bool isFull() + { + return (rear == size - 1); + } + + void enqueue(T val) + { + if (isFull()) + { + cout << "Queue Overflow" << endl; + return; + } + rear++; + arr[rear] = val; + cout << "Inserted element: " << arr[rear] << endl; + } + + void dequeue() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + front++; + cout << "Deleted element: " << arr[front] << endl; + } + + T queueFront() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[front + 1]; + } + + T queueRear() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return arr[rear]; + } + + void display() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + cout << "Printing..." << endl; + for (int i = (front + 1); i <= rear; i++) + { + cout << arr[i] << " "; + } + cout << endl; + } +}; + +int main() +{ + Queue q(5); + q.enqueue(23); + q.enqueue(56); + q.enqueue(42); + q.enqueue(12); + q.enqueue(121); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.dequeue(); + q.display(); + cout << "Size: " << q.queueSize() << endl; + cout << "Front element: " << q.queueFront() << endl; + cout << "Bottom element: " << q.queueRear() << endl; + q.enqueue(1); + return 0; +} diff --git a/DSA/DSA-CPP/Queue/Implementation_using_linkedList.cpp b/DSA/DSA-CPP/Queue/Implementation_using_linkedList.cpp new file mode 100644 index 00000000..09755b4f --- /dev/null +++ b/DSA/DSA-CPP/Queue/Implementation_using_linkedList.cpp @@ -0,0 +1,147 @@ +#include +using namespace std; + +template + +class node +{ +public: + T data; + node *next; +}; + +template + +class Queue +{ + node *front, *rear; + +public: + Queue() + { + front = rear = NULL; + } + + int queueSize() + { + int count = 0; + node *n = front; + while (n != NULL) + { + count++; + n = n->next; + } + return count; + } + + bool isEmpty() + { + return (rear == NULL); + } + + bool isFull() + { + node *n = new node; + return (n == NULL); + } + + void enqueue(T val) + { + node *n = new node; + if (isFull()) + { + cout << "Queue Overflow" << endl; + return; + } + n->data = val; + n->next = NULL; + if (isEmpty()) + { + rear = front = n; + cout << "Inserted element: " << val << endl; + return; + } + rear->next = n; + rear = n; + cout << "Inserted element: " << val << endl; + } + + void dequeue() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return; + } + node *n = front; + front = front->next; + cout << "Deleted element: " << n->data << endl; + delete n; + } + + void traversal() + { + cout << "Printing..." << endl; + node *n = front; + while (n != NULL) + { + cout << n->data << " "; + n = n->next; + } + cout << endl; + } + + void givenPosition(int index) + { + node *n = front; + for (int i = 0; (i < index - 1 && n != NULL); i++) + { + n = n->next; + } + if (n != NULL) + { + cout << "Element at index " << index << " is: " << n->data << endl; + return; + } + cout << "Invalid index" << endl; + } + + T queueFront() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return (front->data); + } + + T queueRear() + { + if (isEmpty()) + { + cout << "Queue Underflow" << endl; + return -1; + } + return (rear->data); + } +}; + +int main() +{ + Queue q; + q.enqueue(56); + q.enqueue(12); + q.enqueue(5); + q.traversal(); + cout << "Front element: " << q.queueFront() << endl; + cout << "Rear element: " << q.queueRear() << endl; + cout << "Size: " << q.queueSize() << endl; + q.givenPosition(1); + q.dequeue(); + q.traversal(); + cout << "Front element: " << q.queueFront() << endl; + cout << "Rear element: " << q.queueRear() << endl; + cout << "Size: " << q.queueSize() << endl; + return 0; +} diff --git a/DSA/DSA-CPP/STL/set.cpp b/DSA/DSA-CPP/STL/set.cpp index b82d1215..ff9e5bdc 100644 --- a/DSA/DSA-CPP/STL/set.cpp +++ b/DSA/DSA-CPP/STL/set.cpp @@ -1,3 +1,19 @@ //tales only unique value // set returns value in sorted order -//unordered set returns in random order \ No newline at end of file +//unordered set returns in random order +#include +#include +using namespace std; +int main() { + sets; + s.insert(1); + s.insert(1); + s.insert(3); + s.insert(3); + s.insert(2); + s.insert(0); + for (auto &i : s) { + cout << i << " "; + } + return 0; +} diff --git a/DSA/DSA-CPP/Sorting Algo/ShellSort.cpp b/DSA/DSA-CPP/Sorting Algo/ShellSort.cpp new file mode 100644 index 00000000..b41d8325 --- /dev/null +++ b/DSA/DSA-CPP/Sorting Algo/ShellSort.cpp @@ -0,0 +1,63 @@ +// C++ implementation of Shell Sort +#include +using namespace std; + +// Function to sort array using shellSort +int shellSort(int arr[], int n) +{ + // Start with a big gap, then reduce the gap + for (int gap = n/2; gap > 0; gap /= 2) + { + /* Do a gapped insertion sort for this gap size. + The first gap elements a[0..gap-1] are already in gapped order + keep adding one more element until the entire array is + gap sorted */ + for (int i = gap; i < n; i += 1) + { + /*add a[i] to the elements that have been gap sorted + save a[i] in temp and make a hole at position i */ + int temp = arr[i]; + + /*shift earlier gap-sorted elements up until the correct + location for a[i] is found*/ + int j; + for (j = i; j >= gap && arr[j - gap] > temp; j -= gap) + arr[j] = arr[j - gap]; + + // put temp (the original a[i]) in its correct location + arr[j] = temp; + } + } + return 0; +} + +void printArray(int arr[], int n) +{ + for (int i=0; i>n; + + int arr[n], i; + cout<<"Enter elements of array\n"; + for(i=0;i>arr[i]; + } + + cout << "Array before sorting: \n"; + printArray(arr, n); + + shellSort(arr, n); + + cout << "Array after sorting: \n"; + printArray(arr, n); + + return 0; +} \ No newline at end of file diff --git a/DSA/DSA-CPP/Sorting Algo/menuDriven.cpp b/DSA/DSA-CPP/Sorting Algo/menuDriven.cpp new file mode 100644 index 00000000..967f110b --- /dev/null +++ b/DSA/DSA-CPP/Sorting Algo/menuDriven.cpp @@ -0,0 +1,470 @@ +#include +using namespace std; + +class Sort +{ + int size; + int *arr; + +public: + Sort(int n) + { + this->size = n; + arr = new int[size]; + } + + void setVal() + { + for (int i = 0; i < size; i++) + { + cout << "Enter value you want to insert at index " << i << ": "; + cin >> arr[i]; + } + } + + void bubbleSortA() + { + for (int i = 0; i < size - 1; i++) + { + for (int j = 0; j < size - 1 - i; j++) + { + if (arr[j] > arr[j + 1]) + { + int temp = arr[j + 1]; + arr[j + 1] = arr[j]; + arr[j] = temp; + } + } + } + } + + void bubbleSortD() + { + for (int i = 0; i < size - 1; i++) + { + for (int j = 0; j < size - 1 - i; j++) + { + if (arr[j] < arr[j + 1]) + { + int temp = arr[j + 1]; + arr[j + 1] = arr[j]; + arr[j] = temp; + } + } + } + } + + void insertionSortA() + { + for (int i = 1; i <= size - 1; i++) + { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = key; + } + } + + void insertionSortD() + { + for (int i = 1; i <= size - 1; i++) + { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] < key) + { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = key; + } + } + + void selectionSortA() + { + int indexOfmin; + for (int i = 0; i < size - 1; i++) + { + indexOfmin = i; + for (int j = i + 1; j < size; j++) + { + if (arr[j] < arr[indexOfmin]) + { + indexOfmin = j; + } + } + int temp = arr[indexOfmin]; + arr[indexOfmin] = arr[i]; + arr[i] = temp; + } + } + + void selectionSortD() + { + int indexOfmax; + for (int i = 0; i < size - 1; i++) + { + indexOfmax = i; + for (int j = i + 1; j < size; j++) + { + if (arr[j] > arr[indexOfmax]) + { + indexOfmax = j; + } + } + int temp = arr[indexOfmax]; + arr[indexOfmax] = arr[i]; + arr[i] = temp; + } + } + + int PartitionA(int low, int high) + { + int i, j, pivot; + pivot = arr[low]; + i = low + 1; + j = high; + do + { + if (arr[i] < pivot) + { + i++; + } + if (arr[j] > pivot) + { + j--; + } + if (i < j) + { + int temp = arr[j]; + arr[j] = arr[i]; + arr[i] = temp; + } + } while (i < j); + int t = arr[low]; + arr[low] = arr[j]; + arr[j] = t; + return j; + } + + void quickSortA(int low, int high) + { + int p; + if (low < high) + { + p = PartitionA(low, high); + quickSortA(low, p - 1); + quickSortA(p + 1, high); + } + } + + int PartitionD(int low, int high) + { + int i, j, pivot; + pivot = arr[low]; + i = low + 1; + j = high; + do + { + if (arr[i] > pivot) + { + i++; + } + if (arr[j] < pivot) + { + j--; + } + if (i < j) + { + int temp = arr[j]; + arr[j] = arr[i]; + arr[i] = temp; + } + } while (i < j); + int t = arr[low]; + arr[low] = arr[j]; + arr[j] = t; + return j; + } + + void quickSortD(int low, int high) + { + int p; + if (low < high) + { + p = PartitionD(low, high); + quickSortD(low, p - 1); + quickSortD(p + 1, high); + } + } + + void mergeA(int low, int mid, int high) + { + int i, j, b[size + 1], k = low; + i = low; + j = mid + 1; + while (i <= mid && j <= high) + { + if (arr[i] < arr[j]) + { + b[k] = arr[i]; + k++; + i++; + } + else + { + b[k] = arr[j]; + k++; + j++; + } + } + while (i <= mid) + { + b[k] = arr[i]; + k++; + i++; + } + while (j <= high) + { + b[k] = arr[j]; + k++; + j++; + } + for (int i = low; i <= high; i++) + { + arr[i] = b[i]; + } + } + + void mergeSortA(int low, int high) + { + int mid; + if (low < high) + { + mid = (low + high) / 2; + mergeSortA(low, mid); + mergeSortA(mid + 1, high); + mergeA(low, mid, high); + } + } + + void mergeD(int low, int mid, int high) + { + int i, j, b[size + 1], k = low; + i = low; + j = mid + 1; + while (i <= mid && j <= high) + { + if (arr[i] > arr[j]) + { + b[k] = arr[i]; + k++; + i++; + } + else + { + b[k] = arr[j]; + k++; + j++; + } + } + while (i <= mid) + { + b[k] = arr[i]; + k++; + i++; + } + while (j <= high) + { + b[k] = arr[j]; + k++; + j++; + } + for (int i = low; i <= high; i++) + { + arr[i] = b[i]; + } + } + + void mergeSortD(int low, int high) + { + int mid; + if (low < high) + { + mid = (low + high) / 2; + mergeSortD(low, mid); + mergeSortD(mid + 1, high); + mergeD(low, mid, high); + } + } + + void countSortA() + { + int max = *max_element(arr, arr + size); + int count[max + 1]; + for (int i = 0; i < max + 1; i++) + { + count[i] = 0; + } + for (int i = 0; i < size; i++) + { + count[arr[i]]++; + } + int j = 0; + for (int i = 0; i < max + 1;) + { + if (count[i] > 0) + { + arr[j] = i; + j++; + count[i]--; + } + else + { + i++; + } + } + } + + void countSortD() + { + int max = *max_element(arr, arr + size); + int count[max + 1]; + for (int i = 0; i < max + 1; i++) + { + count[i] = 0; + } + for (int i = 0; i < size; i++) + { + count[arr[i]]++; + } + int j = 0; + for (int i = max; i >= 0;) + { + if (count[i] > 0) + { + arr[j] = i; + j++; + count[i]--; + } + else + { + i--; + } + } + } + + void display() + { + for (int i = 0; i < size; i++) + { + cout << arr[i] << " "; + } + cout << endl; + } +}; + +int main() +{ + int s; + cout << "Enter the size of array: "; + cin >> s; + Sort S(s); + S.setVal(); + cout << "\nInitial Array:" << endl; + S.display(); + while (true) + { + cout << "\n\n------Menu Driven Program For Sorting------" << endl; + cout << "1. Ascending Order through Bubble sort" << endl; + cout << "2. Descending Order through Bubble sort" << endl; + cout << "3. Ascending Order through Insertion sort" << endl; + cout << "4. Descending Order through Insertion sort" << endl; + cout << "5. Ascending Order through Selection sort" << endl; + cout << "6. Descending Order through Selection sort" << endl; + cout << "7. Ascending Order through Quick sort" << endl; + cout << "8. Descending Order through Quick sort" << endl; + cout << "9. Ascending Order through Merge sort" << endl; + cout << "10. Descending Order through Merge sort" << endl; + cout << "11. Ascending Order through Count sort" << endl; + cout << "12. Descending Order through Count sort" << endl; + cout << "13. Exit" << endl; + cout << "-------------------------------------------" << endl; + int choice; + cout << "\nEnter you choice: "; + cin >> choice; + switch (choice) + { + case 1: + S.bubbleSortA(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 2: + S.bubbleSortD(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 3: + S.insertionSortA(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 4: + S.insertionSortD(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 5: + S.selectionSortA(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 6: + S.selectionSortD(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 7: + S.quickSortA(0, s - 1); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 8: + S.quickSortD(0, s - 1); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 9: + S.mergeSortA(0, s - 1); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 10: + S.mergeSortD(0, s - 1); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 11: + S.countSortA(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 12: + S.countSortD(); + cout << "Sorted Array:" << endl; + S.display(); + break; + case 13: + cout << "Exiting..." << endl; + exit(0); + default: + break; + } + } + return 0; +} diff --git a/DSA/DSA-CPP/Stacks/Postfix.cpp b/DSA/DSA-CPP/Stacks/Postfix.cpp index 72d274b0..4b4cea66 100644 --- a/DSA/DSA-CPP/Stacks/Postfix.cpp +++ b/DSA/DSA-CPP/Stacks/Postfix.cpp @@ -1,48 +1,54 @@ #include -#include -#include using namespace std; - -int postfixEvaluation(string s){ - stackst; - for(int x=0;x='0' && s[x]<='9'){ - st.push(s[x]-'0'); - } - else{ - int op2=st.top(); - st.pop(); - int op1=st.top(); - st.pop(); - - switch(s[x]){ - case '+': - st.push(op1+op2); - break; - - case '-': - st.push(op1-op2); - break; - - case '*': - st.push(op1*op2); - break; - - case '/': - st.push(op1/op2); - break; - - case '^': - st.push(pow(op1,op2)); - break; - } - } - } - return st.top(); +float scanNum(char ch){ + int value; + value = ch; + return float(value-'0'); +} +int isOperator(char ch){ + if(ch == '+'|| ch == '-'|| ch == '*'|| ch == '/' || ch == '^') + return 1; + return -1; + } + int isOperand(char ch){ + if(ch >= '0' && ch <= '9') + return 1; + return -1; + } +float operation(int a, int b, char op){ + + if(op == '+') + return b+a; + else if(op == '-') + return b-a; + else if(op == '*') + return b*a; + else if(op == '/') + return b/a; + else if(op == '^') + return pow(b,a); + else + return INT_MIN; +} +float postfixEval(string postfix){ + int a, b; + stack stk; + string::iterator it; + for(it=postfix.begin(); it!=postfix.end(); it++){ + + if(isOperator(*it) != -1){ + a = stk.top(); + stk.pop(); + b = stk.top(); + stk.pop(); + stk.push(operation(a, b, *it)); + }else if(isOperand(*it) > 0){ + stk.push(scanNum(*it)); + } + } + return stk.top(); +} +main(){ + string post = "21+3*"; + cout <a[j]): + a[i] , a[j] = a[j] , a[i] + +a = array.array('i' , []) + +n = int(input("Enter lenght of array : ")) + +for i in range(n): + c = int(input("Enter the number : ")) + a.append(c) + +BubbleSort(a) +print(list(a)) \ No newline at end of file diff --git a/DSA/DSA-python/Sorting Algo/InsertionSort.py b/DSA/DSA-python/Sorting Algo/InsertionSort.py new file mode 100644 index 00000000..d568d389 --- /dev/null +++ b/DSA/DSA-python/Sorting Algo/InsertionSort.py @@ -0,0 +1,25 @@ +import array + +# it is the most time taking sorting algo , But performs best for small array which is already sorted + +def insertionSort(a): + for i in range(1 , len(a)): + key = a[i] + j = i-1 + while (key=0): + a[j+1]=a[j] + j-=1 + a[j+1]=key + +a = array.array('i' , []) + +n = int(input("Enter lenght of array : ")) + +for i in range(n): + c = int(input("Enter the number : ")) + a.append(c) + + +insertionSort(a) +print(list(a)) + diff --git a/DSA/DSA-python/Sorting Algo/QuickSort.py b/DSA/DSA-python/Sorting Algo/QuickSort.py new file mode 100644 index 00000000..65c5804f --- /dev/null +++ b/DSA/DSA-python/Sorting Algo/QuickSort.py @@ -0,0 +1,58 @@ +# This follows the same principle as Divide and conquer as in Merge Sort +import array + +def partition(start , end , a): + #Initializing pivot index to start + pivot_index = start + pivot = a[pivot_index] + + while start < end : + + while start pivot : + end-=1 + + #if start and end have not crossed each other + #swap the numbers on start and end + + if(start < end): + a[start] , a[end] = a[end] , a[start] + + # Swap pivot element with element on end pointer + # This puts pivot on its correct sorted place + + a[end] , a[pivot_index] = a[pivot_index] , a[end] + + return end + +def quick_sort(start , end , a): + + if(start < end): + p = partition(start , end , a) + quick_sort(start , p-1 , a) + quick_sort(p+1 , end , a) + +a = array.array('i' , []) + +n = int(input("Enter lenght of array : ")) + +for i in range(n): + c = int(input("Enter the number : ")) + a.append(c) + +quick_sort(0 , len(a)-1 , a) +print(list(a)) + + + + + + + + + diff --git a/DSA/DSA-python/Sorting Algo/SelectionSort.py b/DSA/DSA-python/Sorting Algo/SelectionSort.py new file mode 100644 index 00000000..25eb24ad --- /dev/null +++ b/DSA/DSA-python/Sorting Algo/SelectionSort.py @@ -0,0 +1,29 @@ +import array + +def SelectionSort(a): + n = len(a) + #i will go through len(a) - 1 array size -1(till) + + for i in range(n): + min_index = i + for j in range(i+1 , n): + if(a[j] < a[min_index]): + #we will take new min index + min_index = j + + # Swap the found minimum element with + # the first element + a[i] , a[min_index] = a[min_index] , a[i] + + +a = array.array('i' , []) +n = int(input("Enter lenght of array : ")) + +for i in range(n): + c = int(input("Enter the number : ")) + a.append(c) + +# Time Complexity: O(n2) as there are two nested loops. + +SelectionSort(a) +print(list(a)) diff --git a/DSA/DSA-python/Sorting Algo/bubblesort.py b/DSA/DSA-python/Sorting Algo/bubblesort.py new file mode 100644 index 00000000..bf6342d5 --- /dev/null +++ b/DSA/DSA-python/Sorting Algo/bubblesort.py @@ -0,0 +1,14 @@ +def bubbleSort(lst): + n = len(lst) + + for i in range(n-1): + + for j in range(0, n-i-1): + + + if lst[j] > lst[j + 1] : + lst[j], lst[j + 1] = lst[j + 1], lst[j] + +lst = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(lst) diff --git a/Java/AddTwoNumbers.java b/Java/AddTwoNumbers.java new file mode 100644 index 00000000..5e38fc84 --- /dev/null +++ b/Java/AddTwoNumbers.java @@ -0,0 +1,43 @@ +/** + * You are given two non-empty linked lists representing two non-negative + * integers. The digits are stored in reverse order, and each of their nodes + * contains a single digit. Add the two numbers and return the sum as a linked + * list. + * + * You may assume the two numbers do not contain any leading zero, except the + * number 0 itself. + */ + +/** + * Definition for singly-linked list. public class ListNode { int val; ListNode + * next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, + * ListNode next) { this.val = val; this.next = next; } } + */ +class Solution { + public ListNode addTwoNumbers(ListNode l1, ListNode l2) { + ListNode ans = new ListNode(); + ListNode temp = ans; + int carry = 0; + + while (l1 != null || l2 != null || carry != 0) { + int s = 0; + if (l1 != null) { + s += l1.val; + l1 = l1.next; + } + if (l2 != null) { + s += l2.val; + l2 = l2.next; + } + + s += carry; + carry = s / 10; + ListNode n = new ListNode(s % 10); + temp.next = n; + temp = temp.next; + } + + return ans.next; + + } +} diff --git a/Java/Banking/.idea/.gitignore b/Java/Banking/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/Java/Banking/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Java/Banking/.idea/description.html b/Java/Banking/.idea/description.html new file mode 100644 index 00000000..db5f1295 --- /dev/null +++ b/Java/Banking/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/Java/Banking/.idea/encodings.xml b/Java/Banking/.idea/encodings.xml new file mode 100644 index 00000000..97626ba4 --- /dev/null +++ b/Java/Banking/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Banking/.idea/misc.xml b/Java/Banking/.idea/misc.xml new file mode 100644 index 00000000..bf392ff5 --- /dev/null +++ b/Java/Banking/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Banking/.idea/modules.xml b/Java/Banking/.idea/modules.xml new file mode 100644 index 00000000..365d32c2 --- /dev/null +++ b/Java/Banking/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Banking/.idea/project-template.xml b/Java/Banking/.idea/project-template.xml new file mode 100644 index 00000000..1f08b887 --- /dev/null +++ b/Java/Banking/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/Java/Banking/.idea/vcs.xml b/Java/Banking/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/Java/Banking/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Banking/Banking.iml b/Java/Banking/Banking.iml new file mode 100644 index 00000000..d5c07432 --- /dev/null +++ b/Java/Banking/Banking.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Java/Banking/out/production/Banking/com/company/Bank.class b/Java/Banking/out/production/Banking/com/company/Bank.class new file mode 100644 index 00000000..a789fec4 Binary files /dev/null and b/Java/Banking/out/production/Banking/com/company/Bank.class differ diff --git a/Java/Banking/out/production/Banking/com/company/Branch.class b/Java/Banking/out/production/Banking/com/company/Branch.class new file mode 100644 index 00000000..f64f7cf5 Binary files /dev/null and b/Java/Banking/out/production/Banking/com/company/Branch.class differ diff --git a/Java/Banking/out/production/Banking/com/company/Customer.class b/Java/Banking/out/production/Banking/com/company/Customer.class new file mode 100644 index 00000000..37294488 Binary files /dev/null and b/Java/Banking/out/production/Banking/com/company/Customer.class differ diff --git a/Java/Banking/out/production/Banking/com/company/Main.class b/Java/Banking/out/production/Banking/com/company/Main.class new file mode 100644 index 00000000..8db6cf50 Binary files /dev/null and b/Java/Banking/out/production/Banking/com/company/Main.class differ diff --git a/Java/Banking/src/com/company/Bank.java b/Java/Banking/src/com/company/Bank.java new file mode 100644 index 00000000..01a915a9 --- /dev/null +++ b/Java/Banking/src/com/company/Bank.java @@ -0,0 +1,89 @@ +package com.company; + +import java.util.ArrayList; + +public class Bank { + private String name; + private ArrayList branches; + + public Bank(String name){ + this.name = name; + this.branches = new ArrayList(); + } + + // find the name of the branch + private Branch findBranch(String branchName){ + for (Branch branch : this.branches) { + String searchName = branch.getName(); + if (branchName.equals(searchName)) { + return branch; + } + } + return null; + } + + // add branch + public boolean addBranch(String branchName){ + Branch existingBranch = findBranch(branchName); + if(existingBranch == null){ + Branch newBranch = new Branch(branchName); + branches.add(newBranch); + System.out.println(branchName + " branch added successfully"); + return true; + }else{ + System.out.println("branch name already exists"); + + } + return false; + } + + // add customer + public boolean addCustomer(String customerName, String branchName, double initialTransaction){ + Branch existingBranch = findBranch(branchName); + System.out.println("branch is " + branchName); + + if(existingBranch != null){ + existingBranch.newCustomer(customerName,initialTransaction); + System.out.println("customer -> " + customerName + " added successfully to " + branchName); + return true; + }else{ + System.out.println("something went wrong"); + } + return false; + } + + // add customer transaction + public boolean addCustomerTransaction(String customerName, String branchName, double initialTransaction){ + Branch existingBranch = findBranch(branchName); + if(existingBranch != null){ + System.out.println("Customer " + customerName + " transaction ->" + initialTransaction); + existingBranch.addCustomerTransaction(customerName,initialTransaction); + return true; + } + return false; + } + + public boolean listCustomer(String branchName, boolean printTransaction){ + Branch existingBranch = findBranch(branchName); + if(existingBranch != null && printTransaction){ + System.out.println("Customers for " + branchName); + for(int i=0; i customers; + + public Branch(String name){ + this.name = name; + this.customers = new ArrayList(); + } + + public String getName() { + return name; + } + + public ArrayList getCustomers() { + return customers; + } + + public boolean newCustomer(String name, double initialTransaction){ + if(findCustomer(name) != null){ + System.out.println("Customer name already exists"); + return false; + }else{ + Customer addNewCustomer = new Customer(name,initialTransaction); + customers.add(addNewCustomer); + return true; + } + + } + + public boolean addCustomerTransaction(String name, double transaction){ + Customer existingCustomer = findCustomer(name); + if(existingCustomer!= null){ + existingCustomer.addTransaction(transaction); + return true; + }else{ + return false; + } + } + + public Customer findCustomer(String name){ + int i=0; + for(i=0; i transaction; + + public Customer(String name, double initialTransaction){ + this.name = name; + transaction = new ArrayList(); + this.addTransaction(initialTransaction); + } + + public String getName() { + return name; + } + + public ArrayList getTransaction() { + return transaction; + } + + public void addTransaction(double transaction){ + this.transaction.add(transaction); + } +} diff --git a/Java/Banking/src/com/company/Main.java b/Java/Banking/src/com/company/Main.java new file mode 100644 index 00000000..7d421a2c --- /dev/null +++ b/Java/Banking/src/com/company/Main.java @@ -0,0 +1,93 @@ +/* +Program to create banking system. +Program to have bank acccount for customers that displays customer name and transactions in respective branch +Add the branch name, bank, and customer details using arraylist. + */ + +package com.company; + +import java.util.Scanner; + +public class Main { + + private static Scanner sc = new Scanner(System.in); + private static Bank bank = new Bank("Axis bank"); + + public static void main(String[] args) { + // write your code here + boolean quit = false; + int ch; + printActions(); + while(!quit){ + + System.out.println("enter your choice"); + ch = sc.nextInt(); + switch(ch){ + case 1: + addBranch(); + break; + case 2: + addCustomer(); + break; + case 3: + addCustomerTransaction(); + break; + case 4: + printCustomer(); + break; + case 5: + printActions(); + break; + case 6: + quit = true; + break; + } + } + } + + private static void printActions(){ + System.out.println( + "1. add branch \n" + + "2. add customer \n" + + "3. add customer transaction \n" + + "4. print customer list \n" + + "5. quit" ); + + } + + private static void addBranch(){ + String name; + System.out.println("enter branch name"); + name = sc.next(); + bank.addBranch(name); + } + private static void addCustomer(){ + System.out.println("enter customer name"); + String customerName = sc.next(); + System.out.println("enter branch name"); + String branchName = sc.next(); + System.out.println("enter initial transaction"); + double transaction = sc.nextDouble(); + bank.addCustomer(customerName, branchName, transaction); + + } + + private static void addCustomerTransaction(){ + System.out.println("enter customer name"); + String customerName = sc.next(); + System.out.println("enter branch name"); + String branchName = sc.next(); + System.out.println("enter transaction"); + double transaction = sc.nextDouble(); + bank.addCustomerTransaction(customerName, branchName, transaction); + + } + + private static void printCustomer(){ + System.out.println("enter branch name"); + String branchName = sc.next(); + System.out.println("do you want to print transaction"); + boolean print = sc.nextBoolean(); + bank.listCustomer(branchName, print); + } +} diff --git a/Java/Phone-contacts-project/.idea/.gitignore b/Java/Phone-contacts-project/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/Java/Phone-contacts-project/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Java/Phone-contacts-project/.idea/description.html b/Java/Phone-contacts-project/.idea/description.html new file mode 100644 index 00000000..db5f1295 --- /dev/null +++ b/Java/Phone-contacts-project/.idea/description.html @@ -0,0 +1 @@ +Simple Java application that includes a class with main() method \ No newline at end of file diff --git a/Java/Phone-contacts-project/.idea/encodings.xml b/Java/Phone-contacts-project/.idea/encodings.xml new file mode 100644 index 00000000..97626ba4 --- /dev/null +++ b/Java/Phone-contacts-project/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java/Phone-contacts-project/.idea/misc.xml b/Java/Phone-contacts-project/.idea/misc.xml new file mode 100644 index 00000000..3afb4eec --- /dev/null +++ b/Java/Phone-contacts-project/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Java/Phone-contacts-project/.idea/modules.xml b/Java/Phone-contacts-project/.idea/modules.xml new file mode 100644 index 00000000..61e91e57 --- /dev/null +++ b/Java/Phone-contacts-project/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Java/Phone-contacts-project/.idea/project-template.xml b/Java/Phone-contacts-project/.idea/project-template.xml new file mode 100644 index 00000000..1f08b887 --- /dev/null +++ b/Java/Phone-contacts-project/.idea/project-template.xml @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/Java/Phone-contacts-project/Mobile_phone_arrayList.iml b/Java/Phone-contacts-project/Mobile_phone_arrayList.iml new file mode 100644 index 00000000..d5c07432 --- /dev/null +++ b/Java/Phone-contacts-project/Mobile_phone_arrayList.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Contact.class b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Contact.class new file mode 100644 index 00000000..1588acd0 Binary files /dev/null and b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Contact.class differ diff --git a/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Main.class b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Main.class new file mode 100644 index 00000000..8c46aceb Binary files /dev/null and b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/Main.class differ diff --git a/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/MobilePhone.class b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/MobilePhone.class new file mode 100644 index 00000000..4dae6921 Binary files /dev/null and b/Java/Phone-contacts-project/out/production/Mobile_phone_arrayList/com/company/MobilePhone.class differ diff --git a/Java/Phone-contacts-project/src/com/company/Contact.java b/Java/Phone-contacts-project/src/com/company/Contact.java new file mode 100644 index 00000000..f08c7106 --- /dev/null +++ b/Java/Phone-contacts-project/src/com/company/Contact.java @@ -0,0 +1,23 @@ +package com.company; +import java.util.*; +public class Contact { + private String name; + private String phoneNumber; + + public Contact(String name, String phoneNumber){ + this.name = name; + this.phoneNumber = phoneNumber; + } + + public java.lang.String getName(){ + return this.name; + } + + public String getPhoneNumber(){ + return this.phoneNumber; + } + + public static Contact createContact(String name, String phoneNumber){ + return new Contact(name, phoneNumber); + } +} diff --git a/Java/Phone-contacts-project/src/com/company/Main.java b/Java/Phone-contacts-project/src/com/company/Main.java new file mode 100644 index 00000000..59b65889 --- /dev/null +++ b/Java/Phone-contacts-project/src/com/company/Main.java @@ -0,0 +1,133 @@ +/* + Program to create phone contacts using arraylist, the program should do following operations + -> Add new contact + -> Update the existing contact + -> Remove the contact + -> print the contact list + -> query the contact + + */ + + + +package com.company; + +import java.util.Scanner; + +public class Main { + private static Scanner sc = new Scanner(System.in); + private static MobilePhone mobilePhone = new MobilePhone("0039 330 4404"); + + public static void main(String[] args) { + // write your code here + boolean quit = false; + int choice; + System.out.println("Phone is turned on"); + printActions(); + while (!quit) { + System.out.println("select option"); + choice = sc.nextInt(); + sc.nextLine(); + switch (choice) { + case 1: + addContact(); + break; + case 2: + setContact(); + break; + case 3: + removeContact(); + break; + case 4: + queryContact(); + break; + case 5: + mobilePhone.printContact(); + break; + case 6: + printActions(); + break; + case 7: + quit = true; + break; + } + + + + + } + +} + + + // add new contact + private static void addContact () { + String name, number; + System.out.println("enter name"); + name = sc.nextLine(); + System.out.println("enter number"); + number = sc.nextLine(); + Contact contact = Contact.createContact(name, number); + mobilePhone.addNewContact(contact); + + } + + // update contact + private static void setContact(){ + System.out.println("Enter existing contact name: "); + String name = sc.nextLine(); + Contact existingContactRecord = mobilePhone.queryContact(name); + if(existingContactRecord == null) { + System.out.println("Contact not found."); + return; + } + + System.out.println("enter new contact name"); + String newName = sc.nextLine(); + System.out.print("Enter new contact phone number: "); + String newNumber = sc.nextLine(); + Contact newContact = Contact.createContact(newName, newNumber); + mobilePhone.updateContact(existingContactRecord, newContact); + + } + + // remove contact + private static void removeContact(){ + System.out.println("enter existing contact name"); + String name = sc.nextLine(); + Contact existingContactRecord = mobilePhone.queryContact(name); + if(existingContactRecord != null){ + mobilePhone.removeContact(existingContactRecord); + System.out.println("contact removed"); + }else{ + System.out.println("contact not found"); + } + } + + // query contact + private static void queryContact(){ + System.out.println("Enter existing contact name: "); + String name = sc.nextLine(); + Contact existingContactRecord = mobilePhone.queryContact(name); + if(existingContactRecord == null){ + System.out.println("contact not found"); + }else{ + System.out.println("contact name = " + existingContactRecord.getName() + " number = " + existingContactRecord.getPhoneNumber()); + } + } + // print actions + private static void printActions(){ + System.out.println("\nAvailable actions:\npress"); + System.out.println( + "1 - to add a new contact \n" + + "2 - to update an existing contact\n" + + "3 - to remove an existing contact\n" + + "4 - query if an existing contact exists\n" + + "5 - to print a list of contacts.\n" + + "6 - to print actions\n" + + "7 - to quit"); + + System.out.println("Choose your action: "); + } +} + diff --git a/Java/Phone-contacts-project/src/com/company/MobilePhone.java b/Java/Phone-contacts-project/src/com/company/MobilePhone.java new file mode 100644 index 00000000..831c02a7 --- /dev/null +++ b/Java/Phone-contacts-project/src/com/company/MobilePhone.java @@ -0,0 +1,103 @@ +package com.company; + +import java.util.ArrayList; + +public class MobilePhone { + private String myNumber; + ArrayList myContacts; + + public MobilePhone(String myNumber){ + this.myNumber = myNumber; + this.myContacts = new ArrayList(); + } + + + // add new contact to contacts arraylist + public boolean addNewContact(Contact contact){ + if(findContact(contact) < 0){ + myContacts.add(contact); + System.out.println(contact.getName() + " has been added"); + return true; + }else{ + System.out.println("contact with " + contact.getName() + " already exists"); + return false; + } + } + + // update contact + public boolean updateContact(Contact oldContact, Contact newContact){ + int position = findContact(oldContact); + if(position >= 0){ + myContacts.set(position,newContact); + System.out.println("new contact successfully updated"); + return true; + } + System.out.println(oldContact.getName() + " contact doesn't exist"); + return false; + } + + // remove contact + public boolean removeContact(Contact contact){ + int position = findContact(contact); + if(position >= 0){ + myContacts.remove(contact); + System.out.println(contact.getName() + " contact is removed"); + return true; + }else{ + System.out.println(contact.getName() + " contact doesn't exist"); + return false; + } + } + + + // find contact returns the contact + private int findContact(Contact contact){ + return findContact(contact.getName()); + } + + // find contact with contact name + private int findContact(String contactName){ + for(int i=0; i< myContacts.size(); i++){ + if(myContacts.get(i).getName().equals(contactName)){ + return i; + } + } + return -1; + } + + + // query contact returns contact + public String queryContact(Contact contact) { + if(findContact(contact) >=0) { + return contact.getName(); + } + return null; + } + + // query contact with contact name + public Contact queryContact(String name) { + int position = findContact(name); + if(position >=0) { + return this.myContacts.get(position); + } + + return null; + } + + // print contact list + public void printContact(){ + System.out.println("Contact List: "); + + for(int i = 0; i < this.myContacts.size();i++){ + if(this.myContacts.get(i) != null){ + + System.out.println((i+1)+". "+ this.myContacts.get(i).getName() + " -> "+ this.myContacts.get(i).getPhoneNumber()); + }else{ + System.out.println("Contact List is empty"); + + } + } + + } + +} diff --git a/Java/Simple Games/Connect Four/ConnectFour.java b/Java/Simple Games/Connect Four/ConnectFour.java new file mode 100644 index 00000000..ab9c5ba7 --- /dev/null +++ b/Java/Simple Games/Connect Four/ConnectFour.java @@ -0,0 +1,146 @@ +import java.util.Arrays; +import java.util.Scanner; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class ConnectFour +{ + + private static final char[] PLAYERS = {'X','O'}; + private final int width, height; + private final char[][] grid; + private int lastCol = -1, lastTop = -1; + public ConnectFour(int w, int h) + { + width = w; + height = h; + grid = new char[h][]; + for (int i = 0; i < h; i++) + { + Arrays.fill(grid[i] = new char[w], '.'); + } + } + public String toString() + { + return IntStream.range(0, width). + mapToObj(Integer::toString). + collect(Collectors.joining()) + + "\n" + + Arrays.stream(grid). + map(String::new). + collect(Collectors.joining("\n")); + } + public String horizontal() + { + return new String(grid[lastTop]); + } + public String vertical() + { + StringBuilder sb = new StringBuilder(height); + + for (int h = 0; h < height; h++) + { + sb.append(grid[h][lastCol]); + } + + return sb.toString(); + } + public String slashDiagonal() + { + StringBuilder sb = new StringBuilder(height); + + for (int h = 0; h < height; h++) + { + int w = lastCol + lastTop - h; + + if (0 <= w && w < width) + { + sb.append(grid[h][w]); + } + } + return sb.toString(); + } + public String backslashDiagonal() + { + StringBuilder sb = new StringBuilder(height); + + for (int h = 0; h < height; h++) + { + int w = lastCol - lastTop + h; + + if (0 <= w && w < width) + { + sb.append(grid[h][w]); + } + } + return sb.toString(); + } + public static boolean contains(String str, String substring) + { + return str.indexOf(substring) >= 0; + } + public boolean isWinningPlay() { + if (lastCol == -1) + { + System.err.println("No move has been made yet"); + return false; + } + char sym = grid[lastTop][lastCol]; + String streak = String.format("%c%c%c%c", sym, sym, sym, sym); + return contains(horizontal(), streak) || + contains(vertical(), streak) || + contains(slashDiagonal(), streak) || + contains(backslashDiagonal(), streak); + } + public void chooseAndDrop(char symbol, Scanner input) + { + do + { + System.out.println("\nPlayer " + symbol + " turn: "); + int col = input.nextInt(); + if (!(0 <= col && col < width)) + { + System.out.println("Column must be between 0 and " + (width - 1)); + continue; + } + for (int h = height - 1; h >= 0; h--) + { + if (grid[h][col] == '.') { + grid[lastTop = h][lastCol = col] = symbol; + return; + } + } + System.out.println("Column " + col + " is full."); + } while (true); + } + public static void main(String[] args) + { + System.out.println(" ---------------------------"); + System.out.println(" Welcome to ConnectFour Game"); + System.out.println(" ---------------------------"); + System.out.println("The first to form a horizontal, vertical, or diagonal line of four of ones own discs wins."); + System.out.println(" X stands for Player 1 and O stands for Player 2"); + System.out.println(" Then let's begin the game!!!"); + try (Scanner input = new Scanner(System.in)) + { + int height = 6; int width = 8; int moves = height * width; + ConnectFour board = new ConnectFour(width, height); + System.out.println("Use 0-" + (width - 1) + " to choose a column"); + System.out.println(board); + for (int player = 0; moves-- > 0; player = 1 - player) + { + char symbol = PLAYERS[player]; + board.chooseAndDrop(symbol, input); + System.out.println(board); + if (board.isWinningPlay()) + { + System.out.println("\nPlayer " + symbol + " wins!"); + return; + + } + } + System.out.println("Game over. No winner. Try again!"); + } + } + +} \ No newline at end of file diff --git a/Java/Simple Games/Connect Four/README.md b/Java/Simple Games/Connect Four/README.md new file mode 100644 index 00000000..782cc552 --- /dev/null +++ b/Java/Simple Games/Connect Four/README.md @@ -0,0 +1,5 @@ +# Summary + +![image](https://user-images.githubusercontent.com/91012632/139526793-d7f3986d-8693-4f58-9b43-7bd64b89b6a9.png) + +This is a program for the game of Connect Four. This is a two playered game. The first player to form a horizontal, vertical or a diagonal line of 4 X's or O's wins the game. diff --git a/Java/Simple Games/Hand Cricket/Hand_Cricket.java b/Java/Simple Games/Hand Cricket/Hand_Cricket.java new file mode 100644 index 00000000..bd3a77f7 --- /dev/null +++ b/Java/Simple Games/Hand Cricket/Hand_Cricket.java @@ -0,0 +1,182 @@ +import java.io.*; + +public class Hand_Cricket + +{ + + public static void main(String args[])throws IOException + + { + + InputStreamReader isr=new InputStreamReader(System.in); + BufferedReader br=new BufferedReader(isr); + + String name; // to accept the player's name; + int aa; // converting the random real number generated by 'rr' into a random whole number run for the computer; + int ii; // used in for loops; + int bb; // to accept the player's number; + double rr; // to generate a random real number; + int cheat; // to end the game if wrong input is entered; to keep a check whilst the game is running as to whether the game has ended or not; + int score1; // to store the latest runs scored by the player; + int score2; // to store the latest runs scored by the computer; + int c; // used in for loops to create a specific design; + int choice; // used to decide whether the game needs to be ended or restarted; + int infinity=1; // used to keep the game running until the player decides to end the game; + while(infinity>0) + { + name=" "; + aa=0; + ii=0; + bb=0; + rr=0; + cheat=0; + score1=0; + score2=0; + c=0; + choice=0; + infinity=1; + System.out.println("WELCOME TO THE GAME "); + System.out.println(""); + System.out.print("Enter Your Name: "); + name=br.readLine(); + System.out.println("Hello "+name+","); + System.out.println("WELCOME TO THE CRICKET-MANIA"); + System.out.println("Instructions:"); + System.out.println("You Will First Bat. Enter Any Number From 1 To 10."); + System.out.println("YOU ARE BATTING:"); + for(ii=1;ii>0;ii++) + { + System.out.print("Enter Your Number: "); + bb=Integer.parseInt(br.readLine()); + rr=((Math.random())*10); + rr=rr+1; + aa=(int)(rr); + System.out.println("Computer's Number: "+aa); + if(bb==aa) + { + System.out.println("YOU ARE OUT!!!"); + System.out.println("YOUR FINAL SCORE = "+score1); + break; + } + + else if(bb>0&&bb<=10) + { + score1=score1+bb; + } + else if(bb>10||bb<=0) + { + System.out.println("You have entered wrong number. Game Over!"); + cheat++; + break; + } + + System.out.println("Your Current Score Is "+score1); + } + + for(c=0;c<=2;c++) { if(cheat>0) + { + break; + } + } + + for(c=0;c<1;c++) + { + if(cheat>0) + { + break; + } + System.out.println("YOU ARE BOWLING:"); + } + + for(c=0;c<=2;c++) + { + if(cheat>0) + { + break; + } + } + + for(ii=1;ii>0;ii++) + { + if(cheat>0) + { + break; + } + System.out.print("Enter Your Number: "); + bb=Integer.parseInt(br.readLine()); + rr=((Math.random())*10); + rr=rr+1; + aa=(int)(rr); + System.out.println("Computer's Number: "+aa); + if(aa==bb) + { + System.out.println("COMPUTER IS OUTT!!!!"); + System.out.println("COMPUTER'S FINAL SCORE = "+score2); + break; + } + + else if(bb>0&&bb<=10) + { + score2=score2+aa; + } + else if(bb>10||bb<=0) + { + System.out.println("You have entered a wrong number. Game Over!"); + cheat++; + break; + } + if(score2>score1) + { + System.out.println("THE COMPUTER HAS SCORED MORE THAN YOUU!!!"); + System.out.println("COMPUTER'S FINAL SCORE = "+score2); + break; + } + System.out.println("Computer's Current Score Is "+score2); + } + for(c=0;c<=2;c++) + { + if(cheat>0) + { + break; + } + } + for(ii=0;ii<1;ii++) + { + if(cheat>0) + { + break; + } + System.out.println("YOUR FINAL SCORE = "+score1); + System.out.println("COMPUTER'S FINAL SCORE = "+score2); + if((score1)>(score2)) + { + System.out.println("Congratulations "+name+"!! You Have Defeated The Computer!!!"); + } + + else if((score1)<(score2)) + { + System.out.println("Sorry "+name+", But The Computer Has Defeated You!!!"); + } + + else + { + System.out.println("It's a Tie!!!"); + } + } + System.out.println("Enter 1 To Play This Game Again."); + System.out.println("Enter 0 Or Any Other Number To Quit."); + choice=Integer.parseInt(br.readLine()); + if(choice==1) + { + System.out.print('\f'); + } + + else + { + System.out.print('\f'); + System.out.println("Good Bye!"); + break; + } + } + } +} \ No newline at end of file diff --git a/Java/Simple Games/Hand Cricket/README.md b/Java/Simple Games/Hand Cricket/README.md new file mode 100644 index 00000000..7b620d1d --- /dev/null +++ b/Java/Simple Games/Hand Cricket/README.md @@ -0,0 +1,6 @@ +# Summary + +![image](https://user-images.githubusercontent.com/91012632/139527121-23e05246-f857-43a0-aae9-74c77a476260.png) + + - This is a program for the simple game of Hand Cricket. It is usually played between 2 players but this is vs computer game. + - You can choose a number between 1-10. If the number matches with the one that computer randomly generates, then you are out. Else the numbers add up till you are out. Whoever scores the most, wins. diff --git a/Java/Temperature_Conversion.java b/Java/Temperature_Conversion.java new file mode 100644 index 00000000..fa0327ad --- /dev/null +++ b/Java/Temperature_Conversion.java @@ -0,0 +1,54 @@ +import java.util.*; +public class Temperature_Conversion +{ + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + double c=0.0,k=0.0,f=0.0; + int n; + System.out.println("Enter the value of the temperature you wish to convert"); + double value=sc.nextDouble(); + System.out.println("In which unit do you have the temperature?"); + System.out.println("Enter 1 for Celsius to Fahrenheit and Kelvin"); + System.out.println("Enter 2 for Fahrenheit to Celsius and Kelvin"); + System.out.println("Enter 3 for Kelvin to Celsius and Fahrenheit"); + n=sc.nextInt(); + switch(n) + { + case 1: + { + System.out.println("The answer in Fahrenheit will be:"); + f=(value*9/5)+32; + System.out.println(f); + System.out.println("The answer in Kelvin will be:"); + k=value+273; + System.out.println(k); + break; + } + case 2: + { + System.out.println("The answer in Celsius will be:"); + c=(value*5/9)-32; + System.out.println(c); + System.out.println("The answer in Kelvin will be:"); + k=c+273; + System.out.println(k); + break; + } + case 3: + { + System.out.println("The answer in Celsius will be:"); + c=value-273; + System.out.println(c); + System.out.println("The answer in Fahrenheit will be:"); + f=(c*9/5)+32; + System.out.println(f); + break; + } + default: + { + System.out.println("Invalid choice"); + } + } + } +} \ No newline at end of file diff --git a/Java/armstrong.java b/Java/armstrong.java new file mode 100644 index 00000000..48b7f2a9 --- /dev/null +++ b/Java/armstrong.java @@ -0,0 +1,36 @@ +import java.util.Scanner; +import java.lang.Math; +public class armstrong +{ +static boolean isArmstrong(int n) +{ +int temp, digits=0, last=0, sum=0; +temp=n; +while(temp>0) +{ +temp = temp/10; +digits++; +} +temp = n; +while(temp>0) +{ +last = temp % 10; +sum += (Math.pow(last, digits)); +temp = temp/10; +} +if(n==sum) +return true; +else return false; +} +public static void main(String args[]) +{ +int num; +Scanner sc= new Scanner(System.in); +System.out.print("Enter the number: "); +num=sc.nextInt(); +if(isArmstrong(num)) +System.out.println(num+" is an armstrong number"); +else +System.out.println(num+" is not armstrong"); +} +} diff --git a/Javascript/Numbers/fibonacci.js b/Javascript/Numbers/fibonacci.js new file mode 100644 index 00000000..7bb3cb73 --- /dev/null +++ b/Javascript/Numbers/fibonacci.js @@ -0,0 +1,13 @@ +// fibonacci method returns the specific Nth fibonacci number +const fibonacci = (n, memo = {}) => { + // firstly, check that input is a number or not. + if (typeof n !== 'number') { + return 'not a number.' + } + return ( + memo[n] || + (n <= 2 ? 1 : (memo[n] = fibonacci(n - 1, memo) + fibonacci(n - 2, memo))) + ) +} + +console.log(fibonacci(20)) diff --git a/Python/Alphabet_Rangoli.py b/Python/Alphabet_Rangoli.py new file mode 100644 index 00000000..e0065b82 --- /dev/null +++ b/Python/Alphabet_Rangoli.py @@ -0,0 +1,18 @@ +import string +alpha = string.ascii_lowercase + +def alphabet_rangoli(size): + list = [] + for row in range(size): + hypen = "-".join(alpha[row:size]) + list.append(hypen[::-1] + hypen[1:]) + width = len(list[0]) + + for row in range(size-1, 0, -1): + print(list[row].center(width, '-')) + + for row in range(size): + print(list[row].center(width, '-')) + + +alphabet_rangoli(int(input('Enter n = '))) diff --git a/Python/Birthday wish calculator.py b/Python/Birthday wish calculator.py new file mode 100644 index 00000000..7ddfd980 --- /dev/null +++ b/Python/Birthday wish calculator.py @@ -0,0 +1,14 @@ +import datetime +current_date=datetime.date.today().strftime('%Y-%m-%d') +current_date_ist=current_date.split('-') +b_date=input("Enter birthday date in year-month-date format : ") +name=input("Name of birthday legend : ") +b_date=b_date.split('-') +if current_date_ist[1] == b_date[1] and current_date_ist[2] == b_date[2] : + age=int(current_date_ist[0]) - int(b_date[0]) + ordinal_suffix={1 : 'st',2 : 'nd',3 : 'rd',11 : 'th',12 : 'th',13 : 'th'}.get(age % 10 if not 10 < age <= 13 else age % 14,'th' ) + print(f" it's {name}'s {age}{ordinal_suffix} birthday" ) +else: + print("sorry today is not your birthday") + +#Please enter your date of birth year-month-date format diff --git a/Python/Projects/Image to sketch/main.py b/Python/Projects/Image to sketch/main.py new file mode 100644 index 00000000..f6123423 --- /dev/null +++ b/Python/Projects/Image to sketch/main.py @@ -0,0 +1,11 @@ +import cv2 # pip install cv2 +image = cv2.imread("fireball.jpg") # downloaded image +cv2.imshow("image", image) +grey_img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) +invert = cv2.bitwise_not(grey_img) +blur = cv2.GaussianBlur(invert, (21, 21), 0) +inverted_blur = cv2.bitwise_not(blur) +sketch = cv2.divide(grey_img, inverted_blur, scale=256.0) + +cv2.imwrite("sketch.png", sketch) +quit() diff --git a/Python/serial.py b/Python/serial.py new file mode 100644 index 00000000..dda8ffe5 --- /dev/null +++ b/Python/serial.py @@ -0,0 +1,14 @@ +import serial +# https://pyserial.readthedocs.io/en/latest/ + +def read_Serial(serial_device): + # gets data from serial port + line_read = serial_device.readline() + return line_read + +if (__name__) == "__main__": + # Must define serial port here, currently it is COM3 + serial_device = serial.Serial(port='COM3') + while(1): + if serial_device.in_waiting: + print(read_serial()) diff --git a/Python/urlshortner.py b/Python/urlshortner.py new file mode 100644 index 00000000..ec31e07b --- /dev/null +++ b/Python/urlshortner.py @@ -0,0 +1,14 @@ +import urllib +import requests +import json + + +def shorten(link): + key = '' # Your cutt.ly api key + url = urllib.parse.quote(link) + r = requests.get(f'http://cutt.ly/api/api.php?key={key}&short={url}') + y = json.loads(r.text) + return y['url']['shortLink'] + +url = input("Enter url you want to shorten=>") +print("Your shortened url:", shorten(url)) diff --git a/README.md b/README.md index 81a30935..26cca4e5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -[![Hacktoberfest 2021](./assets/hacktober.png)](https://hacktoberfest.digitalocean.com/) -## [Hactoberfest FAQs](https://hacktoberfest.digitalocean.com/faq) -# Programming-Basics + +#

Programming-Basics

![Hactoberfest](https://img.shields.io/badge/Hactoberfest-%E2%9D%A4-red) @@ -19,7 +18,7 @@ Want To Start your Open-Source Journey Without Facing Difficulties?,If Yes, Then You Are at The Right Place!🎯 -**Don't Know How to Begin Your Journey in Hacktober Fest 2021? Follow Our [Tutorials](https://github.com/Astrodevil/Programming-Basics/blob/main/assets/hacktoberfest-guide.md).** +**Don't Know How to Begin Your Journey in Hacktober Fest? Follow Our [Tutorials](https://github.com/Astrodevil/Programming-Basics/blob/main/assets/hacktoberfest-guide.md).** This Project Contains Basic Solutions, Source Codes, Projects, Games, Book Pdfs related to Different Programming Languages🤗. As Everyone is Learning One or More Programming Languages, So Contribution to This Project Will be Very Easy for You!. @@ -27,6 +26,15 @@ This Project Contains Basic Solutions, Source Codes, Projects, Games, Book Pdfs You can Also Take Help from This Project Towards Your Learning or You Can Contribute to Make This More Helpful for Others. **So, What are you Waiting For?** +# This Project is a part of the following Open Source Program❤️ +

+ + + +
Hacktoberfest
Hacktoberfest 2022
+    + +**[Hactoberfest FAQs](https://hacktoberfest.digitalocean.com/faq)** # Contributing Guidelines📝 Thanks a Ton for Showing Your Interest in Contributing to our Repo! Pull requests are Welcome. For Major Changes, Please Open an Issue First to Discuss What you would like to Change. diff --git a/Useful-Books/C++/C++ programming today by Johnston, Barbara (z-lib.org).pdf b/Useful-Books/C++/C++ programming today by Johnston, Barbara (z-lib.org).pdf new file mode 100644 index 00000000..0ba443ad Binary files /dev/null and b/Useful-Books/C++/C++ programming today by Johnston, Barbara (z-lib.org).pdf differ diff --git a/Useful-Books/C++/CP_handbook.pdf b/Useful-Books/C++/CP_handbook.pdf new file mode 100644 index 00000000..ab4448e3 Binary files /dev/null and b/Useful-Books/C++/CP_handbook.pdf differ