Арифметическое c операций с использованием OOP - PullRequest
0 голосов
/ 28 апреля 2020

Я хочу создать программу, в которой пользователь будет вводить свой ответ на следующие вопросы, и программа проверит, является ли его ответ хорошим или нет. Но я получаю ошибку операции :: вычисления должны возвращать значение. У меня есть следующие запросы: 1. Как я могу удалить эту ошибку? 2. Правильно ли я написал свой код OOP? 3. Есть ли другой способ, которым я могу написать этот код более эффективно?

Мои коды показаны ниже:

#include<iostream>
#include<string>

using namespace std;

class operations {
    int res1,res2,r_a,r_b;

public:
    operations();
    operations(int  r1, int r2,int ra, int rb,);
    int calculations();
    int display();
    ~operations();
};
operations::operations() {
    res1 = 0;
    res2 = 0;
    r_a = 0;
    r_b = 0;
}
operations::operations(int r1, int r2,int ra, int rb, int rc) {
    res1 = r1;
    res2 = r2;
    r_a = ra;
    r_b = rb;
}

int operations::calculations() {
    cout << "Complete the following." << endl;

    cout << "(a) 34 + 5 = ";
    res1 = 34 + 5;
    cin >> r_a;
    if (r_a != res1)
        cout << "Wrong! The correct answer is " << res1 << endl;
    else
        cout << "Correct!" << endl;
    cout << endl;
    cout << "(b) 56 + 702 = ";
    res2 = 56 + 702;
    cin >> r_b;

    if (r_b != res2)
        cout << "Wrong! The correct answer is " << res2 << endl;
    else
        cout << "Correct" << endl;
}
int operations::display(){
    int basic;
    basic = calculations();
    return basic;
}
operations::~operations() {
}
int main() {
    operations o;
    o.display();
    return 0;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...