Skip to content

Commit

Permalink
practice
Browse files Browse the repository at this point in the history
  • Loading branch information
muhibarshad committed Oct 9, 2022
1 parent 40d05ee commit 17e7401
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>

using namespace std;

class Complex
{
private:
int real;
int imag;

public:
Complex(int real = 0, int imag = 0) : real(real), imag(imag) {}
friend istream &operator>>(istream &in, Complex &obj)
{
cout << "Enter the real part of the complex number :";
in >> obj.real;
cout << "Enter the imaginary part of the complex number :";
in >> obj.imag;
return in;
}
friend ostream &operator<<(ostream &out, Complex &obj)
{
if (obj.real != 0 && obj.imag != 0)
{
out << obj.real;
obj.imag >= 0 ? cout << "+" : cout << "-";
cout << obj.imag<< "i"
<< "\n";
}
else
{
cout << 0 << "\n";
}

return out;
}
Complex operator-(const Complex &obj) const
{
return Complex(real - obj.real, imag - obj.imag);
}
bool operator==(const Complex &obj) const
{
return (real == obj.real && imag == obj.imag);
}
bool operator!=(const Complex &obj) const
{
return !(*this == obj);
}
};
int main()
{
Complex C1;
Complex C2(5, 6);
Complex C3;

cout << "Input a complex number" << endl;
cin >> C3;

cout << C1 << C2 << C3;

if (C1 == C2)
cout << "C1 == C2" << endl;
else
cout << "C1 != C2" << endl;

if (C1 != C3)
cout << "C1 != C3" << endl;
else
cout << "C1==C3" << endl;

Complex C4 = C2 - C3;
cout << C4;

system("pause");
return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include <iostream>

using namespace std;

class Box
{
private:
double length, breadth, height;
static int objectCount;

public:
Box() : length(0), breadth(0), height(0) {}
Box(double length, double breadth, double height) : length(length), breadth(breadth), height(height) {}
void setLength(double length) { this->length = length; }
void setbreadth(double breadth) { this->breadth = breadth; }
void setheigth(double heigth) { this->height = heigth; }
double getLength() { return length; }
double getbreadth() { return breadth; }
double getheigth() { return height; }
void print()
{
cout << "The length of the object = " << length << "\n";
cout << "The breadth of the object = " << breadth << "\n";
cout << "The height of the object = " << height << "\n";
}
static int getCount()
{
return objectCount;
}
double getVolume()
{
return (length * breadth) * height;
}
double getArea()
{
return length * breadth;
}
friend void print_surfaceArea(const Box &b1)
{
cout << "The surface area of the box = " << (2 * (b1.length * b1.breadth) + 2 * (b1.length * b1.height) + 2 * (b1.breadth * b1.height));
}
friend void double_data_members(double &length, double &breadth, double &height)
{
length += length;
breadth += breadth;
height += height;
}
};
int Box::objectCount=1;
int main()
{
Box b(2, 2, 2);
b.print();
cout << Box::getCount();
return 0;
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ class algebra
{
private:
int x;
const int y = 30;
const int y;

public:

//OVERLOADED_CONSTRUCTOR
algebra(int x = 0, int y = 0)
algebra(int x = 0):y(30)
{
setX(x);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main()
obj1.getData(); // x=0 , y=0
// only non-static members become object property
//on the time of creation of object it defaulty initliaze the all values with 0 so static meber became aslo zero

algebra obj2(2, 7);
obj2.getData(); // x=2 , y=7
obj1.getData(); // x=0 , y=7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,12 @@ class algebra
}

// 3. Assignment =
void operator=(const algebra &obj)
algebra& operator=(const algebra &obj)
{
x = obj.x;
y = obj.y;
z = obj.z;
return *this;
}

// 4.Arithematic_Assignment +=, -=, *=, /=, %=
Expand Down

0 comments on commit 17e7401

Please sign in to comment.