How to resolve the algorithm Table creation/Postal addresses step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Table creation/Postal addresses step by step in the ALGOL 68 programming language

Table of Contents

Problem Statement

Create a table to store addresses. You may assume that all the addresses to be stored will be located in the USA.   As such, you will need (in addition to a field holding a unique identifier) a field holding the street address, a field holding the city, a field holding the state code, and a field holding the zipcode.   Choose appropriate types for each field. For non-database languages, show how you would open a connection to a database (your choice of which) and create an address table in it. You should follow the existing models here for how you would structure the table.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Table creation/Postal addresses step by step in the ALGOL 68 programming language

Source code in the algol programming language

MODE ADDRESS = STRUCT(
	INT page,
	FLEX[50]CHAR street,
	FLEX[25]CHAR city,
	FLEX[2]CHAR state,
	FLEX[10]CHAR zip
);
FORMAT address repr = $"Page: "gl"Street: "gl"City: "gl"State: "gl"Zip: "gll$;

INT errno;
FILE sequence; errno := open(sequence, "sequence.txt", stand back channel);
SEMA sequence sema := LEVEL 1;

OP NEXTVAL = ([]CHAR table name)INT: (
  INT out;
  # INT table page = 0; # # only one sequence implemented #
  # DOWN sequence sema; # # NO interprocess concurrency protection #
    on open error(sequence, 
      (REF FILE f)BOOL: (
        reset(sequence); #set(table page,1,1);# 
        put(sequence, 0);
        try again;
        FALSE
      )
    );
    try again:
    reset(sequence); #set(table page,1,1);# get(sequence,out);
    out +:=1; 
    reset(sequence); #set(table page,1,1);# put(sequence,out);
  # UP sequence sema; #
  out
);

OP INIT = (REF ADDRESS self)REF ADDRESS: ( page OF self := NEXTVAL "address"; self);

REF ADDRESS john brown = INIT LOC ADDRESS;

john brown := (page OF john brown, "10 Downing Street","London","England","SW1A 2AA");

printf((address repr, john brown));

FILE address table;
errno := open(address table,"address.txt",stand back channel);
# set(address table, page OF john brown,1,1);  - standard set page not available in a68g #
put bin(address table, john brown);
close(address table)

  

You may also check:How to resolve the algorithm Keyboard input/Flush the keyboard buffer step by step in the Action! programming language
You may also check:How to resolve the algorithm Concurrent computing step by step in the Elixir programming language
You may also check:How to resolve the algorithm Levenshtein distance/Alignment step by step in the Arturo programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the Brat programming language
You may also check:How to resolve the algorithm Associative array/Creation step by step in the zkl programming language