Advertisement
Iamlugano

Untitled

Oct 11th, 2011
2,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 1.95 KB | None | 0 0
  1. class
  2.     BUSINESS_CARD
  3.  
  4. create
  5.     fill_in
  6.  
  7. feature {NONE} -- Initialization
  8.  
  9.     fill_in
  10.             -- Fill in the card and print it.
  11.         do
  12.             io.put_string ("Your name: ")
  13.             io.read_line
  14.             set_name(io.last_string)
  15.  
  16.             io.put_string ("Your job: ")
  17.             io.read_line
  18.             set_job(io.last_string)
  19.  
  20.             io.put_string ("Your age: ")
  21.             io.read_integer
  22.             set_age(io.last_integer)
  23.  
  24.             io.put_string (print_card)
  25.  
  26.         end
  27.  
  28. feature -- Access
  29.  
  30.     name: STRING
  31.             -- Owner's name.
  32.  
  33.     job: STRING
  34.             -- Owner's job.
  35.  
  36.     age: INTEGER
  37.             -- Owner's age.
  38.  
  39. feature -- Setting
  40.  
  41.     set_name (a_name: STRING)
  42.             -- Set `name' to `a_name'.
  43.         require
  44.             name_exists: a_name /= Void
  45.         do
  46.             name := a_name.twin
  47.         end
  48.  
  49.     set_job (a_job: STRING)
  50.             -- Set `job' to `a_job'.
  51.         require
  52.             job_exists: a_job /= Void
  53.         do
  54.             job := a_job.twin
  55.         end
  56.  
  57.     set_age (a_age: INTEGER)
  58.             -- Set `age' to `a_age'.
  59.         require
  60.             age_non_negative: a_age >= 0
  61.         do
  62.             age := a_age
  63.         end
  64.  
  65. feature -- Output
  66.  
  67.     name_info: STRING
  68.             -- Text representation of name on the card
  69.         do
  70.             Result := name.out
  71.         end
  72.  
  73.     job_info: STRING
  74.             -- Text representation of job on the card
  75.         do
  76.             Result := job.out
  77.         end
  78.  
  79.     age_info: STRING
  80.             -- Text representation of age on the card.
  81.         do
  82.             Result := age.out + " years old"
  83.         end
  84.  
  85.     print_card: STRING
  86.             --Declares what to put on the business card
  87.         do
  88.             Result := line(width) + "%N" + "|" + name_info + spaces(width - (1 + name_info.count)) + "|" + "%N" + "|" + job_info +
  89.             spaces(width - (1 + job_info.count)) + "|" + "%N" + "|" + age_info + spaces(width - (1 + age_info.count)) + "|" + "%N" + line(width)
  90.         end
  91.  
  92.     Width: INTEGER = 50
  93.             -- Width of the card (in characters), excluding borders.
  94.  
  95.     line (n: INTEGER): STRING
  96.             -- Horizontal line on length `n'.
  97.         do
  98.             Result := "-"
  99.             Result.multiply (n)
  100.         end
  101.  
  102.     spaces (n: INTEGER): STRING
  103.             --Inserts `n' spaces.
  104.         do
  105.             Result := " "
  106.             Result.multiply (n)
  107.         end
  108.  
  109. end
  110.  
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement