Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require spd/tags)
- ;; DO NOT PUT ANY PERSONALLY IDENTIFYING INFORMATION IN THIS FILE.
- ;; YOUR COMPUTER SCIENCE IDs WILL BE SUFFICIENT TO IDENTIFY YOU
- ;; AND, IF YOU HAVE ONE, YOUR PARTNER
- ; Computer Science 110
- ; 2018W1
- ;
- ; Graded Problem Set 6
- ;
- ; Computer Science id (Student 1): x1p2b
- ; Computer Science id (Student 2): l8k2b
- ;;
- ;; In some of your courses, you may need to write reports on a specific
- ;; topic. Many reports cite other previous written reports to support
- ;; the ideas presented in the work, or to provide background information.
- ;;
- ;; For Problem Set 6, you will be working with a simplified version of
- ;; information representing a report. In this simplified version, ASSUME
- ;; that each report is only cited by one other report, and each report
- ;; can have an arbitrary number of reports it cites.
- ;;
- ;; Like any program, the first thing to think about is how to represent
- ;; the report information as data - specifically how to represent a single
- ;; report as data.
- ;;
- ;; For this problem set, each report has a title, and author, a list of
- ;; keywords that the report is about, and a list of other reports the
- ;; given report referenced (cited).
- ;;
- ;; Please carefully read through the data definition for a report provided
- ;; for you below. You should get out a pen and paper to trace out which
- ;; reports cite which other reports to better visualize the structure of
- ;; reports given in the examples below.
- ;;
- (@HtDD Report ListOfReport ListOfString)
- (define-struct report (title author keywords cites))
- ;; Report is (make-report String String ListOfString ListOfReport)
- ;; interp. a report with a title and a single author name,
- ;; with a list of keywords to categorize the report,
- ;; and a list of other reports cited
- ;; ListOfReport is one of:
- ;; - empty
- ;; - (cons Report ListOfReport)
- ;; interp. a list of reports
- ;; ListOfString is one of:
- ;; - empty
- ;; - (cons String ListOfString)
- ;; interp. a list of strings
- (define LOS0 empty)
- (define LOS1 (list "Transportation"))
- (define LOS2 (list "Kiczales" "Ola" "Estey"))
- (define LOR0 empty)
- (define R0 (make-report "Public transportation vs Car2Go" "A. Lee" LOS1 empty))
- (define R1 (make-report "Fastest Growing Programs at UBC"
- "Grace Hopper"
- (list "Enrollment" "Higher Education" "Careers")
- empty))
- (define R2 (make-report "Apprenticeship Expectations"
- "Art Ison"
- (list "Salary")
- empty))
- (define LOR1 (list R1 R2))
- (define R3 (make-report "Trade School or University"
- "Ed Youkaytion"
- (list "Employment" "Future" "Salary")
- LOR1))
- (define R4 (make-report "Best Careers for 2020 and Beyond"
- "Grace Hopper"
- (list "Employment" "Salary" "Careers")
- (list R3)))
- (define R5 (make-report "DOTA2: $25 Million on the Line"
- "IceFrog"
- (list "E-sports" "Careers" "Video Game" "MOBA")
- empty))
- (define R6 (make-report "Canucks Promising Youngsters"
- "P. Bure"
- (list "NHL" "Prospects" "Vancouver Canucks" "Salary")
- empty))
- (define R7 (make-report "Why everyone must see Cirque du Soleil"
- "Holly Wood"
- (list "Acrobatics" "Drama" "Theatre")
- empty))
- (define R8 (make-report "Quickest Events to Sell Out"
- "Holly Wood"
- (list "Entertainment" "Events" "Sports" "Tickets")
- (list R5 R6 R7)))
- (define R9 (make-report "Vancouver Interest"
- "G. Robertson"
- (list "Vancouver" "Lower Mainland" "News and Events")
- (list R0 R4 R8)))
- (define (fn-for-report r)
- (... (report-title r)
- (report-author r)
- (fn-for-los (report-keywords r))
- (fn-for-lor (report-cites r))))
- (define (fn-for-lor lor)
- (cond [(empty? lor) (...)]
- [else
- (... (fn-for-report (first lor))
- (fn-for-lor (rest lor)))]))
- (define (fn-for-los los)
- (cond [(empty? los) (...)]
- [else
- (... (first los)
- (fn-for-los (rest los)))]))
- (@Problem 1)
- ;;
- ;; Assume that your instructor has tasked you with reading a report
- ;; AND all the reports that report has cited (and all the reports
- ;; those reports cite, etc). The first thing you might want to do is
- ;; count how many reports you'll need to read.
- ;;
- ;; Design a function that will do this for you. Given a report, the
- ;; function should produce a count of the number of all reports reachable
- ;; from that report by going through all of the cited reports.
- ;;
- ;; Remember that for all functions operating on mutually referential types,
- ;; you must group your function definitions in the new way.
- (@HtDF report-count)
- (@signature Report -> Natural)
- ;; produce count of total reports reachable by given report
- (check-expect (report-count R0) 1)
- (check-expect (report-count R1) 1)
- (check-expect (report-count R8) 4)
- (check-expect (report-count R9) 10)
- ;(define (report-count r) 0) ;stub
- (@template Report)
- (define (report-count r)
- (cond [(empty? (report-cites r)) 1]
- [else
- (+ 1 (lor-count (report-cites r)))]))
- (@HtDF lor-count)
- (@signature ListOfReport -> Natural)
- ;; produce first report from list of reports
- (check-expect (lor-count LOR0) 0)
- (check-expect (lor-count LOR1) 2)
- (check-expect (lor-count (list R1 R2 R3 R7)) 6)
- (@template ListOfString)
- (define (lor-count lor)
- (cond [(empty? lor) 0]
- [else
- (+ (report-count (first lor))
- (lor-count (rest lor)))]))
- (@Problem 2)
- ;;
- ;; Design a function that consumes a report and a keyword, and produces
- ;; a list of the names of reports with the given keyword.
- ;;
- ;; FYI, there is a built-in function called member that consumes
- ;; a String and ListOfString and produces true if the String is
- ;; in the list.
- (@HtDF list-report)
- (@signature Report -> ListOfReport)
- ;;takes keyword and produces list that matches reports
- (check-expect (list-report R1 "Careers") (list R1))
- (check-expect (list-report R2 "Income") empty)
- ;(define (list-report r s) empty) ;stub
- (@template ListOfReport)
- (define (list-report lor)
- (cond [(empty? lor) empty]
- [else
- (list (fn-for-report (first lor))
- (list-report (rest lor)))]))
- (@template Report)
- (define (create-report r)
- (... (report-title r)
- (report-author r)
- (fn-for-los (report-keywords r))
- (fn-for-lor (report-cites r))))
- ;(@template Report)
- ;(define (list-report r s)
- ; (if (string=? (fn-for-poop (report-keywords r)) s)
- ; (cons (first r) (list-report (rest r) s))
- ; empty))
- ;
- ;(define (list-report r s)
- ; (cond [(empty? r) empty]
- ; [else
- ; (if (fn-for-shit r s)
- ; (list (first r) (list-report (rest r) s))
- ; (list-report (rest r) s))]))
- ;
- ;(define (fn-for-shit r s)
- ; [(empty? (report-keyboards r)) empty]
- ; [else
- ; (
- ;
- ;;
- ;(@HtDF los-keywords)
- ;(@signature ListOfReport -> String)
- ;;; produces report upon matching keywords
- ;(check-expect (lor-keywords LOR0 "") empty)
- ;(check-expect (lor-keywords LOR1 "Salary") (list R2))
- ;(check-expect (lor-keywords (list R1 R2 R3 R4) "Salary") (list R2 R3 R4))
- ;
- ;;(define (los-keywords lor s) empty)
- ;
- ;(@template ListOfString)
- ;(define (los-keywords los)
- ; (cond [(empty? los) empty]
- ; [else
- ; (list (first los)
- ; (los-keywords (rest los)))]))
- ;;(define (lor-keywords lor s)
- ;; (cond [(empty? lor) empty]
- ;; [else
- ;; (list (first lor) (lor-keywords))
- ;; [(string=? (report-keywords (first lor)) s) (list (first lor) (lor-keywords (rest lor) s))]
- ;; [else
- ;; (list (lor-keywords (rest lor) s))]))
- ;
- (@Problem 3)
- ;;
- ;; Design a function that consumes a report and a title.
- ;; Search the given report and all cited reports for a report with the
- ;; given title, and if found, produce that report.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement