Josh
Josh

Reputation: 519

using structure definitions

i've been pulling my hair trying to figure this out. i'm suppose to design a function takes in a hstudent, i get another student with the same contents and with his age converted into dog years. any ideas on how to start? This exact question is going to be on an open book test I have on Friday.

(define-struct hsstudent (first-name last-name classroom overall-grade age))

(define hsstudent1 (make-hsstudent "Randy" "Smith" 'WH '-A 14))
(define hsstudent2 (make-hsstudent "Jon" "James" 'AH '-A 13 ))
(define hsstudent3 (make-hsstudent "Alex" "Manzi" 'LO '+A 16))
(define hsstudent4 (make-hsstudent "Kevin" "Matthews" 'WH '-A 14))
(define hsstudent5 (make-hsstudent "Issac" "Lewis" 'AH '-A 13 ))
(define hsstudent6 (make-hsstudent "Michael" "Gabbin" 'LO '+A 16))

Upvotes: 0

Views: 64

Answers (2)

dyoo
dyoo

Reputation: 12003

Note: when you say design, that implies you're in a HTDP-based course.

You should already have been introduced to a very concrete set of steps to follow for designing functions that consume and produce structures. Have you looked at Designing with Structures and followed the steps there? If so, are you stuck at any particular step listed here?

The purpose of this methodology is to help pinpoint conceptual problems as soon as possible, rather than at coding time.

Upvotes: 3

Warwick Masson
Warwick Masson

Reputation: 883

What you could do is use the struct selectors to get the values from the student and then give those to make-hsstudent in order to make a new student. For example

(hsstudent-age hsstudent1)

Will return 14. Generally (hsstudent-FIELDNAME student) will give the field value of FIELDNAME for student.

Upvotes: 1

Related Questions