Professional Documents
Culture Documents
M109 - TMA - Summer 2022
M109 - TMA - Summer 2022
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:
3. What is method overloading in C#? Describe the two ways to do method overloading
in C# with examples.
5. Explain value data types and reference data types in C# with examples.
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’
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int i, j;
int [,] A = new int[5,5];
for (i = 0; i < 5; ++i)
{
for (j = 0; j < 4; ++j)
{
A[i,j] = i+j;
}
}
for (i = 0; i < 5; ++i)
{
for (j = 0; j < 4; ++j)
{
if (i < 5)
{
A[j, i] = A[i, j];
}
else
break;
Console.Write(A[i, j] + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
namespace ConsoleApplication1
{
struct TMA
{
public int marks;
}
class Program
{
static void Main(string[] args)
{
TMA x = new TMA();
x.marks = 75;
Check(ref x);
Console.Write(x.marks + " ");
Console.ReadLine();
}
public static void Check(ref TMA y)
{
y.marks = 70;
Console.Write(y.marks + " ");
}
}
}
3. Consider the program below. Will it generate the output "Welcome to Tutor
Marked Assignment"? If no, which statement should be added in the function
BBB() of class PQR, if it is to produce the above output? [4
Marks]
namespace ConsoleApplication1
{
class XYZ
{
public void AAA()
{
Console.Write("Welcome");
}
}
class PQR : XYZ
{
public void BBB()
{
// [*** Add statement here ***]
Note: Provide a copy of the code and screen shot for the output in the solutions’
2. Write a C# application that asks the user to input the required data to implement the three
methods below:
(Use Method Overloading to write the methods)
a. Method Area that takes as input, integer values ‘l’ (length) and ‘w’ (width),
calculates the area of a rectangle, and displays it. [Area = ]
b. Method Area that takes as input, double values ‘B’ (base) and ‘h’ (height),
calculates the area of a parallelogram, and displays it. [Area = ]
c. Method Area that takes as input, a double value ‘B’ (base) and an integer value
‘h’ (height), calculates the area of a triangle, and displays it. [Area = ]
[15 Marks]
Sample I/O
3. Write a C# application that asks the user to search for an item in the array. Input an array
of 10 elements and the search item. If the item is found in the array, display the location
of the item in the array. Otherwise, display appropriate error messages.
[15 Marks]
Sample I/O