From 80827625e22c96e8ce0c9204496f126ea886c163 Mon Sep 17 00:00:00 2001 From: vanshika <82704514+jainvanshi3105@users.noreply.github.com> Date: Tue, 15 Feb 2022 18:01:55 +0530 Subject: [PATCH 1/2] Create plus overloading get volume of a box by using plus operator overloading in cpp --- C++/plus overloading | 88 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 C++/plus overloading diff --git a/C++/plus overloading b/C++/plus overloading new file mode 100644 index 0000000..2888e71 --- /dev/null +++ b/C++/plus overloading @@ -0,0 +1,88 @@ +#include +using namespace std; +class box +{ + private: + double length,breadth,height; + + public: + double getvolume() + { + return length*breadth*height; + } + void setlength(double l) + { + length=l; + } + void setbreadth(double b) + { + breadth=b; + } + void setheight(double h) + { + height=h; + } + box operator+(const box&b) + { + box box; + box.length=this->length+b.length; + box.breadth=this->breadth+b.breadth; + box.height=this->height+b.height; + return box; + } + box operator-(const box&m) + { + box box; + box.length=this->length-m.length; + box.breadth=this->breadth-m.breadth; + box.height=this->height-m.height; + return box; + } +}; +int main() +{ + double vol1,vol2,vol3,vol4,vol5; + box box1; + box box2; + box box3; + box box4; + box box5; + box1.setlength(2.5); + box1.setbreadth(5.5); + box1.setheight(7.5); + + box2.setlength(12.5); + box2.setbreadth(15.5); + box2.setheight(17.5); + + box4.setlength(2.5); + box4.setbreadth(1.5); + box4.setheight(1.5); + + vol1=box1.getvolume(); + vol2=box2.getvolume(); + vol4=box4.getvolume(); + cout< Date: Tue, 15 Feb 2022 18:03:30 +0530 Subject: [PATCH 2/2] Create stack --- c/stack | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 c/stack diff --git a/c/stack b/c/stack new file mode 100644 index 0000000..e0ea053 --- /dev/null +++ b/c/stack @@ -0,0 +1,84 @@ +#include +#define MAX 5 +int stack[MAX],top=-1; +void push() +{ + int value; + if(top==MAX-1) + { + printf("\nstack is full\n"); + } + else + { + printf("enter the value to push in the stack:"); + scanf("%d",&value); + top++; + stack[top]=value; + } +} +void pop() +{ + if(top==-1) + { + printf("\nstack is empty\n"); + } + else + { + printf("deleted element is %d",stack[top]); + top--; + } +} +void display() +{ + if(top>=0) + { + printf("stack elements:\n"); + for(int i=top;i>=0;--i) + { + printf("%d\n",stack[i]); + } + } + else if(top==-1) + { + printf("\nstack is empty\n"); + } +} +int main() +{ + int exit=0; + for(int x=0;x<=100;x++) + { + printf("\npress 1 to push the element in stack\n"); + printf("press 2 to pop the element from stack\n"); + printf("press 3 to display the elements\n"); + printf("press 4 for exit\n"); + printf("NOTE: max input 5\n"); + int ch; + printf("enter your choice:"); + scanf("%d",&ch); + switch (ch) + { + case 1: + push(); + break; + case 2: + pop(); + break; + case 3: + display(); + break; + case 4: + printf("EXIT"); + exit++; + break; + default: + printf("INVALID CHOICE"); + break; + } + if(exit==1) + { + break; + } + } + return 0; +}