You are on page 1of 4

EUROPEAN UNIVERSITY OF LEFKE

Faculty of engineering
computer engineering department

NAME surname : Sikandar Ali


STUDENT NO : 184385
COURSE : COMP218
Lab work : 6
 TASK .1
#include <iostream>

#include <math.h>

#include <iomanip>

using namespace std;

class Rectangle {

private:

int length;

int width;

public:

Rectangle(int, int);

int getArea();

int getPerimeter();

double getDigonalLength();

};
Rectangle :: Rectangle(int length, int width) {

this->length = length;

this->width = width;

int Rectangle :: getArea() {

return length * width;

int Rectangle :: getPerimeter() {

return 2 * (length + width);

double Rectangle :: getDigonalLength() {

return sqrt(length * length + width * width);

int main() {

Rectangle rect(10, 20);

cout << "Area = " << rect.getArea() << "\n";

cout << "Perimeter = " << rect.getPerimeter() << "\n";

cout << "Length of digonal = " << fixed << setprecision(2) << rect.getDigonalLength() << "\n";

return 0;

}
 TASK .2
#include <iostream>
#include <math.h>
using namespace std;
class rectangle
{
int length;
int breadth;

public:
void getarea(int l, int b)
{
int area;
area = l * b;
cout << "Area = " << area << "\n";
}

void getcircumference(int l, int b)


{
int cir;
cir = 2 * (l + b);
cout << "Perimeter = " << cir << "\n";
}
void getdiagonallength(int l, int b)
{
int dia;
dia = pow(pow(l, 2) + pow(b, 2), 0.5);
cout << "Diagonal length = " << dia << "\n";
}
};

//Main.cpp

#include <iostream>
#include "Rectangle.h"

using namespace std;

int main()
{
int l, b;
rectangle r;
cout << "Enter length of rectangle ";
cin >> l;
cout << "Enter breadth of rectangle ";
cin >> b;
r.getarea(l, b);
r.getcircumference(l, b);
r.getdiagonallength(l, b);
return 0;
}

You might also like