Get Timers Now!
X
 
Nov 06 - 11:12:49
-1
Page:  1 
C# is a bastard (any coders to help?) Started by: Drexler on Mar 08, '11 16:41

Basically the simplest of C# jargon has gone right over my head, admittedly I am high far to often to learn but I do try :/

I've a couple of tasks I need to do but the Uni are a bunch of wankers and just expect little ol'me to learn by myself and do not actually teach us they just give the tasks, so for someone who has zero skills with C# its a bitch to learn new things so fast :(

I mean half the tasks they give us are mere copy/paste questions of Java, and I know they're similar but geesh my head is going to explode,

I offer Interwebz and mafie pennies to helpers! find me on mIRC or here :/

Report Post Tip

 


Question 1
Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7, according to the following requirements:
1.The expressions are to be typed in by the user.
2.The input always consists of a number, followed by an operator, followed by another number.
3.The operators that are allowed are +, -, *, and /.
4.The solution must be implemented creating a class called Calculator.
5.The calculation should be performed by an instance method belonging to the class Calculator. This method should be called Calculate.
6.After performing a calculation, the method should prompt to the user a message asking if she wants to perform another calculation. If the answer is “YES”, then another calculation should be performed. If the answer is “NO”, then the application should be terminated. The system should reply to another answer indicating that the answer provided is not valid, and asking again if the user wants to perform another calculation.
7.The application Main method should create an instance of the class Calculator, and then trigger the calculation process appropriately.
What happens if the user does not input the expect types of values? How can you check the validity of the input?
3.2.2INSTRUCTIONS
A possible algorithm for the solution of this problem could be:
1.Read the first number.
2.Read an operator.
3.Read the second number.
4.Check the operator, selecting the most appropriate conditional statement, in your opinion.
5.If the operator is '+', then calculate the summation of both number. 
6.If the operator is '-', then calculate the subtraction of both number. 
7.If the operator is '*', then calculate the multiplication of both number. 
8.If the operator is '/', then calculate the division of both number. 
9.Print out the result of calculation.
10.Ask the user if she wants to perform a new calculation.
11.Depending on the answer, ask again, start a new calculation or terminate the application “politely”.

Question 1
Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7, according to the following requirements:1.The expressions are to be typed in by the user.


2.The input always consists of a number, followed by an operator, followed by another number.


3.The operators that are allowed are +, -, *, and /.


4.The solution must be implemented creating a class called Calculator.


5.The calculation should be performed by an instance method belonging to the class Calculator. This method should be called Calculate.


6.After performing a calculation, the method should prompt to the user a message asking if she wants to perform another calculation. If the answer is “YES”, then another calculation should be performed. If the answer is “NO”, then the application should be terminated. The system should reply to another answer indicating that the answer provided is not valid, and asking again if the user wants to perform another calculation.


7.The application Main method should create an instance of the class Calculator, and then trigger the calculation process appropriately.What happens if the user does not input the expect types of values? How can you check the validity of the input?



INSTRUCTIONS


A possible algorithm for the solution of this problem could be:


1.Read the first number.


2.Read an operator.


3.Read the second number.


4.Check the operator, selecting the most appropriate conditional statement, in your opinion.


5.If the operator is '+', then calculate the summation of both number. 


6.If the operator is '-', then calculate the subtraction of both number. 


7.If the operator is '*', then calculate the multiplication of both number. 


8.If the operator is '/', then calculate the division of both number. 


9.Print out the result of calculation.


10.Ask the user if she wants to perform a new calculation.


11.Depending on the answer, ask again, start a new calculation or terminate the application “politely”.


 

Report Post Tip

Fucking fuck! why does this gay site paste shit twice :/

Report Post Tip

Question 2

Many board games require the generation of bi-dimensional boards, often filled with values generated based on game rules. In this task you are required to write a class that generates a square board composed of cells (i.e. it is organised like a matrix) The board must be created based on dimensions provided by the user, must be filled with numbers generated based on the rules specified in the task requirements. Hence, you should write a GameBoard class, based on the following:

