Faculty of Computer Studies
Course Code: M107
Course Title: Introduction to C# Programming
Fall 2017Faculty of Computer Studies- 2018 -Tutor Marked Assignment
Cut-Off Date: Total Marks: 80
Contents
Part I: Theoretical Questions [20 Marks]
Part II: Output and Debugging Questions [20 Marks]
Part III: Problem Solving Questions [40 Marks]
Plagiarism Warning:
As per AOU rules and regulations, all students are required to submit their own TMA work and avoid plagiarism. The AOU has implemented sophisticated techniques for plagiarism detection. You must provide all references in case you use and quote another person's work in your TMA. You will be penalized for any act of plagiarism as per the AOU's rules and regulations.
Declaration of No Plagiarism by Student (to be signed and submitted by student with TMA work):
I hereby declare that this submitted TMA work is a result of my own efforts and I have not plagiarized any other person's work. I have provided all references of information that I have used and quoted in my TMA work.
Name of Student:
Signature: Date:
Part I: Theoretical Questions (4 marks each) [20 Marks]
Convert the following Algebraic expression to C# equivalent?
p= m+ n + r + s+ y
6
y= ax2 + bx + c
Briefly explain the value data types and reference data types in C#.
Differentiate between while loop and do-while loop with the help of examples.
What is an exception? How exceptions are handled in C#? Briefly explain.
How multiple inheritance is implemented in C#? Demonstrate with the help of an example.
Part II: Output and Debugging Questions (10 marks each) [20 Marks]
Note: Provide a copy of the code and screen shot for the output in the solutions’
What is the output of the following program? [10 Marks]
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int p;
int[] A = {2,5,6,1,8,4,9,1,3,0};
for (p = 0; p < 10; ++p)
{
if(A[p]%2 == 1)
Console.WriteLine(A[p]);
} Console.ReadLine();
}
}
}
What is the output of the following program? [6 Marks]
class Program
{
static void method1(ref int m, int n)
{
m = m + 10;
n = n + 20;
}
static void Main(string[] args)
{
int x = 100;
int y = 50;
method1(ref x, y);
Console.WriteLine("x =" + x);
Console.WriteLine("y =" + y);
Console.ReadLine();
}
}
Identify the errors in the following C# program. Write the correct program. [4 marks]
class Program
{
static Main(string[] args)
{
{
/ This is a comment
int m = 12
Console.WriteLine("The value of m = ",);
}
Console.ReadLine();
}
}
Part III- Problem Solving Questions [40 Marks]
Note: Provide a copy of the code and screen shot for the output in the solutions’
Write a C# program to print the factorial of a number input by the user. Hint: Factorial of number is the product of all positive integers less than or equal to that number. e.g. 5!= 5 X 4 X 3 X 2 X 1=120 [15 marks]
Sample I/O
Write a C# application that asks the user to input the required data to implement the four methods below:
(Use Method Overloading to write the methods)
Method Vol that takes as input, double values ‘r’ (radius) and ‘h’ (height), calculates the volume of a cone, and displays it. [Volume = 1/3 πr^2 h]
Method Vol that takes as input, double values ‘B’ (base area) and ‘h’ (height), calculates the volume of a pyramid, and displays it. [Volume = 1/3 Bh]
Method Vol that takes as input, a double value ‘r’ (radius), calculates the volume of a sphere, and displays it. [Volume = 4/3 πr^3]
[15 Marks]
Sample I/O
Using loops, write a C# program to print the following pattern. [10 Marks]