Skip to main content
GameDev.net gamedev.net
🔒 Locked

Any web based simple c# exercises?

Started by simesf Aug 1, 2007 at 9:49 AM 11 replies 8.6k views
Original Post
simesf
simesf
Following this workshop I'm keen to try tinkering with the language. Are there any websites that have plenty of simple exercises for beginners? The kind of thing you get at the end of 'Learn C# in 23 Minutes' book chapters.
Spoonbender
Spoonbender
Don't know of any, but if you name a subject, I'm sure we'd be able to come up with some :)
DarkTimes
DarkTimes
As someone above posted, if you want an example of something specific we can easily write something to help you.
TheTroll
TheTroll
Just let us know what you want to work on and we can write something up.

theTroll
simesf
simesf
ok; these are some of the kinds of exercises I've done in the past:

1. Write a simple program that takes 5 integers and determines the highest and the lowest. You should use a class/method/structure called NumberSort in the program

2. Write a program that accepts a 5 number integer and prints the numbers of that integer with a space between each number (hint: use the modulus operator)

3. Write a program which simulates a chess tour; i.e. take a knight on a chess board, start them at a random square and see how many moves the knight can make before it runs out of squares it hasn't already occupied. A more advanced challenge is to assign the squares towards the corners with a lower probability of being selected than the centre squares. Use (whatever C# topic that was being discussed in that section) in your answer.

4. Create a base object to represent a living being in a simple game and derive 3 subclasses from it; human, dog, and Silurian 3 legged wimple chucker. Make sure they can all walk, make a sound and die(ok we haven't done inheritance yet)

My apologies to Messrs. Dietel and Dietel since I'm pretty sure most of those examples came from one of their books. I found their writing style a bit difficult to follow but at the end of some chapters they would have up to 50 exercises which was really where you learned by trying out in a guided manner the things you had learned.

I suppose my ideal would be a few exercises which make you use what you have learned without getting too frustrated with the central problem (that chess tour took me a few days - very frustrating but such a good feeling when it worked!) If they had some kind of game theme to them as appropriate to a site called gamedev.net then so much the better. It's difficult as a learner to set yourself exercises given you don't know what you don't know.

edit - don't get me wrong; this workshop is great as it is, and I appreciate that some people here are already working flat out on it. Hence my original question that if anyone knew of a website that already had a repository of these 'practice what you've learned' tasks. The site could be C# or another language if the problem can be applicable to C#. Such an existing site would help practice without the generous people round here donating yet more time.
BrasiLokau
BrasiLokau
hello,
try to google for the book C# How To Program, this book is awsome and there are a HUGE list of excercises for each chapter.
I had some of the exercises in my machine, but I can't find them right now, so I will post it when I find them.
blog: www.brasilokau.com/games/blog
Melinye
Melinye
These aren't C# specific, but there are many, so at least some should be useful. I plan on digging in there myself this weekend.

http://www.spoj.pl/problems/classical/
simesf
simesf
Quote:
Original post by Melinye
These aren't C# specific, but there are many, so at least some should be useful. I plan on digging in there myself this weekend.

http://www.spoj.pl/problems/classical/


This is exactly what I was talking about. Bookmarked and many thanks!



DarkTimes
DarkTimes
Quote:
Original post by simesf
1. Write a simple program that takes 5 integers and determines the highest and the lowest. You should use a class/method/structure called NumberSort in the program


I'll start then...

Well, it doesn't fit your criteria exactly, but a program this simple doesn't need structs or methods really. Anyway, I knocked this up in a couple of minutes... Oh yeah, it can expand to take any number of ints, not just five.

public class Program{    public static void Main(string[] args)    {        int highest = 0, lowest = 0;        foreach (string arg in args)        {            int number;            if (System.Int32.TryParse(arg, out number))            {                if ((lowest == 0) || (number < lowest))                    lowest = number;                if (number > highest)                    highest = number;            }            else            {                System.Console.WriteLine("The command line argument '{0}' couldn't be parsed into an integer, so we're going to skip it.", arg);            }        }        System.Console.WriteLine("The highest number was '{0}' and the lowest number was '{1}'.", highest, lowest);    }}


Anyway, very simple. You would run the program and pass the ints through the command line arguments.

Alternatively you could put the args into an int[] array and then use the static method Array.Sort() to determin the order.

[Edited by - DarkTimes on August 2, 2007 10:37:52 AM]
Cerasti
Cerasti
If you're still looking, you should try http://www.javabat.com. Not really C# exercises, but you don't need to know a lot of Java knowledge to complete the problems.
SamLowry
SamLowry
Quote:
Original post by DarkTimes
Quote:
Original post by simesf
1. Write a simple program that takes 5 integers and determines the highest and the lowest. You should use a class/method/structure called NumberSort in the program


I'll start then...

Well, it doesn't fit your criteria exactly, but a program this simple doesn't need structs or methods really. Anyway, I knocked this up in a couple of minutes... Oh yeah, it can expand to take any number of ints, not just five.

*** Source Snippet Removed ***

Anyway, very simple. You would run the program and pass the ints through the command line arguments.

Alternatively you could put the args into an int[] array and then use the static method Array.Sort() to determin the order.


Now try to make it work for negative numbers also. Don't use any extra variables than you already have.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.