Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions C++/plus overloading
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include<iostream>
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<<endl<<"box1 volume is "<<vol1<<endl;
cout<<"box2 volume is "<<vol2<<endl;
cout<<"box4 volume is "<<vol4<<endl;

box3=box1+box2+box4;
vol3=box3.getvolume();
box5=box2-box1;
vol5=box5.getvolume();
cout<<endl<<"overloads unuary + operator:"<<endl;
cout<<"box3 volume is "<<vol3<<endl; //box3=box1+box2+box4
cout<<endl<<"overloads unuary - operator:"<<endl;
cout<<"box5 volume is "<<vol5<<endl; //box5=box2-box1

cout<<endl<<"overloads [] operator:"<<endl;
int intArray[1024];
for (int i = 0, j = 0; i < 1024; i++)
{
intArray[i] = j++;
}
// 512
cout << intArray[512] << endl;
// 257
cout << 257 [intArray] << endl;
}
84 changes: 84 additions & 0 deletions c/stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include<stdio.h>
#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;
}