Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class
- BUSINESS_CARD
- create
- fill_in
- feature {NONE} -- Initialization
- fill_in
- -- Fill in the card and print it.
- do
- io.put_string ("Your name: ")
- io.read_line
- set_name(io.last_string)
- io.put_string ("Your job: ")
- io.read_line
- set_job(io.last_string)
- io.put_string ("Your age: ")
- io.read_integer
- set_age(io.last_integer)
- io.put_string (print_card)
- end
- feature -- Access
- name: STRING
- -- Owner's name.
- job: STRING
- -- Owner's job.
- age: INTEGER
- -- Owner's age.
- feature -- Setting
- set_name (a_name: STRING)
- -- Set `name' to `a_name'.
- require
- name_exists: a_name /= Void
- do
- name := a_name.twin
- end
- set_job (a_job: STRING)
- -- Set `job' to `a_job'.
- require
- job_exists: a_job /= Void
- do
- job := a_job.twin
- end
- set_age (a_age: INTEGER)
- -- Set `age' to `a_age'.
- require
- age_non_negative: a_age >= 0
- do
- age := a_age
- end
- feature -- Output
- name_info: STRING
- -- Text representation of name on the card
- do
- Result := name.out
- end
- job_info: STRING
- -- Text representation of job on the card
- do
- Result := job.out
- end
- age_info: STRING
- -- Text representation of age on the card.
- do
- Result := age.out + " years old"
- end
- print_card: STRING
- --Declares what to put on the business card
- do
- Result := line(width) + "%N" + "|" + name_info + spaces(width - (1 + name_info.count)) + "|" + "%N" + "|" + job_info +
- spaces(width - (1 + job_info.count)) + "|" + "%N" + "|" + age_info + spaces(width - (1 + age_info.count)) + "|" + "%N" + line(width)
- end
- Width: INTEGER = 50
- -- Width of the card (in characters), excluding borders.
- line (n: INTEGER): STRING
- -- Horizontal line on length `n'.
- do
- Result := "-"
- Result.multiply (n)
- end
- spaces (n: INTEGER): STRING
- --Inserts `n' spaces.
- do
- Result := " "
- Result.multiply (n)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement