#include <iostream>
namespace cf{
class Rect{
private:
double height;
double width;
char fillRect;
char perimRect;
public:
Rect(double h = 1, double w = 1){
height = h;
width = w;
}
void setFillRect(char c){
fillRect = c;
}
void setPerimRect(char c){
perimRect = c;
}
void setWidth(double w){
width = w;
}
void setHeight(double h){
height = h;
}
double getWidth() const{
return width;
}
double getHeight() const{
return height;
}
double perim() {
return 2 * (width + height);
}
double area() {
return width * height;
}
void draw(){
for(size_t i = 0; i < width; ++i){
for(size_t j = 0; j < height; ++j){
if(i == 0 || i == width - 1)
std::cout << perimRect;
else if(j == 0 || j == height - 1)
std::cout << perimRect;
else
std::cout << fillRect;
}
std::cout << std::endl;
}
}
};
}
int main(){
cf::Rect rect(5, 5);
rect.setFillRect('*');
rect.setPerimRect('=');
rect.draw();
return 0;
}
/// #1
#include <iostream>
using namespace std;
class Complex
{
private:
float realPart, imaginaryPart;
int i;
public:
Complex();
Complex(float real_part, float im_part);
Complex operator + (Complex) const;
Complex operator - (Complex) const;
float getReal(){ return realPart; };
float getIm(){ return imaginaryPart; };
void show();
void input();
};
Complex Complex::operator+ (Complex d) const
{
return Complex(realPart + d.getReal(), imaginaryPart + d.getIm());
}
Complex Complex::operator- (Complex d) const
{
return Complex(realPart - d.getReal(), imaginaryPart - d.getIm());
}
Complex::Complex()
{
realPart = 0;
imaginaryPart = 0;
}
Complex::Complex(float real_part, float im_part)
{
realPart = real_part;
imaginaryPart = im_part;
}
void Complex::input()
{
cout << "Введите действительную часть комплекстного числа\n";
cin >> realPart;
cout << "Введите мнимую часть комплексного числа \n";
cin >> imaginaryPart;
}
void Complex::show()
{
printf_s("(%.3f+%.3f*i)\n", realPart, imaginaryPart);
}
int main()
{
setlocale(LC_ALL, "Russian");
Complex a, b, c, d;
a.input();
b.input();
c = a + b;
d = a - b;
c.show();
d.show();
system("pause");
return 0;
}