include iostream namespace cf class Rect private double height double

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/// #2
#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;
}