Implementing a 300-Question Arithmetic Drill with Pair Programming in C++

The project generates 300 elementary arithmetic exercises (involving three operands and two operators) using C++ and renders them via a custom UI built with the EasyX graphics library. Two developers collaborated using pair programming: one focused on UI design and integration, while the other implemented core logic.

Problem Representation

A Problem class encapsulates each exercise:

class Problem {
public:
    struct Expr {
        int op1 = 0;
        int op2 = 0;
        int op3 = 0;
        char sym1;
        char sym2;
        double answer;
    };

    std::vector<Expr> expressions;
    std::string lines[30];
    LPCTSTR displayLines[30];
};

This design conflates problem generation and evaluation, reducing modularity—a flaw recognized only after implementation.

Random Exercise Generation

Exercises are generated using srand() seeded with the current time:

void generateProblems(char op1, char op2) {
    srand(static_cast<unsigned>(time(nullptr)));
    for (int i = 0; i < 30; ++i) {
        Expr expr;
        expr.op1 = rand() % 100;
        expr.op2 = rand() % 100;
        expr.op3 = rand() % 100;
        expr.sym1 = op1;
        expr.sym2 = op2;

        // Evaluate first operation
        double intermediate;
        switch (expr.sym1) {
            case '+': intermediate = expr.op1 + expr.op2; break;
            case '-': intermediate = expr.op1 - expr.op2; break;
            case 'x': intermediate = expr.op1 * expr.op2; break;
            case '/': intermediate = static_cast<double>(expr.op1) / expr.op2; break;
        }

        // Evaluate second operation
        switch (expr.sym2) {
            case '+': expr.answer = intermediate + expr.op3; break;
            case '-': expr.answer = intermediate - expr.op3; break;
            case 'x': expr.answer = intermediate * expr.op3; break;
            case '/': expr.answer = intermediate / expr.op3; break;
        }

        expressions.push_back(expr);
        // ... formatting into strings for display
    }
}

Note: Division uses floating-point to preserve precision, though input operands are integers.

UI Components

Two lightweight UI classes support rendering:

Button:

class Button {
public:
    int x = -1, y = -1;
    int width = -1, height = -1;
    LPCTSTR label = L"";
    int fontSize = 16;
    bool isVisible = false;
};

Label:

class Label {
private:
    int width, height;
public:
    int x = -1, y = -1;
    LPCTSTR text = L"";
    int fontSize = 16;
    bool isVisible = false;
};

The interface displays 30 problems per page, with navigation via a "Next Page" button. Users can select operator combinations (e.g., only addition/subtraction).

Reflection on Pair Programming

Advantages:

  • Ipmroved code quality through real-time peer review.
  • Knowledge exchange accelerated learning.
  • Faster debugging and problem resolution.
  • Enhanced communication and reduced isolation.

Challenges:

  • Occasional disagreements slowed progress.
  • Overhead from consensus-building sometimes reduced immediate productivity.

Pair programming proved beneficial overall but requires careful coordination to maximize efficiency.

Tags: C++ pair programming arithmetic generator EasyX UI Design

Posted on Fri, 19 Jun 2026 18:12:07 +0000 by minifairy