Впо невозратснию массива чисел определить, есть ли заданное число z, в противном случае подсчитать количество чисел, небольших z; кроме того определить, сколько отрицательных чисел в pascal
function f(x: real): real; begin f:=0.5*x*cos(2*x); end;
// l (logical) - логические координаты // s (screen) - физические координаты procedure drawGraph(x1,x2,y1,y2: real; f: FUN); var xl,xl0,wl,yl,yl0,hl: real; xs0,ws,ys0,hs: integer; function LtoSx(xl: real): integer; begin Result:=round(ws/wl*(xl-xl0)+xs0); end; function LtoSy(yl: real): integer; begin Result:=round(hs/hl*(yl-yl0)+ys0); end; function StoLx(xs: integer): real; begin Result:=wl/ws*(xs-xs0)+xl0; end; var xi: integer; begin // drawGraph xs0:=0; ys0:=WindowHeight; ws:=WindowWidth; hs:=WindowHeight; xl0:=x1; yl0:=y1; wl:=x2-x1; hl:=-(y2-y1); MoveTo(xs0,LtoSy(f(StoLx(xs0; for xi:=xs0+1 to xs0+ws do LineTo(xi,LtoSy(f(StoLx(xi; end;
begin // program SetWindowCaption('График функции'); drawGraph(-12,12,-23,23,f); end.
С++20
#include <iostream>#include <vector>class Point {public: int x, y; Point() = default; Point(const Point &) = default; Point(int _x, int _y) : x(_x), y(_y) {} Point operator + (const Point& p) const { return Point {x + p.x, y + p.y}; } Point operator - (const Point& p) const { return Point {x - p.x, y - p.y}; } std::vector<Point> operator & (const Point& p) const { return std::vector<Point> { Point {x + p.x, y + p.y}, Point {x - p.x, y + p.y}, Point {x + p.x, y - p.y}, Point {x - p.x, y - p.y}, Point {x + p.y, y + p.x}, Point {x - p.y, y + p.x}, Point {x + p.y, y - p.x}, Point {x - p.y, y - p.x}, }; } static Point max (const Point& p1, const Point& p2) { return Point {std::max(p1.x, p2.x), std::max(p1.y, p2.y)}; } static Point min (const Point& p1, const Point& p2) { return Point {std::min(p1.x, p2.x), std::min(p1.y, p2.y)}; } [[nodiscard]] int distance_to_by_ch (const Point & p) const { return std::max(std::abs(p.x - x), std::abs(p.y - y)); } [[nodiscard]] int distance_to_by_m (const Point & p) const { return std::abs(p.x - x) + std::abs(p.y - y); } friend std::ostream &operator << (std::ostream &os, Point const &p) { return os << "(" << p.x << ";" << p.y << ")"; } Point & operator = (const Point &) = default; bool operator == (const Point & p) const { return x == p.x && y == p.y; }};class Horse {public: const Point p; explicit Horse (const Point position) : p(position) { } [[nodiscard]] bool can_I_kill_this_guy (const Point & m) const { auto field = p & Point{2, 3}; return std::find(field.begin(), field.end(), m) != field.end(); }};std::istream &to_number(std::istream &stream) { char ch; do { ch = stream.get(); } while (!isalpha(ch)); if (isupper(ch)) ch -= 16; else ch -= 48; stream.putback(ch); return stream;}int main () { Point horse_p{}, stranger_p{}; std::cin >> horse_p.x >> to_number >> horse_p.y; std::cin >> stranger_p.x >> to_number >> stranger_p.y; Horse jack(horse_p); std::cout << "I am a Horse placed on " << jack.p << ". " << "Can I kill those guy on " << stranger_p << "? " << "-> " << std::boolalpha << jack.can_I_kill_this_guy(stranger_p); }uses GraphABC;
type FUN = function (x: real): real;
function f(x: real): real;
begin
f:=0.5*x*cos(2*x);
end;
// l (logical) - логические координаты
// s (screen) - физические координаты
procedure drawGraph(x1,x2,y1,y2: real; f: FUN);
var
xl,xl0,wl,yl,yl0,hl: real;
xs0,ws,ys0,hs: integer;
function LtoSx(xl: real): integer;
begin
Result:=round(ws/wl*(xl-xl0)+xs0);
end;
function LtoSy(yl: real): integer;
begin
Result:=round(hs/hl*(yl-yl0)+ys0);
end;
function StoLx(xs: integer): real;
begin
Result:=wl/ws*(xs-xs0)+xl0;
end;
var xi: integer;
begin // drawGraph
xs0:=0; ys0:=WindowHeight;
ws:=WindowWidth;
hs:=WindowHeight;
xl0:=x1;
yl0:=y1;
wl:=x2-x1;
hl:=-(y2-y1);
MoveTo(xs0,LtoSy(f(StoLx(xs0;
for xi:=xs0+1 to xs0+ws do
LineTo(xi,LtoSy(f(StoLx(xi;
end;
begin // program
SetWindowCaption('График функции');
drawGraph(-12,12,-23,23,f);
end.