HP Prime Graphing Wireless Calculator Uživatelský manuál Strana 618

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 701
  • Tabulka s obsahem
  • ŘEŠENÍ PROBLÉMŮ
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 617
FOR k FROM 1 TO n DO
ROLLDIE(sides)+ROLLDIE(sides) roll;
L2(roll)+1 L2(roll);
END;
END;
By omitting the EXPORT command when a function is declared, its visibility can be restricted to the program
within which it is
dened. For example, you could dene the ROLLDIE function inside the ROLLMANY
program like this:
ROLLDIE();
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll;
// initialize list of frequencies
MAKELIST(0,X,1,2*sides,1) L2;
FOR k FROM 1 TO n DO
ROLLDIE(sides)+ROLLDIE(sides) roll;
L2(roll)+1 L2(roll);
END;
END;
ROLLDIE(n)
BEGIN
RETURN 1+RANDINT(n-1);
END;
In the second version of the ROLLMANY program, there is no ROLLDIE function exported from another
program. Instead, ROLLDIE is visible only to ROLLMANY. The ROLLDIE function must be declared before it is
called. The
rst line of the program above contains the declaration of the ROLLDIE function. The denition
of the ROLLDIE function is located at the end of the program.
Finally, the list of results could be returned as the result of calling ROLLMANY instead of being stored directly
in the global list variable, L2. This way, if the user wanted to store the results elsewhere, it could be done
easily.
ROLLDIE();
EXPORT ROLLMANY(n,sides)
BEGIN
LOCAL k,roll,results;
// initialize list of frequencies
MAKELIST(0,X,1,2*sides,1) results;
570 Chapter 28 Programming in HP PPL
Zobrazit stránku 617
1 2 ... 613 614 615 616 617 618 619 620 621 622 623 ... 700 701

Komentáře k této Příručce

Žádné komentáře