# source:doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa

Last change on this file was e26a842, checked in by Peter A. Buhr <pabuhr@…>, 11 days ago

update example programs

• Property mode set to `100644`
File size: 1.5 KB
Line
1#include <fstream.hfa>
2#include <stdlib.hfa>
3#include <array.hfa>
4#include <locale.h>                                                     // setlocale
5
6
7
8
9
10forall( T, @[NprovTerty]@, @[Nmunicipalities]@ )
12        array( T, @NprovTerty@ ) provTerty; \$\C{// nested VLA}\$
13        array( T, @Nmunicipalities@ ) municipalities; \$\C{// nested VLA}\$
14        int total_pt, total_mun;
15};
16
17
18// TODO: understand (fix?) why these are needed (autogen seems to be failing ... is typeof as struct member nayok?)
19
20forall( T, [NprovTerty], [Nmunicipalities] )
21        void ?{}( T &, CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {}
22
23forall( T &, [NprovTerty], [Nmunicipalities] )
24        void ^?{}( CanadaPop( T, NprovTerty, Nmunicipalities ) & this ) {}
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40forall( T, [NprovTerty], [Nmunicipalities] )
41void check( CanadaPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) {
42        total_pt = total_mun = 0;
43        for ( i; NprovTerty ) total_pt += provTerty[i];
44        for ( i; Nmunicipalities ) total_mun += municipalities[i];
45}
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60int main( int argc, char * argv[] ) {
61        const int npt = ato( argv[1] ), nmun = ato( argv[2] );
62        @CanadaPop( int, npt, nmun ) pop;@
63        // read in population numbers
64        @check( pop );@
65        sout | setlocale( LC_NUMERIC, getenv( "LANG" ) );
66        sout | "Total province/territory:" | pop.total_pt;
67        sout | "Total municipalities:" | pop.total_mun;
68}
69/*
70\$\\$\$ ./a.out  13  3573
71Total province/territory: 36,991,981
72Total municipalities: 36,991,981
73*/
74
75// Local Variables: //
76// compile-command: "sed -f sedcmd hello-accordion.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" //
77// End: //
Note: See TracBrowser for help on using the repository browser.