diff --git a/30. CPP Programs/Bankdetail.cpp b/30. CPP Programs/Bankdetail.cpp new file mode 100644 index 0000000..1ed77f4 --- /dev/null +++ b/30. CPP Programs/Bankdetail.cpp @@ -0,0 +1,177 @@ +#include +#include +using namespace std; +class bankdetail +{ + private: + string name; + string address; + int accountno; + float balance; + public: + void inputdata() + { + cout<<"enter account holders name = "<>a; + for(int i=0;i<2;i++) + { + temp=data[i].search(a); + if(temp) + { + data[i].deposit(); + data[i].showdata(); + break; + } + if(!temp) + { + cout<<"no detail found"; + } + } + break; + + case 4: + cin>>a; + for(int i=0;i<2;i++) + { + temp=data[i].search(a); + if(temp) + { + data[i].withdrawl(); + data[i].showdata(); + break; + } + if(!temp) + { + cout<<"no detail found"; + } + } + break; + + case 5: + cout<<"enter the acc no. whose data you want to change = "; + cin>>a; + for(int i=0;i<2;i++) + { + temp = data[i].search(a); + if(temp) + { + data[i].address_change(); + data[i].showdata(); + break; + } + if(!temp) + cout<<"no detail found"; + } + break; + case 6: + cout<<"thank you"<>ch2; + }while(ch2=='Y'||ch2=='y'); + return 0; +} \ No newline at end of file diff --git a/30. CPP Programs/Employee.cpp b/30. CPP Programs/Employee.cpp new file mode 100644 index 0000000..9c07e29 --- /dev/null +++ b/30. CPP Programs/Employee.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +class employee +{ + private: int Pan,Taxincome; + char Name[20]; + float Tax; + public: void inputinfo() + { + cin>>Pan>>Name>>Taxincome; + } + void Taxcalc() + { + if(Taxincome<=250000) + Tax=0; + else if(Taxincome>250000 && Taxincome<=300000) + Tax=(Taxincome-2500000)*0.1; + else if(Taxincome>300000 && Taxincome<=400000) + Tax=5000+((Taxincome-300000)*0.2); + else if(Taxincome>400000) + Tax=25000+((Taxincome-400000)*0.3); + } + void Displayinfo() + { + cout< +using namespace std; +class Apples +{ + protected: + int a; + public: + void c_apples() + { + cout<<"Enter number of apples"<>a; + } + void display_c_apples() + { + cout<<"The number of apples are: "<>m; + } + void display_c_mangoes() + { + cout<<"The number of mangoes are: "<>n; + t=n+a+m; + } + void display_t_fruits() + { + cout<<"The total number of fruits are: "< +using namespace std; +class shape +{ + protected: + float width,height; + public: + shape() + { + cout<<"Enter the value of width: "<>width; + cout<<"Enter the value of height: "<>height; + } +}; +class rectangle: public shape +{ + private: + float ar; + public: + void area_rec() + { + ar = height * width; + cout<<"The area of rectangle is: "< +using namespace std; +class Mother +{ + public: + void display() + { + cout<<"I am mother"< +using namespace std; +class Animal +{ + private: + string name; + int age; + public: + void set_value() + { + cout<<"Enter name: "<>age; + } + void display() + { + cout<<"The age is: "< +using namespace std; + +class LinkedList +{ +private: + typedef struct node + { + int info; + struct node *next; + } nodetype; + + typedef struct NODE + { + struct NODE *prev; + int info; + struct NODE *next; + } NODE; + + nodetype *first = NULL, *last = NULL; + NODE *f = NULL, *l = NULL; + int len = 0; + +public: + void single_create() + { + int x; + nodetype *p = NULL; + p = new nodetype(); + cout << "Enter value : "; + cin >> x; + p->info = x; + + if (first == NULL && last == NULL) + { + first = last = p; + } + else + { + last->next = p; + last = p; + } + last->next = NULL; + len++; + } + void single_delete(int pos) + { + nodetype *p = new nodetype(); + nodetype *q = new nodetype(); + if (pos <= len) + { + q = first; + if (pos == 1) + { + first = first->next; + cout << q->info << " is deleted." << endl; + free(q); + } + else if (pos == len) + { + while (q != NULL) + { + p = q; + q->next; + } + cout << q->info << " node is deleted." << endl; + last = p; + p->next = NULL; + free(q); + } + else + { + for (int i = 0; i < pos - 1; i++) + { + p = q; + q = q->next; + } + cout << q->info << " node is deleted." << endl; + p->next = q->next; + p = q->next; + free(q); + } + } + else + { + cout << "Position does not exist." << endl; + } + } + void single_display() + { + nodetype *p = new nodetype(); + p = first; + while (p != NULL) + { + cout << p->info << "\t"; + p = p->next; + } + cout << endl; + } + + void circular_create() + { + int x; + nodetype *p = new nodetype(); + cout << "Enter Value : "; + cin >> x; + p->info = x; + if (first == NULL && last == NULL) + { + first = last = p; + } + else + { + last->next = p; + last = p; + } + last->next = first; + len++; + } + void circular_delete(int pos) + { + nodetype *p = new nodetype(); + nodetype *q = new nodetype(); + if (pos <= len) + { + q = first; + if (pos == 1) + { + cout << q->info << " node is deleted." << endl; + first = q->next; + last->next = q->next; + free(q); + } + else if (pos == len) + { + do + { + p = q; + q = q->next; + } while (q != first); + cout << q->info << " node is deleted." << endl; + last = p; + p->next = q->next; + free(q); + } + else + { + for (int i = 0; i < pos - 1; i++) + { + p = q; + q = q->next; + } + cout << q->info << " node is deleted." << endl; + p->next = q->next; + free(q); + } + } + } + void circular_display() + { + nodetype *p = new nodetype(); + p = first; + do + { + cout << p->info << "\t"; + p = p->next; + } while (p != first); + cout << endl; + } + void doubly_create() + { + int x; + NODE *p = new NODE(); + cout << "Enter Value : "; + cin >> x; + p->info = x; + if (f == NULL && l == NULL) + { + f = l = p; + f->prev = NULL; + } + else + { + l->next = p; + p->prev = l; + l=p; + } + l->next = NULL; + len++; + } + + void doubly_delete(int pos) + { + NODE *p = new NODE(); + NODE *q = new NODE(); + NODE *r= new NODE(); + if (pos <= len) + { + q = f; + if (pos == 1) + { + cout << q->info << " node is deleted." << endl; + f = f->next; + f->prev = NULL; + free(q); + } + else if (pos == len) + { + while (q != NULL) + { + p = q; + q = q->next; + } + cout << q->info << " node is deleted." << endl; + l = p; + p->next = NULL; + free(q); + } + else + { + for(int i=0;inext; + } + r=q->next; + cout<info<<" node is deleted."<next=q->next; + r->prev=p; + free(q); + } + } + else{ + cout<<"Position does not exist"<info << "\t"; + p = p->next; + } + cout << endl; + } +}; + +int main() +{ + LinkedList L1; + int ch, ch1; + int pos; + + cout << "1.Singley Linked List\n2.Circular Linked List\n3.Doubley Linked List" << endl; + cout << "Enter your choice : "; + cin >> ch; + switch (ch) + { + case 1: + while (1) + { + cout << "1.Create\n2.Delete node\n3.Display\n4.Exit" << endl; + cin >> ch1; + switch (ch1) + { + case 1: + L1.single_create(); + break; + case 2: + cout << "Enter position of node to delete :"; + cin >> pos; + L1.single_delete(pos); + case 3: + L1.single_display(); + break; + case 4: + return 0; + break; + default: + cout << "Entered wrong choice ." << endl; + break; + } + } + break; + + case 2: + while (1) + { + cout << "1.Create\n2.Delete node\n3.Display\n4.Exit" << endl; + cin >> ch1; + switch (ch1) + { + case 1: + L1.circular_create(); + break; + case 2: + cout << "Enter position of node to delete :"; + cin >> pos; + L1.circular_delete(pos); + break; + case 3: + L1.circular_display(); + break; + case 4: + return 0; + break; + default: + cout << "Entered wrong choice ." << endl; + break; + } + } + break; + + case 3: + while (1) + { + cout << "1.Create\n2.Delete node\n3.Display\n4.Exit" << endl; + cin >> ch1; + switch (ch1) + { + case 1: + L1.doubly_create(); + break; + case 2: + cout << "Enter position of node to delete :"; + cin >> pos; + L1.doubly_delete(pos); + break; + case 3: + L1.doubly_display(); + break; + case 4: + return 0; + break; + default: + cout << "Entered wrong choice ." << endl; + break; + } + } + break; + default: + cout << "Entered wrong choice." << endl; + break; + } + + return 0; +} \ No newline at end of file diff --git a/30. CPP Programs/Queue.cpp b/30. CPP Programs/Queue.cpp new file mode 100644 index 0000000..9f3b4c4 --- /dev/null +++ b/30. CPP Programs/Queue.cpp @@ -0,0 +1,291 @@ +/* Name - Satyam Gupta + Roll no -32 + CST + QUEUE*/ +#include +#define MAX 10 +using namespace std; + +class Queue +{ +private: + int queue[MAX], rear, front, x, *dyn = NULL, dyn_size; + +public: + Queue() + { + rear = -1; + front = -1; + } + + void stat_enqueue() + { + if (rear == MAX - 1) + { + cout << "Queue is overflow." << endl; + } + else if (front == -1 && rear == -1) + { + rear++; + cout << "Enter the value : "; + cin >> x; + queue[rear] = x; + front++; + } + else + { + rear++; + cout << "Enter the value : "; + cin >> x; + queue[rear] = x; + } + } + + void stat_dequeue() + { + if (front == -1 &&rear==-1) + { + cout << "Queue is underflow." << endl; + } + else if (front == rear) + { + cout << queue[front] << " element is dequeued." << endl; + front = rear = -1; + } + else + { + cout << queue[front] << " element is dequeued." << endl; + front++; + } + } + + void stat_display() + { + int temp=front; + if (front == -1) + { + cout << "Queue is underflow"; + } + else + { + cout << "Queue :-" << endl; + while (temp<=rear) + { + cout<> dyn_size; + dyn = new int[dyn_size]; + } + void dyn_enqueue() + { + if (rear == dyn_size - 1) + { + cout << "Queue is overflow." << endl; + } + else if (front == -1 && rear == -1) + { + rear++; + cout << "Enter the value : "; + cin >> x; + *(dyn+rear)=x; + front++; + } + else + { + rear++; + cout << "Enter the value : "; + cin >> x; + *(dyn+rear) = x; + } + } + + void dyn_dequeue() + { + if (front == -1 || front > rear) + { + cout << "Queue is underflow." << endl; + } + else if (front == rear) + { + cout << *(dyn+front)<< " element is dequeued." << endl; + front = rear = -1; + } + else + { + cout << *(dyn+front) << " element is dequeued." << endl; + front++; + } + } + + void dyn_display() + { + int temp=front; + if (front == -1&&rear==-1) + { + cout << "Queue is underflow." << endl; + } + else + { + cout<<"Queue :-"<> x; + *(dyn+rear)= x; + if(front==-1) + front=rear; + } + } + + void circular_dequeue() + { + if(front==-1&&rear==-1) + { + cout<<"Queue is underflow."<> ch; + switch (ch) + { + case 1: + while (1) + { + cout << "1.Enqueue\n2.Dequeue\n3.Display\n4.Exit" << endl; + cout << "Enter choice : "; + cin >> ch1; + switch (ch1) + { + case 1: + q1.stat_enqueue(); + break; + case 2: + q1.stat_dequeue(); + break; + case 3: + q1.stat_display(); + break; + case 4: + return 0; + + default: + cout << "Entered wrong choice." << endl; + break; + } + } + break; + + case 2: + q1.getdyn_size(); + while (1) + { + cout << "1.Enqueue\n2.Dequeue\n3.Display\n4.Exit" << endl; + cout << "Enter choice : "; + cin >> ch1; + switch (ch1) + { + case 1: + q1.dyn_enqueue(); + break; + case 2: + q1.dyn_dequeue(); + break; + case 3: + q1.dyn_display(); + break; + case 4: + return 0; + default: + cout << "Entered wrong choice." << endl; + break; + } + } + case 3: + q1.getdyn_size(); + while (1) + { + cout << "1.Enqueue\n2.Dequeue\n3.Display\n4.Exit" << endl; + cout << "Enter choice : "; + cin >> ch1; + switch (ch1) + { + case 1: + q1.circular_enqueue(); + break; + case 2: + q1.circular_dequeue(); + break; + case 3: + q1.circular_display(); + break; + case 4: + return 0; + default: + cout << "Entered wrong choice." << endl; + break; + } + } + default: + cout << "Entered wrong choice." << endl; + break; + } +} \ No newline at end of file diff --git a/30. CPP Programs/Test.cpp b/30. CPP Programs/Test.cpp new file mode 100644 index 0000000..027d5a2 --- /dev/null +++ b/30. CPP Programs/Test.cpp @@ -0,0 +1,42 @@ +#include +using namespace std; +class Test +{ + private: + int n1,n2,n3; + public: + void setvalue(int a,int b,int c) + { + n1=a; + n2=b; + n3=c; + } + friend void biggest(Test); +}; +void biggest(Test ob) +{ + int n=ob.n1; + if(ob.n1>=ob.n2) + { + if(ob.n1>=ob.n3) + cout<<"The biggest number is: "<=ob.n3) + cout<<"The biggest number is: "< +#include +using namespace std; +class Bank +{ + private: string name; + string address; + int accno,bal,arr[1000],c=0; + public: int input(int n) + { + c+=arr[n]; + cout<<"Enter Name"<>accno; + } + else + { + accno++; + cout<>bal; + return accno; + } + void print(int n) + { + if(n==accno) + { + cout<<"Name = "<>n; + for(int i=0;i<=n;i++) + { + accno=ob.input(n); + } + cout<<"Enter the account number to find"<>faccno; + ob.print(faccno); + return 0; +} \ No newline at end of file diff --git a/30. CPP Programs/inheritance 1.cpp b/30. CPP Programs/inheritance 1.cpp new file mode 100644 index 0000000..20a45f8 --- /dev/null +++ b/30. CPP Programs/inheritance 1.cpp @@ -0,0 +1,37 @@ +#include +using namespace std; +class Mammals +{ +public: + void display1() + { + cout<<"I am mammal"< +using namespace std; +class PRODUCT +{ + private: + string Pid; + string Pname; + string remarks; + int Pcostprice,Psellingprice,margin; + public: + void setRemarks(int sp,int cp) + { + margin=(sp-cp); + if(margin<0) + remarks = "Loss"; + else if(margin>0) + remarks = "Profit"; + } + void Getdetials() + { + cout<<"Enter Product ID"<>Pcostprice; + cout<<"Enter Selling Price"<>Psellingprice; + setRemarks(Psellingprice,Pcostprice); + cin.clear(); + cin.sync(); + } + void Setdetails() + { + cout<<"Product ID = "< +#define MAX 100 +using namespace std; + +class sorting +{ + int a[MAX], lb=0,ub=n-1; + +public: +int n; + void get() + { + cout << "Enter size of array : "; + cin >> n; + cout << "Enter the elements of array : " << endl; + for (int i = 0; i < n; i++) + cin >> a[i]; + } + + void BubbleSort() + { + int temp = 0; + for (int i = 0; i < n - 1; i++) + { + for (int j = 0; j < n - 1 - i; j++) + { + if (a[j] > a[j + 1]) + { + temp = a[j]; + a[j] = a[j + 1]; + a[j + 1] = temp; + } + } + } + } + + void sel_sort() + { + int pos, min = 0; + + for (int i = 0; i < n - 1; i++) + { + min = a[i]; + pos = i; + for (int j = i + 1; j < n; j++) + { + if (min > a[j]) + { + min = a[j]; + pos = j; + } + } + if (pos != i) + { + a[pos] = a[i]; + a[i] = min; + } + } + } + + void InsertionSort() + { + int i, j, temp = 0; + for (i = 1; i < n; i++) + { + temp = a[i]; + j = i - 1; + while (j >= 0 && temp < a[j]) + { + a[j + 1] = a[j]; + j--; + } + a[j + 1] = temp; + } + } + + void quick_sort(int lb, int ub) + { + int i = lb, j = ub, key = a[lb], temp = 0; + if (lb >= ub) + return; + while (i < j) + { + while (key >a[i] && i < j) + i++; + while (key < a[j]) + j--; + if (i < j) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + quick_sort(lb,j-1); + quick_sort(j+1,ub); + } + + void display() + { + for (int i = 0; i < n; i++) + cout << a[i] << "\t"; + } +}; + +int main() +{ + int ch; + sorting s1; + s1.get(); + cout << "Array before sorting : " << endl; + s1.display(); + cout<> ch; + + switch (ch) + { + case 1: + s1.BubbleSort(); + break; + case 2: + s1.sel_sort(); + break; + case 3: + s1.InsertionSort(); + break; + case 4: + s1.quick_sort(0,(s1.n)-1); + break; + case 5: + return 0; + default: + cout << "Entered choice is wrong" << endl; + break; + } + cout << "Array after sorting : " << endl; + s1.display(); + return 0; +} \ No newline at end of file diff --git a/30. CPP Programs/stack.cpp b/30. CPP Programs/stack.cpp new file mode 100644 index 0000000..8f222d7 --- /dev/null +++ b/30. CPP Programs/stack.cpp @@ -0,0 +1,200 @@ +/* Name - Satyam Gupta + Roll no -32 + CST + STACK*/ +#include +#define MAX 10 +using namespace std; +class stack +{ +private: + int arr[MAX], top, *d = NULL, d_size; + +public: + stack() + { + top = -1; + } + void push() + { + if (top == MAX - 1) + { + cout << "Stack is full." << endl; + } + else + { + top++; + cout << "Enter element in stack : "; + cin >> arr[top]; + } + } + void pop() + { + if (top == -1) + { + cout << "Stack is empty." << endl; + } + else + { + cout << arr[top] << " is deleted." << endl; + top--; + } + } + void peek() + { + if (top == -1) + { + cout << "Stack is empty." << endl; + } + else + { + cout << "Top element of stack is " << arr[top] << "." << endl; + } + } + void display() + { + if (top == -1) + cout << "Stack is empty." << endl; + else + { + for (int i = top; i > -1; i--) + { + cout << arr[i] << "\t"; + } + cout << endl; + } + } + + void dyn_size() + { + cout << "Enter the size of stack : "; + cin >> d_size; + + d = new int[d_size]; + } + void dyn_push() + { + if (top == d_size - 1) + { + cout << "Stack is full." << endl; + } + else + { + top++; + cout << "Enter element in stack : "; + cin >> *(d + top); + } + } + void dyn_pop() + { + if (top == -1) + { + cout << "Stack is empty." << endl; + } + else + { + cout << *(d + top) << " is deleted." << endl; + top--; + } + } + void dyn_peek() + { + if (top == -1) + { + cout << "Stack is empty." << endl; + } + else + { + cout << *(d + top) << "is top element in stack" << endl; + } + } + void dyn_display() + { + if (top == -1) + { + cout << "Stack is empty." << endl; + } + else + { + for (int i = top; i > -1; i--) + { + cout << *(d + i) << "\t"; + } + cout << endl; + } + } +}; +int main() +{ + stack s1; + int ch, x; + cout << "1.Static Stack\n2.Dynamic Stack\n3.Exit" << endl; + cout << "Enter choice : "; + cin >> ch; + switch (ch) + { + case 1: + while (1) + { + cout << "1.Push an element\n2.Pop an element\n3.Peek\n4.Display\n5.Exit" << endl; + cout << "Enter valid choice : "; + cin >> x; + switch (x) + { + case 1: + s1.push(); + break; + case 2: + s1.pop(); + break; + case 3: + s1.peek(); + break; + case 4: + s1.display(); + break; + case 5: + return 0; + default: + cout << "Enetred choice is wrong" << endl; + break; + } + } + break; + case 2: + s1.dyn_size(); + while (1) + { + cout << "1.Push an element\n2.Pop an element\n3.Peek\n4.Display\n5.Exit" << endl; + cout << "Enter valid choice : "; + cin >> x; + switch (x) + { + case 1: + s1.dyn_push(); + break; + case 2: + s1.dyn_pop(); + break; + case 3: + s1.dyn_peek(); + break; + case 4: + s1.dyn_display(); + break; + case 5: + return 0; + default: + cout << "Enetred choice is wrong" << endl; + break; + } + } + break; + case 3: + return 0; + + default: + cout << "Entered wrong choice" << endl; + break; + } +} \ No newline at end of file diff --git a/30. CPP Programs/student.cpp b/30. CPP Programs/student.cpp new file mode 100644 index 0000000..aa8c7ac --- /dev/null +++ b/30. CPP Programs/student.cpp @@ -0,0 +1,47 @@ +#include +using namespace std; +class Student +{ + private: string Name; + int roll; + float s1,s2,s3,per; + public: void Inputinfo() + { + cout<<"enter name"<>roll; + cout<<"enter marks in 3 subjects"<>s1>>s2>>s3; + } + void CalcPercentage() + { + per=((s1+s2+s3)/3); + if(per>=90&&per<=100) + cout<<"Grade A"; + else if(per>=80&&per<90) + cout<<"Grade B"; + else if(per>=60&&per<80) + cout<<"Grade C"; + else if(per>=40&&per<60) + cout<<"Grade D"; + else + cout<<"Grade F"; + } + void DisplayInfo() + { + cout< +using namespace std; +class TollBooth +{ + private: + unsigned int cars; + double amount; + public: + void setvalue() + { + cars=0; + amount=0; + } + void PayingCar() + { + cars++; + amount+=0.5; + } + void nonPayCar() + { + cars++; + } + void Display() + { + cout<<"total number of cars = "<>c; + switch(c) + { + case 'A': ob.PayingCar(); + i++; + break; + case 'B': ob.nonPayCar(); + i++; + break; + case 'E': ob.Display(); + i=0; + break; + default: cout<<"Invalid choice"; + } + }while(i!=0); + return 0; +} \ No newline at end of file