C# PROGRAMMING
Practical Assessment — Methods
Void & Value-Returning Methods | MS Visual Studio
__________________________________
Student Name: ______ Total Marks: ____ / 60
__________________________________ ______________
Student No: ______ Date: ______
INSTRUCTIONS
• 1. Open Microsoft Visual Studio and create a new Console Application (.NET) project for each
question.
• 2. Name each project exactly as specified in the question (e.g., Question1, Question2 …).
• 3. All methods must be written inside the Program class (or a helper class where specified).
• 4. Use only void or value-returning methods — no ref or out parameters.
• 5. Call every method from Main() and display the required output to the console.
• 6. Marks are awarded for correct method signature, logic, and expected console output.
• 7. Save your work regularly. Total time: 90 minutes.
SECTION A — GUIDED EXAMPLES (Study before answering)
Purpose: Read these two examples carefully. They demonstrate the exact patterns you will use in
Sections B and C. You do NOT write code here — just study them.
Example 1 — Void Method (no return value)
A void method performs an action but does not return a value. The keyword void is used as the return
type.
using System;
class Program
{
// Void method — prints a greeting
static void PrintGreeting(string name)
{
[Link]("Hello, " + name + "! Welcome to C#.");
}
static void Main(string[] args)
{
PrintGreeting("Thabo"); // Call the method
PrintGreeting("Lerato");
}
}
/* Expected Output:
Hello, Thabo! Welcome to C#.
Hello, Lerato! Welcome to C#.
*/
Example 2 — Value-Returning Method (returns a result)
A value-returning method uses a return type (e.g. int, double, string, bool) and must include a return
statement.
using System;
class Program
{
// Value-returning method — returns the square of a number
static int Square(int number)
{
return number * number;
}
static void Main(string[] args)
{
int result = Square(5);
[Link]("5 squared = " + result);
[Link]("9 squared = " + Square(9));
}
}
/* Expected Output:
5 squared = 25
9 squared = 81
*/
SECTION B — SHORT QUESTIONS [20 marks]
Question 1 [4 marks]
Create a project named Question1. Write a void method called PrintStars that accepts an int parameter
count and prints count asterisks (*) on a single line (no spaces between them). Call the method from
Main() with the values 5 and 10.
Expected Output:
*****
**********
Answer space:
Question 2 [4 marks]
Create a project named Question2. Write a value-returning method called Add that accepts two int
parameters and returns their sum as an int. In Main() call the method with 12 and 8, and print the result in
the format shown below.
Expected Output:
12 + 8 = 20
Answer space:
Question 3 [4 marks]
Create a project named Question3. Write a value-returning method called IsEven that accepts an int and
returns true if the number is even, or false if it is odd. In Main(), test the method with 4 and 7 and print the
results as shown.
Expected Output:
4 is even: True
7 is even: False
Answer space:
Question 4 [4 marks]
Create a project named Question4. Write a void method called PrintMultiplicationTable that accepts an
int parameter n and prints the multiplication table for n from 1 to 5. Call it with 3.
Expected Output:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
Answer space:
Question 5 [4 marks]
Create a project named Question5. Write a value-returning method called GetFullName that accepts two
string parameters (firstName and lastName) and returns the combined full name with a space between
them. Call it from Main() and print the result.
Expected Output (using 'Naledi' and 'Dlamini'):
Full Name: Naledi Dlamini
Answer space:
SECTION C — PROGRAMMING PROBLEMS [40 marks]
Question 6 — Temperature Converter [10 marks]
Create a project named Question6. Write a program that converts temperatures using the following two
methods:
Method Return Type Parameters Description
CelsiusToFahrenheit double double celsius Returns (celsius × 9/5) + 32
PrintTemperatures void double celsius Calls CelsiusToFahrenheit and prints
both values formatted to 1 decimal place
In Main(), call PrintTemperatures with the values 0, 100, and 37.
Expected Output:
0.0°C = 32.0°F
100.0°C = 212.0°F
37.0°C = 98.6°F
Marks breakdown: CelsiusToFahrenheit method (3) | PrintTemperatures method (3) | Correct output format (2) |
Main() calls (2)
Answer space:
Question 7 — Number Analysis [12 marks]
Create a project named Question7. Write the following three methods:
Method Return Type Parameters Behaviour
GetMax int int a, int b, int c Returns the largest of the three integers
GetAverage double int a, int b, int c Returns the average of the three integers as
a double
PrintAnalysis void int a, int b, int c Calls GetMax and GetAverage and prints
results as shown
Call PrintAnalysis(10, 25, 17) from Main().
Expected Output:
Numbers: 10, 25, 17
Maximum: 25
Average: 17.33
Marks breakdown: GetMax (3) | GetAverage (3) | PrintAnalysis (3) | Output format & Main() (3)
Answer space:
Question 8 — Password Validator [10 marks]
Create a project named Question8. Write the following two methods to validate a password:
Method Return Rule
IsLongEnough bool Returns true if the password has 8 or more characters
ValidatePassword void Accepts a string password, calls IsLongEnough, and prints "Valid
password" or "Too short — must be at least 8 characters"
In Main(), call ValidatePassword with "abc" and "SecurePass1".
Expected Output:
Too short — must be at least 8 characters
Valid password
Marks breakdown: IsLongEnough (3) | ValidatePassword (4) | Correct output (2) | Main() (1)
Answer space:
Question 9 — Invoice Calculator (BONUS) [8 marks]
Bonus Question: Complete this question for extra practice. Marks here count towards your total.
Create a project named Question9. Build an invoice calculator with the following three methods:
Method Return Parameters Behaviour
CalculateVAT double double amount Returns 15% of amount (South African VAT rate)
CalculateTotal double double amount Returns amount + VAT (calls CalculateVAT)
PrintInvoice void string item, double Prints formatted invoice calling both methods
price above
Call PrintInvoice("Laptop", 12999.00) from Main().
Expected Output:
=== INVOICE ===
Item : Laptop
Price : R12999.00
VAT : R1949.85
Total : R14948.85
===============
Answer space:
MARK SUMMARY
Section Questions Marks Available Marks Obtained
A Examples (study only) 0
B Q1 – Q5 20 / 20
C Q6 – Q9 40 / 40
TOTAL 60 / 60
Good luck! Remember: write your methods first, then call them from Main().