You are on page 1of 2

Introduction to C# Programming CEIL-864

Lab Assignment #4 – C# Methods

Student: ______________________

Due Date: 14 Oct 2017 Saturday Midnight

Marks/Weightage: 10/5%

Purpose: The purpose of this Lab assignment is to:


 Practice the use of C# methods

References:
 Textbook, Chapter 7.
 Lecture Notes #4

This assignment may be completed individually by all the students. Submit the solution in a zip file
through assignment link.

This assignment may be completed individually by all the students. Submit the solution in a zip file
using assignment link on Blackboard. The zip file should be named according to the following rule:
You must name your Visual Studio IDE project according to the following rule:
firstname-lastname_Labnumber.
Example: John-Smith_Lab1

If there are two or more exercises, add to the file name: _Ex1 or _Ex2... or Exn
Example: John-Smith_Lab1-Ex1

Submit your assignment in a zip file that is named according to the following rule:
firstname-lastname_Labnumber.zip
Example: John-Smith_Lab1.zip

Apply the naming conventions for variables, methods, classes, and namespaces:
- variable/instance data members names start with a lowercase character ( except the first letter of
every word e.g. firstName )
- classes start with an uppercase character ( first letter of every word, e.g. BankAccount )
- namespace use only lowercase characters ( first letter of every word e.g. mynamespace )
- methods start with a uppercase character ( first letter of every word e.g. CalculateSum() )
- Constants - all letters in uppercase ( e.g. RATE)

Note (Very Important): Late submission past due date are allowed but there would be 10%
deduction for very late day. And after one week, no submission for lab assignments will be accepted.

Lab Assignment #4 Page 1 of 2


Introduction to C# Programming CEIL-864

Exercise #1 (A):

Write a C# console application that implements the following tasks:


- Ask the user to enter an integer number
- Pass this number to a static method using pass-by-value and display the results.
- Pass this number to a static method using pass-by-reference and display the results
- Use a static method that declares an out parameter and display the results.
- Use a static method that declares a parameter array and displays its elements
[2 marks]

Exercise #1 (B):

Write a C# console application, that makes use of two overloaded methods – Compare( a, b) and
Compare( a, b, c) which compares two and three integers respectively and return the one which is
largest in both the cases. [3 marks ]

Exercise #2:

Write a program that plays the game of “guess number” as follows: Your program chooses a number
to be guessed by selecting an integer at random in the range 1 to 1000. Then, it displays the following
message:
I have a number between 1 and 1000.
Please enter your first guess:

The player enters the guess. The program should respond with one of the following:
Excellent!
Would you like to play again (y/n)?

Too low. Try again.

Too high. Try again

If the player’s guess is incorrect, your program should loop until the player finally gets the number
right. The program should keep telling the player “Too high” or “Too low” to help the player to find the
correct answer.

The program should also count the number of guesses the player makes. If the number is fewer
than 10, display the message “I think you know the secret!”. If player makes more than 10 guesses
display the message: “You can do better!”

Your solution should use programmer - defined methods defined in a separate class.

Display the generated number to make it easy to test the solution.


[5 marks ]

Lab Assignment #4 Page 2 of 2

You might also like