Final Exam

Welcome to our final exam for the CSE 251 Lecture Introduction to programming C

Like the last exam you will get a file to download, which contains several functions. Please find the prototypes on the top, and the implementations after main. Next to the prototypes you will find the number of points a correct implementation gives you. Keep in mind that every compile error will give you -1 point, which means that I strongly suggest that you actually compile and run your code!

The code has the main function already done, and I also added a couple of functions myself to help me test your code and to provide you with a context. You will find that some of the calls to these functions do not happen, because they are commented. Please uncomment these functions if you want to test your code by yourself.

Because I want this game to be 4×4 big I defined a Macro called BoardSize which is set to 4, please always assume that the board is BoardSize times BoardSize never smaller, never bigger. Your code should run even if I set BoardSize to 5, or 3, or even 9.

This exam deals with the hypothetical game of Tic-Tac-Toc, a game similar to tic-tac-toe. You play it with three players, and take turns putting down numbers into a 4×4 grid. Each player has a number (1,2, or 3) while the 4×4 field starts out to be filled with 0 in the beginning. Each player can only set his/her number into a field that is empty. The player that either fills a row, or a column, or a square of size 2×2 anywhere in the grid wins.

Examples Three wins:

Two wins:

One wins:

You don’t have to program the entire game, but you have to complete all the functions I provided. I already defined two structures you have to use. The first is called Board, and contains a single pointer two a 2d array. Entries in the array of this structure should only be 1, 2, or 3 as they indicate which cell in the grid already belongs to which player.
The second structure I defined is called Move, it has an x and y coordinate, and a variable c which indicates the player who this move belongs to. Imagine the board is:


and I have the Move x=1 y=1 c=1. This move applied to the current board will turn the board into:


There is another file called game.txt which contains a recorded game which at some point should be loaded and used.
The program you should write should have this naming convention:
CSE251_final_AH.c – where AH are my initials and they are to be replaced with your initials of cause.

I will call the program using game.txt as the first and only command line parameter, like so:
CSE251_final_AH game.txt

Good luck, enjoy, Arend

Here are the files:

and if you want to test your lode function independently here is a winning board file:

Posted in Uncategorized | Leave a comment

lecture 13

This lecture was introducing .h files and how you can make your own include files. Other than that we talked about exam preparations. Remember the exam is Monday 3pm-4pm
The code I used in the lecture:


extra files:

And the PDF of the last lecture:
You can also give feedback here:

Cheers Arend

Posted in Uncategorized | Leave a comment

lecture 12

The last “real” lecture. We covered everything necessary, and the remaining lectures will cover more detailed problems and in depth knowledge to help you understand C better, and make you even better programmers. You can also ask for specific topic to cover if you want?

Otherwise here are the various files we needed or made in this lecture:

And the lecture itself:

And here is a link that explains linked lists again:
Linked List in C Tutorial

Cheers Arend

Posted in Uncategorized | 5 Comments

lecture 11

This lecture was about two main concepts: files and strings. And btw, all of that in the context of pointers.
As you have seen an array of char is synonymous with a point to char that got the same size memory allocated to it. Find todays lecture
herelecture11. The homework is somewhat challenging because it requires you to juggle with arrays, string, and files, as well as loops. Start early, and try hard to solve this on your own. You can also use this demo file:poem as a test.
Cheers Arend

Posted in Uncategorized | Leave a comment

Lecture 10

pointers …

well, pointers are a straight forward concept. Instead of using variables to store values, you can use pointers to access memory “directly” to again use it to store values. I am aware that at first it will feel somewhat obsolete, and you should think so. So far we also never encountered any situation in which they were necessary – but trust me they will become the bread and butter in your programmer lives.
First check out the lecture here:lecture 10. Todays homework is to make a program that uses pointers and you should make up the task to perform. While this might feel random, tis is a fairly realistic situation. Essentially everything I program, be it a game or a scientific simulation tries to fulfill a purpose that I came up with. In reality you will rarely encounter a situation where someone says: make a program that does X using Y as data and output into Z. You will be in a situation where you need to solve problem X and you have constrains and resources, and you have to figure out what your code is supposed to do. Consider this a more realistic situation.

Please read all pages I provided links for in the presentation. BTW: a link is somehow like a pointer, instead of storing the value, it “points” to a place where you can find actual content (or more pointers/links).

Cheers Arend

Posted in Uncategorized | Leave a comment

Lecture 9

A little bit from everything, and loops and arrays again.

Today we visited three very similar problems. Dealing with 2d arrays,  getting command line parameters into a 2d array, and performing other operations in a 2d array. We learned an important concept, and that is command line parameters. Instead of giving your code inputs like in a dialog, where the program asks and gets inputs, you can hand parameters over to your program by simply writing them after the program call. You just need to separate them by blanks. Unfortunately these arguments are of type char * which means we have to convert them to other types in case they represent values. Converting an argument to an int requires atoi() and an argument to a float requires atof(). Check out our examples here:lecture 9 and the code for the tictactoe.c program is here:tictactoe . Next time I will go into dynamic memory allocations and pointers, which means I assume from now on that you are familiar with arrays and how to use loops.

Cheers Arend

Posted in Uncategorized | 1 Comment