1. The creation of the board must be performed by an instance method called CreateBoard.
2. CreateBoard should allow the user to input a number N, defining the size of the board (N rows by N columns).
3. N should be integer, and smaller than 20. Otherwise, the method should ask the user to re-enter the size of the board.
4. The method should then create a board represented as a bi-dimensional array of integers.
5. The board should be filled with integer numbers, based on a rule that you must deduce from the following board examples.
6. Once the board has been generated, CreateBoard must print it on the console.
7. After completing the drawing, CreateBoard should prompt to the user a message asking if she wants to generate another board. If the answer is "YES", then the user should be allowed to input another number, and a new board generation process should begin. If the answer is "NO", then the application should be terminated. The system should reply to any other answer indicating that the answer provided is not valid, and asking again if the user wants to generate another board.
8. The application Main method should create an instance of the class GameBoard, and then trigger the board generation process appropriately.

INSTRUCTIONS

C# supports multi-dimensional arrays. The dimensions are comma separated within the square brackets. For example, the following code creates a 3x4 array of int.

int[,] a = new int[3,4];

Element access is performed using a single set of square brackets with the indices for each dimension comma separated. For example:

a[0,0] = 17; // write a value into row 0, element 0
a[0,1] = 32; // write a value into row 0, element 1
int x = a[0,1]; // read row 0, element 1

The GetLength method is used to obtain the number of elements in a particular dimension. Note that Length gives the total number of elements in the array. The following code illustrates this.

int[,] a = new int[3,4];
int l1 = a.Length; // yields 12 the total number of elements in all dimensions
int l2 = a.GetLength(0); // yields 3, the number of rows
int l3 = a.GetLength(1); // yields 4, the number of elements in each row

Report Post Tip

Question 3


This task requires you to create a simple robot. The robot will have a name, a location in a bi-dimensional world, will record the compass direction it is facing and will be able to perform some basic actions. The robot should be created according to the procedure specified in the instructions.


Instructions:

1. Create a class called Robot to represent a robot.

2. Add four instance variables to store the state of the robot: a string for the name (instance variable name); an integer to store the x coordinate of the robot's location (instance variable x); an integer to store the y coordinate of the robot's position (instance variable y); an integer for the direction the robot is facing (instance variable direction). All the instance variables should be private since we only want code in the Robot class to access them. In order to access them, other objects will be forced to go through the public methods that you will add later.

3. Next you need to model the compass directions North, East, South, and West. There are many ways this can be done in C#. You can choose the simplest option and define a public integer instance variable for each direction. These values can be assigned to the direction instance variable to indicate the direction the robot is facing. It is possible to make this a bit more realistic by introducing the C# keyword const to mark the directions as constants. Adding const makes your code more logically correct since you are creating symbolic constants.

public const int North = 0;
public const int East = 1;
public const int South = 2;
public const int West = 3;

4. Add an Initialize method to the robot. The method should take for arguments, one for the name, one for each of the x and y coordinates, and one for the direction. In the body of the method, set each instance variable to the corresponding value passed as a parameter.

public void Initialize(string name, int x, int y, int direction)
{
...
}

5. Add a Print method to the robot. The method should print the current state of the robot (name, x, y, and direction) to the console.

public void Print()
{
...
}

When printing the direction, a function such as the following might be convenient to map from the internal integer representation to a human readable string. Note that the position in the array of each string corresponds to the value for the constants, so the string "North" is in the first position since the value of the constant North is 0. The method is private since it is for the exclusive use of the Robot class.

private string ToString(int direction)
{
string[] names = { "North", "East", "South", "West" };

return names[direction];
}

6. Create a class called World containing a Main method. Inside Main, create a Robot and call the Initialize and Print methods to test your work.

