Другие языки программирования и технологии
помогите пожалуста решить задачу на СИ++..
Разработайте программу, в которой реализована перегрузка оператора «>». Оператор «>» должен увеличивать число на то количество единиц, которое укажет пользователь.
#include <iostream>
using namespace std;
class Bydlocoder {
public:
Bydlocoder() { };
Bydlocoder(int _n) : n(_n) { }
operator int() const { return n; }
friend Bydlocoder & operator>(Bydlocoder &, const int);
friend ostream & operator<<(ostream &, const Bydlocoder &);
friend istream & operator>>(istream &, Bydlocoder &);
Bydlocoder & operator=(const int);
private:
int n;
};
typedef Bydlocoder INT;
int main() {
locale::global(locale(""));
INT x = 5;
cout << " До: " << x << endl;
x = x > 5;
cout << " После: " << x << endl;
cout << " Введите целое число: ";
INT y;
cin >> y;
cout << " Вы ввели: ";
cout << y << endl;
cout << " Введите целое число, чтобы прибавить его к ранее введённому: ";
int k;
cin >> k;
y = y > k;
cout << " Сумма = " << y << endl;
cin.get(); cin.get();
return 0;
}
Bydlocoder & operator>(Bydlocoder & _int, const int _dx) {
_int.n += _dx;
return _int;
}
Bydlocoder & Bydlocoder::operator=(const int _n) {
this->n += _n;
return *this;
}
ostream & operator<<(ostream & _cout, const Bydlocoder & _int) {
_cout << _int.n;
return _cout;
}
istream & operator>>(istream & _cin, Bydlocoder & _int) {
_cin >> _int.n;
return _cin;
}
А это мои пять копеек во вклад современного образования!
using namespace std;
class Bydlocoder {
public:
Bydlocoder() { };
Bydlocoder(int _n) : n(_n) { }
operator int() const { return n; }
friend Bydlocoder & operator>(Bydlocoder &, const int);
friend ostream & operator<<(ostream &, const Bydlocoder &);
friend istream & operator>>(istream &, Bydlocoder &);
Bydlocoder & operator=(const int);
private:
int n;
};
typedef Bydlocoder INT;
int main() {
locale::global(locale(""));
INT x = 5;
cout << " До: " << x << endl;
x = x > 5;
cout << " После: " << x << endl;
cout << " Введите целое число: ";
INT y;
cin >> y;
cout << " Вы ввели: ";
cout << y << endl;
cout << " Введите целое число, чтобы прибавить его к ранее введённому: ";
int k;
cin >> k;
y = y > k;
cout << " Сумма = " << y << endl;
cin.get(); cin.get();
return 0;
}
Bydlocoder & operator>(Bydlocoder & _int, const int _dx) {
_int.n += _dx;
return _int;
}
Bydlocoder & Bydlocoder::operator=(const int _n) {
this->n += _n;
return *this;
}
ostream & operator<<(ostream & _cout, const Bydlocoder & _int) {
_cout << _int.n;
return _cout;
}
istream & operator>>(istream & _cin, Bydlocoder & _int) {
_cin >> _int.n;
return _cin;
}
А это мои пять копеек во вклад современного образования!
Вот так быдлокодеров и растят.. . Перегрузка не должна менять поведение операторов! Может, но не должна! Код будет совершенно нечитаемым.. .
#include <cmath>
#include <iostream>
class num {
int v;
public:
num(): v(0) {}
int operator()() { return v; }
friend num& operator>(num &v, int n) { v.v += n; return v; }
};
int main() {
num n;
std::cout << n() << std::endl;
n > 5;
std::cout << n() << std::endl;
}
ЗЫ:
> Оператор «>» должен увеличивать число.. .
Кэп все верно сказал. Это неправильно. Преподу передай привет от "ответов" и процитируй ответ Кэпа.
#include <iostream>
class num {
int v;
public:
num(): v(0) {}
int operator()() { return v; }
friend num& operator>(num &v, int n) { v.v += n; return v; }
};
int main() {
num n;
std::cout << n() << std::endl;
n > 5;
std::cout << n() << std::endl;
}
ЗЫ:
> Оператор «>» должен увеличивать число.. .
Кэп все верно сказал. Это неправильно. Преподу передай привет от "ответов" и процитируй ответ Кэпа.
Похожие вопросы
- Помогите решить задачи на Си! Пожалуйста!!!
- Помогите пожалуйста решить задачу по программированию или напишите, как удалить подряд стоящие точки. (Си, Си++ Билдер)
- ПОМОГИТЕ РЕШИТЬ задачи по Си
- помогите решить задачу по Си
- Помогите пожалуйста решить задачи по информатике, одномерные массивы. Си шарп. Очень срочно. Пожалуйста!!!!
- Помогите решить задачу на си++
- Помогите пожалуйста решить задачу по программированию (язык программирования СИ)
- помогите решить задачи по Си. 2 неделю с ними бьюсь. выкладываю свое решение. скажите просто что не правильно
- помогите пожалуйста решить задачу по работе компьютера!
- Помогите,пожалуйста,решить задачу в Паскале.