You are on page 1of 12

Problem 1

Author.cs
using System;

namespace Author

public class Author

private string Name;

private string Email;

private char Gender;

public Author(string Name, string Email, char Gender)

this.Name = Name;

this.Email = Email;

this.Gender = Gender;

public Author()

public void DisplayAuthor()

{
if (Gender=='M' || Gender =='m')

Console.WriteLine("Author's Name: \t" + Name + "\n" + "Author's Email: \t" + Email + "\n"
+"Author's Gender: \tMale");

else if (Gender == 'F'|| Gender=='f')

Console.WriteLine("Author's Name: \t" + Name + "\n" + "Author's Email: \t" + Email + "/n" +

"Author's Gender: \tFemale");

else

Console.WriteLine("Please enter a gender");

Book.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;
namespace Author

public class Book: Author

private string BookId;

private string BookName;

public Author BookAuthor;

public void setBookName(string BookName, string BookId)

this.BookId = BookId;

this.BookName = BookName;

public void getBook()

Console.WriteLine("Book name: \t" + BookName);

Console.WriteLine("Book ID: \t" + BookId);

BookAuthor.DisplayAuthor();

Program.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace Author

class Program

static void Main(string[] args)

Console.WriteLine("Author Details Only:");

Author aAuthor = new Author("Dan Brown", "dan@live.com",'m');

aAuthor.DisplayAuthor();

Console.WriteLine("\nBook Details: ");

Book aBook = new Book();

aBook.BookAuthor = aAuthor;

aBook.setBookName("Inferno", "UI93442KJ");

aBook.getBook();

Console.ReadKey();

}
Problem 2

Programs.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace _2NumberSwapConsoleApp

class Program

static void Swap(int a, int b)

a = a + b;

b = a - b;

a = a - b;

Console.WriteLine("After swapping first number {0} and second number {1}", a,b);

static void Main(string[] args)

int num1 = Convert.ToInt32(Console.ReadLine());


int num2 = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Before swapping first number {0} and second number {1}", num1,
num2);

Swap(num1,num2);

Console.ReadKey();

Problem 3

Program.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace _2DArrayMatrixConsoleApp

class Program

static void Main(string[] args)

try
{

Console.WriteLine("enter 9 numbers: ");

int[,] ary = new int[3,3];

for (int i = 0; i < 3; i++)

for (int j = 0; j < 3; j++)

ary[i, j] = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("The Matrix: ");

for (int i = 0; i < 3; i++)

for (int j = 0; j < 3; j++)

Console.Write(ary[i, j] + "\t");

Console.WriteLine();

int firstRow = 0, secondRow = 0, thirdRow = 0, firstCol = 0, secondCol = 0, thirdCol = 0;

for (int i = 0; i < 3; i++)

{
for (int j = 0; j < 3; j++)

if (i == 0) firstRow += ary[i, j];

else if (i == 1) secondRow += ary[i, j];

else if (i == 2) thirdRow += ary[i, j];

if (j == 0) firstCol += ary[i, j];

else if (j == 1) secondCol += ary[i, j];

else if (j == 2) thirdCol += ary[i, j];

Console.WriteLine("Sum of First Row = " + firstRow);

Console.WriteLine("Sum of Second Row = " + secondRow);

Console.WriteLine("Sum of Third Row = " + thirdRow);

Console.WriteLine("Sum of First Column = " + firstCol);

Console.WriteLine("Sum of Second Column = " + secondCol);

Console.WriteLine("Sum of Third Column = " + thirdCol);

catch (Exception)

Console.WriteLine("Enter Integer Numbers");

}
Console.ReadKey();

Problem 4

Program.cs
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace PatternNumberConsoleApp

class Program

static void Main(string[] args)

int[,] numbers = new int[3, 3];

int[] cloumnSumArray = new int[3];

int i, j, rowSum = 0, columnSum = 0, k, diagonalSum = 0;


for (i = 0; i <= 2; i++)

for (j = 0; j <= 2; j++)

numbers[i, j] = Convert.ToInt32(Console.ReadLine());

for (i = 0; i <= 2; i++)

for (j = 0; j <= 2; j++)

rowSum = rowSum + numbers[i, j];

Console.Write(numbers[i, j] + " ");

Console.Write(rowSum);

Console.WriteLine();

rowSum = 0;

}
for (j = 0; j <= 2; j++)

for (i = 0; i <= 2; i++)

columnSum = columnSum + numbers[i, j];

Console.Write(columnSum + " ");

columnSum = 0;

Console.WriteLine();

for (i = 0; i <= 2; i++)

for (j = 0; j <= 2; j++)

if (i == j)

Console.Write(numbers[i, j]);

diagonalSum += numbers[i, j];

else
{

Console.Write(" ");

Console.WriteLine();

//Console.Write(diagonalSum);

Console.ReadKey();

You might also like