Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QCoreApplication>
- #include <QDebug>
- class Target {
- private:
- float m_x;
- float m_y;
- public:
- Target (float x = 0, float y = 0)
- {
- m_x = x;
- m_y = y;
- }
- void checkifHit () {
- //if (((m_x >= 0 && m_x <= 1)||(m_x >= 2 && m_x <= 3))&&((m_y >= 0 && m_y <= 1)||(m_y >= 2 && m_y <= 3))) {
- if (((m_x > 1 && m_x < 2) && (m_y > 1 && m_y < 2))) //Выбрасываем квадрат в 1 октанте
- qDebug() << "Not Hit";
- else if (((m_x < -1 && m_x > -2) && (m_y < -1 && m_y > -2))) //Выбрасываем квадрат в 3 октанте
- qDebug() << "Not Hit";
- else if ((m_x > 0 && m_y < 0) || (m_x < 0 && m_y > 0) || m_x > 3 || m_x < -3 || m_y > 3 || m_y < -3) //Выбрасываем все, что вне
- qDebug() << "Not hit";
- else
- qDebug() << "Hit";
- }
- };
- int main () {
- int isNumber(int check);
- while (1) {
- int menuChoice = 0;
- qDebug() << "Введите пункт меню.\n1. Ввести координаты.\n2. Выход из программы";
- menuChoice = isNumber(menuChoice);
- switch (menuChoice) {
- case 1 :
- float x, y;
- qDebug() << "Enter X and Y: ";
- if(scanf("%f%f", &x, &y)) {
- Target target(x,y);
- target.checkifHit();
- }
- else {
- qDebug() << "NaN";
- exit(0);
- }
- break;
- case 2 :
- exit(0);
- default:
- qDebug() << "Неверный пункт меню";
- break;
- }
- }
- }
- int isNumber (int check) {
- if (scanf("%d", &check)) {
- return check;
- }
- else {
- qDebug() << "NaN";
- exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement