Lab 10, Esc101, 2004-05 Semester-II

Solve the following problems


Problem 1

Write a class PolyList, to represent a polynomial as a list.  Each element of the list should contain the coefficient as well as the exponent of a term of the polynomial.  Write a method to return the degree of the polynomial.
                                                                               
For extra interest  (Not to be Evaluated):

- Write a method in PolyList to add a given PolyList as argument, and
return a third new PolyList
- Do the same now for multiplication



Problem 2    Tic-Tac-Toe

You are very likely to have played this paper and pencil game with your friends in school. The game is played on a 3X3 grid between two players. All squares in the grid are empty initially, one player places "0" in an unfilled square and the other one places a "1" in an available square. Players move alternately and the one who first fills an entire row or a column or a diagonal with his symbol, wins the game.

In this lab you will be writing a program to play this game between two users who interacts with the program through keyboard inputs. The users feed their moves  through keyboard in accordance with some fixed conventions (like which square in the grid is denoted by which number). These conventions are displayed by the program when the game begins.

Here is a sample run.

--------------------------FIRST SAMPLE RUN BEGINS--------

Welcome to Tic_Tac_Toe

Squares on grid will be denoted by numbers as below

1|2|3

4|5|6

7|8|9

First player moves will be displayed as 0 and Second players' as 1 on the grid

First Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

5

 | |

 |0|

 | |


Second Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

 4

 | |

1|0|

 | |


First Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

9

 | |

1|0|

 | |0


Second Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

1

1| |

1|0|

 | |0


First Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

3

1| |0

1|0|

 | |0


Second Player move Please!, choose an unfilled square

(Type the number corresponding to it followed by Enter)

7

1| |0

1|0|

1| |0


Second Player wins the game. Game over.