MatMod logo

Exercise in Write II (exer-format1)

Run LPL Code  ,  PDF Document

Problem

Generate the following output using Write() and Format(), putting random digits into the cells as follows (it is used to print a time-table:

 Teaching time-table for class 1 Day:     Mo  Tu  We  Th  Fr Time 1   kn  bu  cz  co  by Time 2   by      bu      gu Time 3   gs          be  eb Time 4   kr  er  kn  gu Time 5   kn      lb  er  ga Time 6   gu  gu      be  ga Time 7       ly  gb  by Time 8   kn  fi      cz  gs Teaching time-table for class 2 Day:     Mo  Tu  We  Th  Fr Time 1               lb .... etc..... 

Solution

Listing 1: The Complete Model implemented in LPL [2]

  model exerWrite1  "Exercise in Write II"; 
    set p := 1..20  "Teachers/courses"; 
        c := 1..10  "Classes"; 
        d := ['Mo','Tu','We','Th','Fr'] "Weekdays"; 
        t := 1..8   "Time slot in a day"; 
    string parameter T{p} := //teachers 
      ['ae','by','lb','be','br','bu','cz', 
       'co','eb','er','fi','ga','gb','gs','gu', 
       'kr','kn','kb','ly','mo']; 
    string parameter R{c,t,d} := if(Rnd(0,1)<=0.7, T[Rnd(1,20)]); 
    Write{c}('Teaching time-table for class %s' nDay: %4s ' n%s' n', 
      c,{d} d, Format{t}('Time %1d %4s' n',t,{d} R)); 
  end

References

[1]   MatMod. Homepage for Learning Mathematical Modeling :  https://matmod.ch.

[2]   Hürlimann T. Reference Manual for the LPL Modeling Language, most recent version. https://matmod.ch/lpl/doc/manual.pdf.