implement main open core class predicates qualify: (integer Z) nondeterm (i). clauses %…
- User
implement main
codeopen coreclass predicates
codequalify: (integer Z) nondeterm (i). clauses % Декларация фактов класса main qualify(Z) :- (Z >= 80), (Z <= 100), stdio::write ('магистр'). qualify(Z) :- (Z >= 60), ( Z < 80), stdio::write ('специалист'). qualify(Z) :- (Z >= 40), (Z < 60), stdio::write ('бакалавр'). qualify(Z) :- (Z >= 0), (Z < 40), stdio::write ('неудачник'). qualify(Z) :- (Z >= 100), stdio::write ('недопустимое значение'). % Основной предикат, к нему происходит обращение из цели run() :- console::init(), stdio::write("Введите значение Z ="), stdio::nl, hasDomain(integer,Z), Z = stdio::read(), stdio::write(Z, "\n"), stdio::nl.end implement main
goal
code% ЦЕЛЬ: mainExe::run(main::run).main.pro(7,9) warning c654 : Unused local predicate 'main::qualify/1 (i)'
- Assistant
The code you provided defines a class
mainwith a predicatequalifythat determines the qualification based on the input Z value. It also includes arunpredicate that initializes the console, reads the input Z value, and then calls thequalifypredicate to determine the qualification.To run this code, you can create a new console application and call the
mainExe::run(main::run)goal to execute therunpredicate from themainclass.Here is an example of how to run this code:
prologgoal mainExe::run(main::run).You can enter a value for Z when prompted and see the qualification based on the value entered.
- User
Закрывается консоль при вводе значения как убрать это
- Assistant
To prevent the console from closing after entering a value, you can modify the
runpredicate in themainclass to keep the console application running until you manually exit it. You can do this by adding a loop that continues to read input values until a specific exit condition is met.Here is an updated version of the
runpredicate that includes a loop for reading input values continuously:prolog% Основной предикат, к нему происходит обращение из цели run() :- console::init(), repeat, stdio::write("Введите значение Z ="), stdio::nl, hasDomain(integer,Z), Z = stdio::read(), stdio::write(Z, "\n"), stdio::nl, qualify(Z), % Call the qualify predicate to determine qualification stdio::nl, stdio::write("Для завершения введите 'exit'.\n"), % Provide option to exit hasDomain(string, Input), Input = stdio::read(), Input = "exit".