
Другие языки программирования и технологии
Помогите решить задачу по информатике 10 класс
Надо решить на c++


#include <iostream>
using namespace std;
class Point {
public:
Point() : x_(0), y_(0) {}
Point(double x, double y) : x_(x), y_(y) {}
double x()const { return x_; }
double y()const { return y_; }
double radius()const { return sqrt(x_ * x_ + y_ * y_); }
double radius(double dx, double dy)const {
return sqrt(pow(x_ + dx, 2) + pow(y_ + dy, 2));
}
private:
double x_;
double y_;
};
struct Field {
Field() : first(0), second(0), third(0), fourth(0) {}
unsigned short first : 1;
unsigned short second : 1;
unsigned short third : 1;
unsigned short fourth : 1;
friend ostream& operator<<(ostream& out, const Field& field) {
out << field.first << field.second << field.third << field.fourth;
return out;
}
};
class Position {
public:
using spot = bool (*)(const Point& point);
Position(const Point& point) : point_(point) {}
Field get()const { return field_; }
void first(spot func) { if (func(point_)) field_.first = 1; }
void second(spot func) { if (func(point_)) field_.second = 1; }
void third(spot func) { if (func(point_)) field_.third = 1; }
void fourth(spot func) { if (func(point_)) field_.fourth = 1; }
private:
Point point_;
Field field_;
};
int main() {
auto f1 = [](const Point& p) { return p.y() < 1; };
auto f2 = [](const Point& p) { return p.y() < -p.x(); };
auto f3 = [](const Point& p) { return p.radius() < 1; };
auto f4 = [](const Point& p) { return p.radius(-1, -1) < 1; };
double x, y;
cin >> x >> y;
Point point(x, y);
Position position(point);
position.first(f1);
position.second(f2);
position.third(f3);
position.fourth(f4);
cout << position.get() << '\n';
system("pause");
}
using namespace std;
class Point {
public:
Point() : x_(0), y_(0) {}
Point(double x, double y) : x_(x), y_(y) {}
double x()const { return x_; }
double y()const { return y_; }
double radius()const { return sqrt(x_ * x_ + y_ * y_); }
double radius(double dx, double dy)const {
return sqrt(pow(x_ + dx, 2) + pow(y_ + dy, 2));
}
private:
double x_;
double y_;
};
struct Field {
Field() : first(0), second(0), third(0), fourth(0) {}
unsigned short first : 1;
unsigned short second : 1;
unsigned short third : 1;
unsigned short fourth : 1;
friend ostream& operator<<(ostream& out, const Field& field) {
out << field.first << field.second << field.third << field.fourth;
return out;
}
};
class Position {
public:
using spot = bool (*)(const Point& point);
Position(const Point& point) : point_(point) {}
Field get()const { return field_; }
void first(spot func) { if (func(point_)) field_.first = 1; }
void second(spot func) { if (func(point_)) field_.second = 1; }
void third(spot func) { if (func(point_)) field_.third = 1; }
void fourth(spot func) { if (func(point_)) field_.fourth = 1; }
private:
Point point_;
Field field_;
};
int main() {
auto f1 = [](const Point& p) { return p.y() < 1; };
auto f2 = [](const Point& p) { return p.y() < -p.x(); };
auto f3 = [](const Point& p) { return p.radius() < 1; };
auto f4 = [](const Point& p) { return p.radius(-1, -1) < 1; };
double x, y;
cin >> x >> y;
Point point(x, y);
Position position(point);
position.first(f1);
position.second(f2);
position.third(f3);
position.fourth(f4);
cout << position.get() << '\n';
system("pause");
}
Алексей Гайковский
А ещё длиннее можно было?
Александр Шульга
А что так длинно?
#include iostream//iostream в угловых скобках, но Ответы их хавают
using namespace std;
int main()
{
double x,y;
int code[4]={}, i;
cin>>x>>y;
if(y<1) code[0]=1;
if(y<-x) code[1]=1;
if(x*x+y*y<1) code[2]=1;
if((x-1)*(x-1)+y*y<1) code[3]=1;
for(i=0;i<4;++i)
cout<<code[i];
return 0;
}
using namespace std;
int main()
{
double x,y;
int code[4]={}, i;
cin>>x>>y;
if(y<1) code[0]=1;
if(y<-x) code[1]=1;
if(x*x+y*y<1) code[2]=1;
if((x-1)*(x-1)+y*y<1) code[3]=1;
for(i=0;i<4;++i)
cout<<code[i];
return 0;
}
Александр Шульга
Не работает
Александр Шульга
Когда вводишь 0,5 0,5 выдаёт 1010, а надо 1011
Ашим Нурбеков
if((x-1)*(x-1)+y*y<1) code[3]=1;
Проверьте себя на аккуратность написания этой строчки
Проверьте себя на аккуратность написания этой строчки
Александр Шульга
Точку
Александр Шульга
Запятая не работает
Александр Шульга
Компилятор запятую за и считает
Похожие вопросы
- Помогите решить задачу по информатике 9 класс. Pascal ABC
- Народ, слезно прошу помочь решить задачу по информатике (програмирование), я просто ноль в этом(((
- Задача по информатике. 10 класс
- Помогите решить задачи по информатике!!! ОЧЕНЬ НУЖНО!!!
- Ребята помогите решить задачу по информатике ПЛАЧУ 50 БАЛОВ ЗА ЛУТШИЙ ОТВЕТ
- помогите решить задачи по информатике
- Помогите решить задачи по информатике.
- Помогите решить задачи по информатике.
- помогите решить задачу по информатике, срочно нужно ( программирование с++)
- Помогите решить задачу по информатике ...паскаль