gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
came up with Pascal task, to test me
- User
came up with Pascal task, to test me
- Assistant
came up with Pascal task, to test me
Sure! Here's a task for you to test your knowledge of Pascal programming. The task involves creating a simple program that implements a basic version of a "To-Do List" application:
Add Task:
View Tasks:
Delete Task:
Exit:
program ToDoList;
uses crt;
type
TStringArray = array[1..100] of string;
var
tasks: TStringArray;
taskCount: Integer;
choice: Integer;
procedure AddTask();
var
task: string;
begin
if taskCount < 100 then
begin
Write('Enter new task: ');
ReadLn(task);
Inc(taskCount);
tasks[taskCount] := task;
WriteLn('Task added successfully!');
end
else
WriteLn('Task list is full!');
end;
procedure ViewTasks();
var
i: Integer;
begin
if taskCount = 0 then
WriteLn('No tasks to display.')
else
begin
WriteLn('Current Tasks:');
for i := 1 to taskCount do
WriteLn(i, ': ', tasks[i]);
end;
end;
procedure DeleteTask();
var
index, i: Integer;
begin
if taskCount = 0 then
WriteLn('No tasks to delete.')
else
begin
Write('Enter task index to delete: ');
ReadLn(index);
if (index < 1) or (index > taskCount) then
WriteLn('Invalid index!')
else
begin
for i := index to taskCount - 1 do
tasks[i] := tasks[i + 1];
Dec(taskCount);
WriteLn('Task deleted successfully!');
end;
end;
end;
procedure Menu();
begin
WriteLn;
WriteLn('To-Do List Application');
WriteLn('1. Add Task');
WriteLn('2. View Tasks');
WriteLn('3. Delete Task');
WriteLn('4. Exit');
end;
begin
taskCount := 0;
repeat
clrscr;
Menu;
Write('Enter your choice: ');
ReadLn(choice);
case choice of
1: AddTask();
2: ViewTasks();
3: DeleteTask();
4: WriteLn('Exiting the application...');
else
WriteLn('Invalid choice!');
end;
if choice <> 4 then
begin
WriteLn('Press Enter to continue...');
ReadLn;
end;
until choice = 4;
end.
Once you’ve completed the task, you can run the program to test its functionality!
Not yet included in a published release.