7. You now need to add some more interesting behaviour to the Robot class, beginning with a method called Move. The Move method will move the robot forward one unit in the direction it is currently facing. For example, if the robot is currently at position (0,0) and is facing north, calling Move will move the robot one unit in the positive y direction (i.e. North) so the robot will then be at position (0,1). Implement the following public Move method for the Robot class. Call Move from Main to test your work.

public void Move()
{
...
}

8. Next you need to add the ability for the robot to turn either left or right. Turning the robot modifies the direction the robot is facing. For example, if the robot is currently facing north and turns left, the robot would then be facing west.
Add two symbolic constants to represent Left and Right.

public const int Left = 4;
public const int Right = 5;

Modify the ToString method so it works with the new constants.

private string ToString(int direction)
{
string[] names = { "North", "East", "South", "West", "Left", "Right" };

return names[direction];
}

Implement the following public Turn method. The parameter to is used to indicate whether the turn is to the Left or to the Right. Call Turn from Main to test your work.

public void Turn(int to)
{
...
}

9. You must now now add a random number generator to the Robot. The .NET Framework class library provides a class named System.Random that will do the work for you.
Add the following field to the robot simulation. Notice how the generator uses the current time as the seed to ensure a different sequence of random numbers each time the program is run.

private Random random = new Random((int)DateTime.Now.Ticks);

Add a method called Step to the Robot class which makes use of the random number generator. The generator offers a method named Next which takes an int parameter (called the bound) and returns a random number between 0 and bound-1. The Step method should choose randomly between moving and turning. A reasonable probability distribution might be a 50% chance for Move(), a 25% chance for Turn(Left), and a 25% chance for Turn(Right). Notice that calling Next(2) on the random number generator has an even probability of returning 0 or 1 thus providing a convenient way to create a 50/50 chance. Call Step from Main to test your work.

public void Step()
{
...
}
10. Now you have to give to the robot the ability to search for a goal position. The goal is simply an (x,y) coordinate pair. To keep the simulation from running indefinitely you will define a "world size" and restrict the robot's movement to coordinates in the valid range. Add the following constant to the Robot class.

public const int Size = 10;

Modify the Move method to keep the coordinates in the range 0 through Size-1. The following code accomplishes this very concisely.

public void Move()
{
...
//
// force coordinates back into valid range
//
x = (x + Size) % Size;
y = (y + Size) % Size;
}

Add a method called At to the Robot class. The method should determine whether the robot is at the given coordinates. This method will be useful to test whether the robot has reached the goal.

public bool At(int x, int y)
{
...
}

Hardcode an (x,y) coordinate pair in the Main method to serve as the goal.

int goalx = 5;
int goaly = 5;

Repeatedly call Step on the robot until it reaches the goal. Use the At method to determine if the robot is at the goal. You may also want to create several robots and have them compete to find the goal.

Report Post Tip

public class Teach
{
    public static void Main()
    {
        try
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            process.StartInfo.FileName = "C:\Teach\Drexler";
            process.EnableRaisingEvents = true;
            process.Exited += new EventHandler(Drexler_Fail);
            process.Start();
        }
        catch (Exception GoneAndDoneBlownUp)
        {
            System.Console.WriteLine("You suck.");
        }
    }
    
    private void Drexler_Fail(object sender, System.EventArgs e)
    {
        System.Console.Writeline("You suck.");
    }
}

Report Post Tip

Le sigh!

Report Post Tip

rofl.

Report Post Tip

:(

You get ZERO interwebz

Report Post Tip

Managed to do Task one after a day of failing.

Report Post Tip

10 Print "Falure"

20 Goto 10

Run

 

Hope this helps

Report Post Tip

This Forum Is For Topics Other Than The Game (AKA Outside)
Replying to: C# is a bastard (any coders to help?)
Compose Body:

@Mention Notifications: On More info
How much do you want to tip for this post?

Minimum $20,000

(NaN)
G2
G1
L
H
D
C
Private Conversations
0 PLAYERS IN CHANNEL