## 滑铁卢大学cs115代写

Assignment 5
Due date: Wednesday, February 16th, 5:00 pm Eastern Time
Coverage: Module 06
Files to submit: a05q1.rkt, a05q2.rkt, a05q3.rkt
Assignment Guidelines
Language Level
– Beginning Student with List Abbreviations
General Expectations
– Remember to use defined constants and helper functions where appropriate.
– Follow the full design recipe and the Coding Style document up to and including Section $3.6 .2 .$
Allowable Racket Functions and Special Forms
– define, and, or, not, cond, else, check-expect, check-within, equal?
– Any type predicate such as number? or boolean?
– Any functions on numbers found in Section $2.6$ of the Racket documentation
– Any functions on characters found in Section_2.11_of_the_Racket_decumentation
– Any functions on strings found in Section_2.12. of the_Racket_documentation
– The function symbol=?
– The list functions and values cons, first, second, third, rest, empty, empty?, and list
– You must not use boolean=?
Other Information
– All test data for correctness will always meet the stated assumptions for consumed values.

Problem 1.

Question 1: Prime Factor Decomposition|
A positive integer can be written uniquely as a product of prime factors. We call this prime factor decomposition. For example, $24=2^{3} \cdot 3$, and $42=2 \cdot 3 \cdot 7$.
We will create a new data type, a special kind of list, to represent this kind of data:
1 ;; A PFD, or prime factor decomposition, is a (listof Nat)
2 ;; Requires: the elements are in ascending order
3 ;; the elements are prime numbers.
Include this data definition in your file.
Instead of storing exponents, we will just list the prime factors, with repetition. So $24=2^{3} \cdot 3=2 \cdot 2 \cdot 2 \cdot 3$ will be represented as ( $l$ ist 2223 ), and $42=2 \cdot 3 \cdot 7$ will be
represented as ( list $2.37$ ). The number 1 is the result of the Empty Product, so its prime factor decomposition is empty. A prime number has only one prime factor, so the PFD of a
prime will be a list that contains that value only.
Write a function pfd. It consumes a positive integer $n$, and produces the PFD that represents $n$. For example,
$>(p f d 12)$
\begin{aligned} 1 & ; \text { A PFD, or } \\ 2 & ; ; \text { Requires: } \\ 3 & ; ; \end{aligned}
Include this data definition
represented as ( list 237
prime will be a list that contair
Write a function pfd. it consu
$>($ pfd 12$)$
(list 2 2 3)
(list 223 )
$>(p f d$ 1)
empty
> (pfd 8191) ; a Mersenne prime:
(list 8191)
You can generate the solution list in the correct order using an appropriate recursion on natural numbers. It should not be necessary to sort.

Problem 2.

Question 2: Scrabble Sorting
Sometimes when sorting, we want to sort using a property of each value, instead of the value itself. Then we have to consider what to do for values for which the property is equal. Which should we prefer? criterion is unchanged. previously came after “was”, and now comes before.

Problem 3.

We are going to think about lists of length exactly 3, representing an author, title, and number of pages. Each such list we will call a Book. Because Book is a compound, we’ll include a constructor and and selectors for it:

# CS 115 – Introduction to Computer Science 1School of Computer ScienceUniversity of Waterloo

### Where to Begin

Welcome to CS 115!The Winter 2022 term offering of this course will be delivered through UW Online: online.cs.uwaterloo.ca.

Directions on how to access this site can be found on Learn.

### Course Philosophy

CS 115 has been designed with the diverse interests, backgrounds, and goals of students always in mind. As we are aware of the varied ways in which this material might be of use in the future, we have included concepts that are beautiful and universal. The focus of the course is foundational concepts in computer science (rather than the mechanics of programming) and ways of thinking about computation (rather than solving tasks in a rote fashion). Students will learn skills that are applicable to new languages and environments, not just those used in the course. Because of the fundamental nature of the concepts taught in CS 115, the course can serve both students whose primary interest in computers is in their use in their chosen areas of study and students intending to minor in CS.

### Communication

For questions related to course content, contact an instructor or an ISA. The best place to ask questions is on the edX discussion forum, email or during office hours. For questions about marking, contact the ISAs first, who will consult with the ISC or Instructor if necessary. Contact information for ISAs and Instructors can be found on edX.

### Instructional Support Coordinator (ISC)

Barbara Daly
Email: [email protected]
MS Teams: Barbara Daly

### FAQ

#### I have registered during the first week of classes after the first day of classes, what do I do?

When you register for a course you will not be added to Learn or our class roster until the next day. On that day, log into Learn and read the announcement from Monday May 10.