How to implement the following.

  • Print data from a template, for example:

Vitya took% num1% apple and Maxim% num2%. How many apples do they have together?

  • I enter the answer and check it, depending on num1 + num2.
  • How to make a database of questions?

% num% is a random number.

    2 answers 2

    maybe so try? make a pattern:

    const Shablon = 'Витя взял %d яблока, а Максим %d. Сколько яблок у них вместе? '; 

    and process the template like this:

     str:= Format(Shablon,[num1, num2]) 

    where num1 and num2 are some numbers, mb even query results

    • The answer is accepted after a year. tin - teanych

    In the simplest case, the database is not needed, a text file is enough, in which there are lines with questions in a row.

    What is% num% +% num%?
    Is the identity% num% +% num% =% num% correct?
    ...

    The task is to ensure that

    • read a line from a file
    • find the occurrences of the% num% substring and replace them with random variables,
    • translate a record of the form% num% +% num% into a formula that can be calculated in Delphi.

    Write-read from file - standard with WriteLn / ReadLn, etc. Generation of random variables - Random. Substitute string substitution - StringReplace. In order to correctly perceive the formula, it is better to limit it to a certain set of previously known expressions, then from it you can mark and search for it, otherwise you will have to resort to JIT compilation and the like complex things.