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< +#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; +}