CSCI 3136 Dalhousie University Principles of Programming Languages Project 7

User Generated

FgLhZYA

Computer Science

CSCI 3136

Dalhousie University

CSCI

Description

Unformatted Attachment Preview

Assignment 7 CSCI 3136: Principles of Programming Languages Due Apr 8, 2021 Assignments are due on the due date before 23:59. Plagiarism in assignment answers will not be tolerated. By submitting their answers to this assignment, the authors named above declare that its content is their original work and that they did not use any sources for its preparation other than the class notes, the textbook, and ones explicitly acknowledged in the answers. Any suspected act of plagiarism will be reported to the Faculty’s Academic Integrity Officer and possibly to the Senate Discipline Committee. The penalty for academic dishonesty may range from failing the course to expulsion from the university, in accordance with Dalhousie University’s regulations regarding academic integrity. Question 1 On the slides on iteration, I showed you Python code for generating the sequence of all strings of length at most len over the alphabet {a, b, c, d} in lexicographically sorted order. The implementation of this iterator relied on Python’s support for coroutines — functions that can be interrupted and resumed. C++ and Java do not have support for coroutines built into the language. Provide C++ or Java code that implements an iterator object to iterate over the same sequence of strings. Note that both Java and C++ (via add-on libraries) provide support for threads, which are more general than coroutines and, thus, can be used to simulate coroutines. Do not use these facilities in your implementation but provide an implementation of a single-threaded iterator object. The detailed requirements are as follows: If you provide C++ code . . . • You should provide a class Lexy such that Lexy(len) is an object that represents the lexicographically sorted sequence of all strings of length at most len over the alphabet above. The created object should have constant size, independent of len. In particular, it must not store an explicit representation of the entire sequence of strings. • The class should provide methods begin() and end(). Both return an iterator of type Lexy::iterator. The iterator returned by begin() “points” to the first element in the sequence of strings. The one returned by end() “points” beyond the end of the sequence of strings. • The iterator class itself needs to provide a dereferencing operator and an increment operator. With these operations, the equivalent of the Python code on the slides, for w in lexy(3): print(w) becomes the standard C++ iteration idiom, Lexy l(3); for (Lexy::iterator it = l.begin(); it != l.end(); ++it) { cout
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Attached. Pleas...


Anonymous
Super useful! Studypool never disappoints.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags