CISC105 Summer 2007 Lab07

Notes before you begin:

Programs

  1. Write a program that uses a 10x10 two-dimensional array of integers to store the multiplication tables. Each element of the 2d-array should be equal to the product of its indices. For example:
    Index01234
    000000
    101234
    202468
    3036912
    40481216
    And so on. Fill this array using nested for loops. Then, once it is full, use another set of nested for loops to print the table to the screen. Make sure it is nicely formatted and easy to read. You do not need to include the row/column headers (in bold here). Also, you may leave out the "0" row and column if you wish, though it is not required.
  2. This problem uses tictactoe.c, found in the labs/lab07 directory on the website. Save this file to your home directory, and then make a copy of it as your lab07.2.c. Get familiar with the program; it is very similar to what we worked on in class. Note: the system("clear"); call has been removed because it adds strange characters to the script. Do not add it back, at least not in the final version.
    Add a function to this program that tests whether the board is full. The function should return an integer, 1 if the board is full and 0 otherwise. Change the loop in main such that it calls this new function and quits if the board is full. You may remove the tests for -1 in the loop--we will assume that the game continues until the board is full. This means that you may also want to rearrange things in the loop somewhat (moving the printf/scanf to the beginning of the loop, perhaps).
  3. Make a copy of your lab07.2.c for this problem. Add another function to your tic-tac-toe program, which tests whether there is a winner. This function should return a character: 'X' if X is the winner, 'O' if O is the winner, or '-' if there is no winner on the board. Once again, change your loop in main. It should now immediately end if there is a winner. Lastly, in main, the program should print a message declaring who has won: X, O or the Cat.
  4. The following problems deal with structs. Write a program that creates a new data type using structs, called Student. This data type should consist of:
    integer id
    double gpa
    20 character array, firstName
    20 character array, lastName
    In main, create a variable of type Student. Next, fill the variable with values of your choosing. Remember that you need to use string functions to give values to the character arrays inside of student. You don't need to get user input here, just hard-code the statements into main.

    This program should compile, but not print anything if it is run.
  5. Make a copy of lab07.4.c for this problem. Add to it a void function that takes a single Student as a parameter, and nicely prints the values inside it. Call this function from main, passing in the Student you created for the previous problem.
  6. Once again, make a copy of lab07.5.c for this problem. Add another function, this one called getNewStudent(). The function should have no parameters, and should have a return type of Student. It should declare a new student variable inside the function, and then fill it with values from user input. Once the new Student is filled, return the variable.

    In main, call getNewStudent and assign the returned value to the student variable you created in lab07.4.c. This should assign the user-specified values to this variable. Test this by printing the contents of the variable with your student-printing function from the last problem.

Submission

You should have a total of 6 programs, named lab07.1.c to lab07.6.c. Make a single script file (named lab07.txt) where you cat, compile, and run each program in sequence. That is, you should cat, compile and run lab07.1.c, then do the same with lab07.2.c, etc.

Submit all program and script files on MyCourses before 11:55 Sunday night. Give the paper version of your script to your TA next Monday at the beginning of lab. Write your name and the lab number on the front of your paper submission. Also, if something doesn't work properly, please circle it in bright ink and make a note for your TA explaining the problem. You will lose less points for a problem you recognize and can explain (at least a little) than for one you don't seem to notice.