38 lines
684 B
D
38 lines
684 B
D
module shopping;
|
|
|
|
import singlang : _;
|
|
import std.stdio : writeln;
|
|
import std.array : empty;
|
|
import std.conv : to;
|
|
|
|
string[] items;
|
|
|
|
void addItem(string item) {
|
|
items ~= item;
|
|
}
|
|
|
|
void removeItem(size_t index) {
|
|
if (index < items.length) {
|
|
items = items[0 .. index] ~ items[index + 1 .. $];
|
|
}
|
|
}
|
|
|
|
void printList() {
|
|
if (items.empty) {
|
|
writeln(_("Your shopping list is empty"));
|
|
return;
|
|
}
|
|
writeln(_("Shopping List:"));
|
|
foreach (i, item; items) {
|
|
writeln((i + 1).to!string ~ ". " ~ item);
|
|
}
|
|
}
|
|
|
|
size_t itemCount() {
|
|
return items.length;
|
|
}
|
|
|
|
void printSummary() {
|
|
writeln(_("Total items: ") ~ itemCount().to!string);
|
|
}
|