Thursday, March 27, 2008

 

Visual Studio 2008 IDE C# - UK Launch Notes


 

C# Programming - Part 2 - Conditions

Scope of work

The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.

1. if, else if, else

2. Nested conditions

3. && and

4. switch statement

Training Questions

Create console applications to:

1. Read a number from the console (use ReadLine and Int32.Parse) and using if, else if and else output one of the following

“The number is negative”

“The number is lower than 100”

“The number is 100 or above”


2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:

“The numbers are the same”

“The numbers are not the same”

– the first is lower than the second”

“The numbers are not the same

– the second is lower than the first”


3. Read two numbers from the console (one after the other) and using if, else if and else along with && output one of the following:

“The numbers are the same and are negative”

“The numbers are the same and are positive”

“The numbers are not the same”


4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-10 output one of the following:

“You entered an even number” or

“You entered an odd number” or

“You entered a number that is not 1-10”

5. Read a number from the console (use ReadLine and Int32.Parse) and by nesting if, else if and else output one of the following depending on what range the number is in, and whether it is divisible by 5:

“The number is 0-25 and is divisible by 5” or

“The number is 0-25 and is not divisible by 5” or

“The number is 26-50 and is divisible by 5” or

“The number is 26-50 and is not divisible by 5” or

“The number is 51-75 and is divisible by 5” or

“The number is 51-75 and is not divisible by 5” or

“The number is above 75”


* Note. To check if a number is divisible by 5 you can use:

(number % 5 == 0)

Test Questions

Create console applications to:

1. Read two numbers from the console (one after the other) and using if, else if and else output one of the following:

“The first number is lower than the second”

“The second number is lower than the first”

“The numbers are the same”


2. Read two numbers from the console (one after the other) and by nesting if, else if and else output one of the following:

“Both numbers are negative”

”Both numbers are positive”

“The first number is positive, the second is negative”

“The second number is positive, the first is negative”


3. Read a letter from the console and by if, else if and else with (or) output one of the following:

“1” (if the letter is a, b or c)

“2” (if the letter is d, e or f)

“3” (if the letter is g, h or i)

“4” (if the letter is j, k or l)


4. Read a number from the console (use ReadLine and Int32.Parse) and using a switch statement with cascading, and depending on an input 1-9 output one of the following:

“You entered the number one, two or three” or

“You entered the number four, five or six” or

“You entered the number seven, eight or nine” or

“You entered a number that is not 1-9”


5. Read three numbers from the console (one after the other) and by nesting if, else if and else sort the three numbers and output them in order:

Example: input numbers: 2 5 and 1

Output: 1, 2, 5

Example: input numbers 100, 45, 30

Output: 30, 45, 100

Saturday, March 22, 2008

 

C# Programming - Part 1 - Strings

As languages become more high-level it seems training material focuses more on dragging and dropping components and interacting with the IDE than teaching fundamentals like problem solving and creating logical procedural code. From this deficit I created a set of C# Programming tasks that concentrate on problem solving and creating logical code. This work is made available by kind approval of Siemens AG Industry.

The tasks are provided free of charge but may NOT be copied or redistributed. The work is copyright and all rights are reserved.

Scope of work

The work is split into two parts: the first is a training part where you are encouraged to use books and the Internet to help you complete the questions; the second is a test part where you should complete the questions with no external help. The pass score is 80%.

1. Manipulating strings

2. Substrings

3. Upper/lower case

4. Concatenation

5. Locating a character in a string

6. Replacing characters in a string

Training Questions

Create console applications to:

1. Store your name as a string literal and output it to screen.

2. Read a string from the console and output it in upper case.

3. Read a name from the console (for example "Bob") and output the following:

"Hello, Bob!"

4. Use the following string:

string telephone = "0800 123 4567";

and replace the space with a - so that the output is:

0800-123-4567

5. Use the following string:

string alphabet = "abcdefghijklmnopqrstuvwxyz";

and output six letters starting from e, so that the output is:

efghij

6. Create a simple CSV (comma separated values) parser capable of dealing with a string read in from the console. The string will always be in the format:

firstvalue,secondvalue,thirdvalue

Some example strings:

"1,2,3"

"aa,bb,cc"

"apple,banana,pear"

The output (using the third string as an example) should be output to screen as follows:

First value: apple

Second value: banana

Third value: pear


Test Questions

Create console applications to:

1. Store your name in a string and output it to the screen in upper case.

2. Use the following strings:

string countryCode = “44”;

string areaCode = “1260”;

string number = “123456”

along with string literals to output:

+44-1260-123456

to screen

3. Use a string as follows:

string test = "siemens automation and drives";

Replace every i character with a 1 and then output the string in upper case as so:

S1EMENS AUTOMAT1ON AND DR1VES

4. Parse the following string:

string surnameforename = "Siemens, Werner";

so the forename appears before the surname as follows:

"Werner Siemens"

store it in a string variable and output it to screen.

5. Read in a string from the console that will always be in the following format:

+

This should be done using the substring function.

For example:

12+4

Where the example would output:

First number: 12

Second number: 4

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]