Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // LETIINF3.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "cmath"
- #include "iostream"
- double a, b, r;
- double f_line(double x)
- {
- double x1 = 0;
- double y1 = b;
- double x2 = 2 * a;
- double y2 = -b;
- return ((y1 - y2)*x + (x1*y2 - x2*y1)) / (x1 - x2);
- }
- double s_line(double x)
- {
- double x1 = 2 * a;
- double y1 = -b;
- double x2 = 4 * a;
- double y2 = b;
- return ((y1 - y2)*x + (x1*y2 - x2*y1)) / (x1 - x2);
- }
- double get_y(double x)
- {
- if (x <= 0)
- {
- return get_y(4 * a - fmod(x, 4 * a));
- }
- else {
- if (x <= 2 * a)
- {
- return f_line(x);
- }
- else
- {
- if (x <= 4 * a)
- {
- return s_line(x);
- }
- else
- {
- return get_y(fmod(x, 4 * a));
- }
- }
- }
- }
- void main()
- {
- double x, y;
- std::cout << "a - 1\n";
- //std::cin >> a;
- a = 1;
- std::cout << "b - 1\n";
- //std::cin >> b;
- b = 1;
- std::cout << "x - ";
- std::cin >> x;
- y = get_y(x);
- y = y == -0 ? fabs(y) : y;
- std::cout << y << "\n";
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement