Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS246—Assignment 3 (Fall 2022)

Questions 1a, 2a, and 3a are due on Due Date 1; Question 1b, 2b, and 3b due on Due Date 2.  It is highly recommended that you attempt this assignment before the midterm however.

Note:  You must use the  C++ I/O streaming and memory management facilities on this as- signment.  Moreover, the only standard headers you may #include are <iostream>, <fstream>, <sstream>, <iomanip>, <string>, and <utility>. Marmoset will be programmed to reject sub- missions that violate these restrictions.

Note: Each question on this assignment asks you to write a C++ program, and the programs you write on this assignment each span multiple files.  Moreover, each question asks you to submit a Makefile for building your program. For these reasons, we strongly recommend that you develop your solution for each question in a separate directory. Just remember that, for each question, you should be in that directory when you create your zip file, so that your zip file does not contain any extra directory structure.

Note:   There will  be  a  handmarking  component  in this  assignment,  whose  purpose  is to  en- sure that you are following an appropriate standard of documentation and style, and to verify any assignment requirements not directly checked by Marmoset.  Please code to a standard that you would expect from someone else if you had to maintain their code.   Further comments on coding guidelines can be found here: https://www.student.cs.uwaterloo.ca/~cs246/current/ AssignmentGuidelines.shtml

Note:  You are not permitted to ask any public questions on Piazza about what the programs that make up the assignment are supposed to do. A major part of this assign- ment involves designing test cases, and questions that ask what the programs should do in one case or another will give away potential test cases to the rest of the class.  Instead, we will pro- vide compiled executables, suitable for running on linux .student .cs, that you can use to check intended behaviour.  Questions found in violation of this rule will be marked private or deleted; repeat offences could be subject to discipline.

1. In this exercise, you will write a C++ class (implemented as a struct) to control a go kart on an infinitely-large parking lot.

Your kart starts at coordinates (0,0), facing north. Use the following structure definition for coordinates:

struct  Position  {

int  ew,  ns;

Position(  int  ew  =  0,  int  ns  =  0  );

};

The east-west direction is the first component of a position, and the north-south direction is the second.  Your GoKart class must be properly initialized via a constructor, taking in a driver as an parameter, and must provide the following methods:

Method

Description

void  step()

Updates the karts velocity by its acceleration, then moves the go kart according to its velocity. Karts have no reversing gear and hence any negative velocity must be treated as if the kart had 0 velocity.

void  blueshell()

Hits the go kart with a blue shell, setting both its velocity and acceleration to 0 and setting its direction to be north if its total distance driven is divisible by 4, east if the remain- der is 1 when its total distance is divided by 4, south if the remainder is 2 when its total distance is divided by 4, and west otherwise.

void  left()

Turns the go kart 90 degrees to the left, while remaining in the same location.

void  right()

Turns the go kart 90 degrees to the right, while remaining in the same location.

void  accelerate(int  a)

Accelerates the car by a units.   Go karts thankfully have brakes and therefore a can be negative.

Position  location()

Returns the current position of the go kart.

int  distance()

Returns the total units of distance travelled by the go kart.

int  speed()

Returns the current velocity of the go kart.

int  acc()

Returns the current acceleration of the go kart.

Direction  facing()

Returns the current facing of the go kart.

std::string  driverName()

Returns the name of the  driver of the go kart.

Implement the specified operations for the GoKart.  (Some starter code has been provided for you in the file gokart .h, along with a sample executable.)  You may not change the contents of gokart .h other than by adding your instance variables and comments i.e. the interface must stay exactly the same.

The test harness a3q1 .cc is provided with which you may interact with your go kart for testing purposes. The test harness is not robust and you are not to devise tests for it, just for the GoKart class.  Do not change this file.

(a)  Due on Due Date 1: Design the test suite suiteq1 .txt for this program and zip the

suite into a3q1a .zip.

(b)  Due on Due Date 2:  Implement this in C++ and place the files in a3q1b .zip.  Call

your executable a3q1.

2. In this exercise, you will fill in the implementation of a List class.

You may recall implementing a list as a series of linked Node classes in class, where the Node  class was equipped with copy and move constructors and assignment operators. This time, however, while you will still be building a linked list of Nodes, this functionality will be implemented by the List class and not by each individual Node.  YOU MUST NOT CHANGE the provided Node class.

You will also implement a read- only forward iterator for the List class.

Starter code and method signatures have been provided in  list .h,  along with a sample executable. You may not change the contents of list .h other than by adding your own private instance methods, variables and comments i.e.  the interface must stay exactly the same.

The test harness a3q2 .cc is provided with which you may interact with your list for testing purposes. The test harness is not robust and you are not to devise tests for it, just for the List class.  Do not change this file.

(a)  Due on Due Date 1: Design the test suite suiteq2 .txt for this program and zip the

suite into a3q2a .zip.

(b)  Due on Due Date 2: Implement this in C++ and place the files Makefile, a3q2 .cc,

list .h and list .cc in the zip file, a3q2b .zip. Call your executable a3q2.

3. In this exercise, you will fill in the implementation of a TierList class, that is, a ranked collection of tiers, each tier containing the set of elements ranked at that tier.  Examples of tier lists can be found at https://tiermaker.com/.

Traditionally the tiers in the tier list have been ranked S to F, with S being the best tier and F being the worst tier.  For simplicity we will order our tiers by number, with 0 addressing the best-tier, 1 addressing the second-best tier, 2 addressing the third-best tier, and so on and so forth.

You will also implement a read- only forward iterator for the TierList class which will iterate through the tier list from the items in the best tier to the items in the worst tier in the

TierList.

In addition to the standard operations a read- only forward  iterator provides, you will also implement overrides of the << and >> operators in the iterator which return a new iterator pointing to the start of the tier that is n tiers before/after (respectively) the tier of the current item.

Starter code and method signatures have been provided in tierlist .h, along with a sample executable. You may not change the contents of tierlist .h other than by adding your own private  instance methods,  variables and comments  i.e.   the  interface must stay exactly the same.

The test harness a3q3 .cc is provided with which you may interact with your tier list for testing purposes. The test harness is not robust and you are not to devise tests for it, just for the TierList class.  Do not change this file.

(a)  Due on Due Date 1: Design the test suite suiteq3 .txt for this program and zip the

suite into a3q3a .zip.

(b)  Due on Due Date 2: Implement this in C++ and place the files Makefile, a3q3 .cc,

tierlist .h,  tierlist .cc,  along with  any  additional  files you  need,  in the  zip  file, a3q3b.zip. Call your executable a3q3.