Make sure that students understand the basics of C# from ITFN1303 such as function calls, parameter passing, conditionals, iteration, input and output streams, the preprocessor, and the Microsoft Visual .NET C# IDE.
This program should be relatively easy for you if you know the prerequisite information from Intro to C#. If this project is difficult for you, make sure youre up to speed on the ITFN1303 topics.
Write a program in Microsoft Visual C# that prompts the user for a non-negative integer over and over, each time printing out the Roman numeral equivalent, until the user enters the value zero (0).
Some important Roman numerals you might be
interested in (see the pattern?):
1 I
2 II
3 III
4 IV
5 V
9 IX
10 X
40 XL
49 XLIX
50 L
90 XC
99 XCIX
100 C
400 CD
500 D
999 CMXCIX
1000 M
3999 MMMCMXCIX
You must do the following:
50% Write the main algorithm that loops, asking the user for an integer between 0 and 3999 until the user enters zero (0). You must do range checking, so that if the user enters an invalid number (a negative or >= 4000), an error message is printed (but the loop continues).
75% Write a function that takes in an integer (1-3999) via a by-value parameter and prints out the Roman numeral equivalent. Return 0 upon successful completion of the function.
100% Call the function you wrote for part 2 (above) from the main algorithm for each valid integer (1-3999) entered by the user.
.cs file which compiles and works as defined above.
Any file that doesnt compile or
terminates ugly will receive no credit.
To explore the concept of recursion and collections
Solve the coloring problem: given an n x n array, and quarters which can be one of 4 colors (i.e. red, green, blue or yellow), how many ways can you place the quarters in the array such that no two adjacent (neighboring) quarters are the same color?
This problem is solved by going through all possible combinations of boards; what you need is a board class that has the ability to clone itself, and has the ability to verify itself (to ensure that two colors aren't the same), along with a couple of other useful functions:
class Board
{
// attributes, constructor, etc...
// Here's the copy function
Board copyBoard ( ) {
// return a new
Board that has a copy of all the attributes of this board!
}
// Here's the verify function
bool verifyBoard (int
i, int j) {
// return
either a true or false as to whether or not the quarter at location i, j
is valid
}
// Here's a print function
void printBoard ( ) {
// have two
nested loops that print out the values of each slot
}
// Determine if the board is full
bool isFull ( ) {
// have two
nested loops that print out the values of each slot
}
}
Then, you can create a function in Board called calculate that takes in a board (and current coordinates); if the board is verified and not full, tries the next slot with all 4 different colors. If the board is full and verified, then you can increment the number of 'wins' by one, and print out that board. If the board isn't verified, the function returns.
Be careful on the verifyBoard function. It needs to check only the quarter to the left and above it. This has a special case for either i or j equaling 0.
One .cs file.
Finally understand this whole recursion/board generation thing...
For this assignment, you are asked to solve the n-queens problem, which states that, given an n x n chess board, how can you position n queens such that no queen can attack another. Queens are able to attack along the horizontal row, the vertical column, and along diagonals.
Your program should read in a number from the user to determine the board size. The output can be done in ASCII, but should show that positions the queens - satisfying the conditions above.
The algorithm itself is for all positions in a column, place a queen, then recursively call to place the next piece in the next column. At the placement of each piece, you need to verify that it is not able to attack another piece.
All needed .cs file(s).
Work with a Stack data structure and explore the idea of FILO servicing
Imagine that you're visiting a local all-you-can-eat breakfast bar; among the many items on the bar is a pan of sausages. Your task is to simulate the sausage pan. Note that when new sausages are added to the pan, they're always added to the top (the worker just dumps new sausages on top of the old sausages); also note that whenever someone takes a sausage to eat, they pick the top-most sausage. Thus we've got a stack (first-in, last-out) and the bottom-most sausage is always the oldest. For sake of simplicity, imagine that the pan only allows you to select a "top" sausage (i.e. you can't pick among many).
Your task is to implement a stack collection (or even better use the STL stack or vector class to save yourself some implementation time). Your program should allow the user to add a sausage, remove a sausage, and print the status of the stack. The stack should store the time in which the sausage was added, and when a sausage is removed, the program should display how long the sausage "lived" in the pan (i.e. the difference from now to when it was added to the pan).
Important items to consider:
My sample solution (C++).
All needed .cs file(s).
Work with dynamic data structures like trees and linked-lists.
Create a "binary search tree" class that contains the following member functions:
Insert (takes in a new item and adds it)
Search (takes in an item and returns a pointer/reference to a node which contains the item, or NULL if the item doesn't exist in the tree)
Traverse (performs an in-order - L C R - , depth-first print/display of all items)
Breadth-Traverse (performs a breadth-first print/display of all items)
Add your class(es) into the provided "menu system" to demonstrate that it functions properly.
HINTS
Use a deque (or similar) class to help implement the Breadth-Traverse method
You might want to code separate "node" and "tree" classes
Make your BST class a template class (assume the item type implements the <<, <, >, <=, >=, == operators)
All needed .cs file(s).
Explore multithreaded and networked based programming.
Write a program in C# (or Java for the Java students) that asks a user for an IP (or machine name) and "port scans" the specified machine. Rather than waiting quite a while for each port to be scanned before scanning the next port, your program must generate a new thread for each port; the thread's responsibility is to then scan a port and print out a message if the port is open. Your program should scan the first 2048 ports on the machine, and each port is to be scanned by a unique thread. Your main program does not need to block (i.e. "join") on the threads.
NOTE - we STRONGLY recommend you only test your program on your local machine (using "localhost" as the machine name) since it's considered bad practice to port scan other machines.
Here is my sample running program (requires the .NET framework).
HINT - remember to "close" the connection/socket once you've tried it.
HINT 2 - remember that it is possible to run out of threads, so catch the "OutOfMemoryException" and try to create the thread again after "Sleep(0)".
All project files - ZIPPED.
Explore the arraylist and C# programming.
Write a class that simulates a deck of cards.
Write a class called Card that has the following attributes and methods
Write a class called Deck that has the following attributes and methods
Create a simple GUI that demonstrates the correct working of your classes above. Your GUI must:
Note – you may use any collection class or algorithm as you see fit.
Things to consider
All project files - ZIPPED.
To explore C# programming and visual controls
Create a visual interface and implement the program to play Blackjack in C#. Details below:
Things to consider:
You will demo your finished project in class on 12/4.