< Back

Assignment 1

This is an individual assignment. You should create a directory called assignment1 in cs170/assignments for this assignment. All code written for this assignment should be stored in that directory.

    $ cd ~/cs170/assignments
    $ mkdir assignment1 
    $ cd assignment1 


Connect 4

This is a C++ assignment. Your goal is to write a program that allows two players to play a terminal based version of connect 4.

Connect 4 is a \(6 \times 7\) grid in which players take turns placing tokens in the grid. Tokens fall all the way to the bottom of the grid when placed in a particular column. The goal of the game is to get 4 of your tokens adjacent in a particular row, column, or diagonal.

Before each turn, the current state of the board should be displayed. Empty locations should appear as a space, and you should choose two different characters to represent each player.

Your program should alternatively ask a user to input an integer representing a column. If the user were to select an invalid column (either outside the bounds of the board, or a full column), it should prompt the user for a different column selection. The game should continue until one of the players gets 4 in a row, or until the board is completely full.


Pseudocode

One important skill we hope to get across this semester is how much starting on paper actually helps write programs. We are going to force you to do so starting with this assignment.

For Monday, January 23rd, ON PAPER perform the top-down design discussed in class on Monday for this assignment. You must have a good outline of the "main" portion of your program by Monday. For any sufficiently complicated block of code, define a function and write the Pre and Post conditions for the functions. You do not have to have written the function bodies by Monday, but it should be obvious how to write the function bodies based on the Pre and Post conditions.

These are worth 30 points of your assignment grade. They will be graded 50% on completion, and 50% on correctness. It does not sound like a lot, but they should be 30 easy points to get each week. Do not neglect them.

I will provide a top-down design of the program in class on Monday.


Your program should include the traditional header, use appropriate variable names, and nicely label all values printed to the terminal. Submission are to be done through inquire.roanoke.edu through the Assignment 1 link. Both partners must submit through inquire!