Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bart³omiej Kozyra
- #include <iostream>
- #include <cstdlib>
- #include <cmath>
- #include <sstream>
- using namespace std;
- class NapBon {
- public:
- double x;
- NapBon (double arg = 0) {
- if(arg < 0){
- cout << "!!!";
- x = 0;
- }
- else if(arg > 157){
- cout << "!!!";
- x = 157;
- }
- else {
- x = arg;
- }
- }
- friend ostream& operator<<(ostream& out, NapBon arg){
- out << arg.x;
- return out;
- }
- friend istream& operator>>(istream& in, NapBon& arg){
- in >> arg.x;
- if(arg.x < 0){
- cout << "!!!";
- arg.x = 0;
- }
- else if (arg.x > 157){
- cout << "!!!";
- arg.x = 157;
- }
- return in;
- }
- friend NapBon operator+(NapBon left, NapBon right){
- NapBon arg;
- if((left.x + right.x) > 157){
- cout << "!!!";
- arg.x = 157;
- }
- else{
- arg.x = left.x + right.x;
- }
- return arg;
- }
- friend NapBon operator-(NapBon left, NapBon right){
- NapBon arg;
- if((left.x - right.x) < 0){
- cout << "!!!";
- arg.x = 0;
- }
- else{
- arg.x = left.x - right.x;
- }
- return arg;
- }
- friend NapBon operator*(NapBon left, NapBon right){
- NapBon arg;
- if((left.x * right.x) > 157){
- cout << "!!!";
- arg.x = 157;
- }
- else{
- arg.x = left.x * right.x;
- }
- return arg;
- }
- friend NapBon operator/(NapBon left, NapBon right){
- NapBon arg;
- if((left.x / right.x) > 157){
- cout << "!!!";
- arg.x = 157;
- }
- else{
- arg.x = left.x / right.x;
- }
- return arg;
- }
- NapBon operator+(){
- return *this;
- }
- NapBon operator-(){
- NapBon arg(0);
- cout << "!!!";
- return arg;
- }
- NapBon operator++(){
- if(x == 157){
- cout << "!!!";
- }
- else{
- x += 1.0;
- }
- return *this;
- }
- NapBon operator--(){
- if(x == 0){
- cout << "!!!";
- }
- else{
- x -= 1.0;
- }
- return *this;
- }
- NapBon operator++(int){
- NapBon arg(x);
- if(x == 157){
- cout<< "!!!";
- }
- else {
- x += 1.0;
- }
- return arg;
- }
- NapBon operator--(int){
- NapBon arg(x);
- if(x == 0){
- cout<< "!!!";
- }
- else {
- x -= 1.0;
- }
- return arg;
- }
- NapBon& operator=(const NapBon& arg){
- x = arg.x;
- return *this;
- }
- NapBon operator+=(NapBon arg){
- if((x + arg.x) > 157){
- cout << "!!!";
- x = 157;
- }
- else{
- x = x + arg.x;
- }
- return *this;
- }
- NapBon operator-=(NapBon arg){
- if((x - arg.x) < 0){
- cout << "!!!";
- x = 0;
- }
- else{
- x = x - arg.x;
- }
- return *this;
- }
- NapBon operator*=(NapBon arg){
- if((x * arg.x) > 157){
- cout << "!!!";
- x = 157;
- }
- else{
- x = x * arg.x;
- }
- return *this;
- }
- NapBon operator/=(NapBon arg){
- if((x / arg.x) > 157){
- cout << "!!!";
- x = 157;
- }
- else{
- x = x / arg.x;
- }
- return *this;
- }
- bool operator==(NapBon arg){
- if(x == arg.x)
- return true;
- else
- return false;
- }
- bool operator!=(NapBon arg){
- if(x != arg.x)
- return true;
- else
- return false;
- }
- bool operator>=(NapBon arg){
- if(x >= arg.x)
- return true;
- else
- return false;
- }
- bool operator<=(NapBon arg){
- if(x <= arg.x)
- return true;
- else
- return false;
- }
- bool operator<(NapBon arg){
- if(x < arg.x)
- return true;
- else
- return false;
- }
- bool operator>(NapBon arg){
- if(x > arg.x)
- return true;
- else
- return false;
- }
- };
- string kampania(NapBon x1, NapBon y1, NapBon x2, NapBon y2){
- a = (x2 - y2) / (x1 - y1);
- b = ((x1 * y2) - (x2 * y1)) / (x1 - y1);
- double tmp = a * 100.0 + 0.5;
- a = floor(tmp) / 100.0;
- double tmp2 = b * 100.0 + 0.5;
- b = floor(tmp2) / 100.0;
- if(a >= 0 && a <= 157 && b >= 0 && b <= 157 ){
- //{(a,b)};
- double a,b;
- ostringstream ss;
- ss << "{" << "(" << a << "," << b << ")" << "}";
- string str = ss.str();
- return str;
- }
- else{
- // {}
- double a,b;
- ostringstream ss;
- ss << "{" << "}";
- string str = ss.str();
- return str;
- }
- }
Add Comment
Please, Sign In to add comment