Hello everyone!

This is the description of our first exam. You will have 60 minutes to complete it. Your objective is to write a program that performs ten different functions, at best. Below you will find the ten functions you have to code. Each function has a different difficulty and gives points related to that. In total you could score up to 52 points. I do not expect that from you, so we set a 100% score to 30 points. Points you score above 3o will be added as a bonus to your homework assignments. You have to score at least 15 points to not get a F in this test. This is a closed book, no internet exam. If we see you mailing (except to submit the exam in the end), texting, calling, facebooking, browsing, or any similar thing, we will fail you!

Here are the 10 functions you have to code, with their corresponding point they give:
1) 3 Points: print the numbers 9 to 0, count the lines incrementally while doing so
1. 9
2. 8
3. 7

10. 0
2) 3 Points: print a solid box of * size 5×5, example:
3) 5 Points: make an empty box of * with size N time M
emptyBoxSize(3,4); ->
I used . to indicate blanks (space)
4) 5 Points: make a / from * of size N example:
dashLeftSize(3); ->
I used . to indicate blanks (space)
5) 5 Points: return the value of A B or C that is not the highest and not the lowest
example: printf(“%i\n”,getMiddleNumber(1,2,3)); -> 2
6) 7 Points: you get the array N of size 100 filled with numbers,
within this function N[100] exists, return the lowest number in this array
7) 7 Points: make floyds triangle with N lines:
Floyds triangle is a triangle of numbers startin by one and counting up,
each line contains one more number, example:
2 3
4 5 6
7 8 9 10
2 3
4 5 6
7 8 9 10
11 12 13 14 15
8) 7 Points: you get the array N of size 100 filled with numbers,
return the count of numbers below M
9) 9 Points: you get the array N of size 100 filled with numbers,
count how often the number X occurs in the Array N, and return that value
10) 1 Points: printf you first,middle (if existent),last name
example in my case: yourName(); -> Arend Hintze

You must download the template file here:mainplease rename it into exam_yourfullname.c and mail this file to me at the end of the exam, as you would do that with your homework. As an alternative, if mailing doesn’t work, you can submit your file by copy and pasting it as a comment to this post.

The template file is organized in such a way, that you only need to fill in the functions, the rest is already setup so that we have it easy when correcting your exam. The template file has a brief description of the ten functions, and ten templated functions. The main() function should not be altered. The main is followed by the ten functions to implement. Each function contains the question description again as a comment, and an example of what it should do.

I highly recommend that you test your code by compiling it! Save often, and make copies, so not accidentally erase already working code!

Good luck, Cheers Arend

br /

Posted in Uncategorized | Leave a comment

Lecture 7

Today was all about arrays, unfortunately we didn’t finish this lecture, but I left the last code example in there in case you are interested. Keep in mind that we have an exam next week. In the meantime here is the lecture:lecture 7

Cheers Arend

Posted in Uncategorized | 2 Comments

Homework results L5

A H 0
A N 0
A R 9
C R 4
D K 10
D M 10
D S 10
D Z 10
F L 10
G J 10
G W 10
H K 10
J G 10
J L 6
J M 6
J S 6
J W 10
K W 10
M J 10
M R 10
M S 8
N H 0
R B 10
R L 10
R S 4
S G 10
T P 10
T S 10
X Z 10
Y J 10

Cheers Arend

Posted in Uncategorized | Leave a comment

Exam Preparation

I am not exactly sure about the format of the midterm exam but I think you will get a set of programming problems you can choose from and more difficult ones give you more points than simpler ones. However, you probably would like to prepare, so I list a couple of problems you might see in the test. I marked some with *, these will become solvable after the next class. I will continue adding more examples over the next couple of days.

Cheers Arend

-count from 1 to 19
-count from 2 to 22, using intervals of 2
-count from 234 backwards to 7
-make a function that counts from S to E using an I interval print letter C in every line next to the number you are currently counting
-make a square size 5×5
-make a function that makes a NxM square, and print the size of it
-sum 100 random numbers
-convert C in F, F in C, inch in cm, cm in inch – all using functions

-make Floyds triangle
-count from 1 to N, each time you generate a random number between 0 and the count you are at, print the mean of all numbers
-print a chess board with letters and numbers as indexes next to it
-make 100 random numbers in the range from 1..N, find the lowest and highest
-count from 1 to 100, print the number, but print “tick” instead of the number every third count, print “tock” instead of the number every 5th count, the 15th count will read “ticktock” instead of the number
-make a random number between 0..100 let the computer guess it as well.
-make a function that takes three int parameters A, B, and C. If C is 0 return true if A equal to B, if C is -1 return true if A is bigger than B, if C is 1 return true if A is smaller than B, return false in all other cases
-make a function that takes three int parameters A, B, and C. Compare the values and return the value in the middle

-make Floyds triangle backwards, starting with 76 until you hit 0
-simulate a one dimensional random walk, measure the mean number of updates it takes for the random walk to get back to the origin
-make a function that returns the distance between 2 points, each point defined by an X and Y position
-make two arrays called X and Y of size 10 each. X and Y define the coordinate of a point, use this to create 10 random points, and find the point pair with the closest distance

Posted in Uncategorized | Leave a comment