#include <iostream>
using namespace std;
class Rec
{
private:
int length;
int width;
public:
void set_length(int l)
{
length = l;
}
void set_width(int w)
{
width = w;
}
int get_length()
{
return length;
}
int get_width()
{
return width;
}
void show()
{
int perimeter = 2 * (length + width);
int area = length * width;
cout << "Perimeter: " << perimeter << endl;
cout << "Area: " << area << endl;
}
};
int main()
{
Rec r1;
r1.set_length(5);
r1.set_width(3);
cout << "Length: " << r1.get_length() << endl;
cout << "Width: " << r1.get_width() << endl;
r1.show();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class Circle
{
private:
double r;
public:
void set_r(double radius)
{
r = radius;
}
void show(double PI = 3.14)
{
double circumference = 2 * PI * r;
double area = PI * r * r;
cout << "Perimeter: " << circumference << std::endl;
cout << "Area: " << area << std::endl;
}
};
class Car
{
public:
string brand;
string color;
int speed;
};
int main()
{
Circle circle;
circle.set_r(5.0);
cout << "Circle:" << endl;
circle.show();
circle.show(3.14159);
Car car;
car.brand = "Toyota";
car.color = "Red";
car.speed = 60;
cout << "\nCar:" << endl;
cout << "Brand: " << car.brand << endl;
cout << "Color: " << car.color << endl;
cout << "Speed: " << car.speed << " km/h" << endl;
return 0;
}