Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
1K views5 pages

Assignment 02

This document provides instructions for an assignment on problem solving using C# in Visual Studio. It includes 14 problems related to topics like checking if a string is a palindrome, summing values in a 2D matrix while avoiding certain elements, determining if two arrays can be made equal by swapping one pair of elements, finding the minimum jump length to avoid obstacles in an array, shifting characters in a string by one in the alphabet, inheritance between shape/triangle and shape/rectangle classes, inheritance between mother/daughter classes, polymorphism through method overloading, and polymorphism through method overriding. Students are instructed to submit their work by the due date for grading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views5 pages

Assignment 02

This document provides instructions for an assignment on problem solving using C# in Visual Studio. It includes 14 problems related to topics like checking if a string is a palindrome, summing values in a 2D matrix while avoiding certain elements, determining if two arrays can be made equal by swapping one pair of elements, finding the minimum jump length to avoid obstacles in an array, shifting characters in a string by one in the alphabet, inheritance between shape/triangle and shape/rectangle classes, inheritance between mother/daughter classes, polymorphism through method overloading, and polymorphism through method overriding. Students are instructed to submit their work by the due date for grading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Microsoft ASP .

NET TRAINING PROGRAM UMT


Assignment-II
Due Date: 23-07-2019 Section: A Total Marks: 25

Instructions
1. Understanding of the problems is part of the assignments. So no query please.
2. You will get Zero marks if found any type of cheating.
3. 25 % deduction of over marks on the one day late submission after due date .
4. The best things about the assignment is you are allowed internet surfing. Try to explore
maximum knowledge.
GOOD LUCK :)

Questions: PROBLEM SOLVING BY USING C# In VISUAL STUDIO

Problem 1

Given the string, check if it is a palindrome. Example


 For inputString = "aabaa", the output should be
checkPalindrome(inputString) = true ;

 For inputString = "abac", the output should be


checkPalindrome(inputString) = false ;

 For inputString = "a", the output should be


checkPalindrome(inputString) = true

Problem 2

After becoming famous, the CodeBots decided to move into a new building together. Each of the
rooms has a different cost, and some of them are free, but there's a rumour that all the free
rooms are haunted! Since the CodeBots are quite superstitious, they refuse to stay in any of the
free rooms, or any of the rooms below any of the free rooms.

Given matrix, a rectangular matrix of integers, where each value represents the cost of the room,
your task is to return the total sum of all rooms that are suitable for the CodeBots (ie: add up all
the values that don't appear below a 0).
Example

 For

 matrix = [[0, 1, 1, 2],


 [0, 5, 0, 0],
 [2, 0, 3, 3]]
the output should be
matrixElementsSum(matrix) = 9 .

There are several haunted rooms, so we'll disregard them as well as any rooms beneath
them. Thus, the answer is 1 + 5 + 1 + 2 = 9.

 For

 matrix = [[1, 1, 1, 0],


 [0, 5, 0, 1],
 [2, 1, 3, 10]]
the output should be
matrixElementsSum(matrix) = 9 .

Note that the free room in the final column makes the full column unsuitable for bots (not
just the room directly beneath it). Thus, the answer is 1 + 1 + 1 + 5 + 1 = 9.
Problem 3
Two arrays are called similar if one can be obtained from another by swapping at most one pair of
elements in one of the arrays.

Given two arrays a and b, check whether they are similar.


Example
 For a = [1, 2, 3] and b = [1, 2, 3], the output should be
areSimilar(a, b) = true .

The arrays are equal, no need to swap any elements.

 For a = [1, 2, 3] and b = [2, 1, 3], the output should be


areSimilar(a, b) = true .
We can obtain b from a by swapping 2 and 1 in b.
 For a = [1, 2, 2] and b = [2, 1, 1], the output should be
areSimilar(a, b) = false .
Any swap of any two elements either in a or in b won't make a and bequal.
Problem 4

You are given an array of integers representing coordinates of obstacles situated on a straight
line.

Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to
make jumps of the same length represented by some integer.
Find the minimal length of the jump enough to avoid all the obstacles.

Example
For inputArray = [5, 3, 6, 7, 9] , the output should be
avoidObstacles(inputArray) = 4 .
Check out the image below for better understanding:

Problem 5

Given a string, your task is to replace each of its characters by the next one in the English
alphabet; i.e. replace a with b, replace b with c, etc (z would be replaced by a).
Example
For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz" .

Inheritance
Problem 6
Write a program that defines a shape class with a constructor that gives value to width and height. The
define two sub-classes triangle and rectangle, that calculate the area of the shape area (). In the main,
define two variables a triangle and a rectangle and then call the area() function in this two varibles.

Problem 7
Write a program with a mother class and an inherited daugther class.Both of them should have a
method void display ()that prints a message (different for mother and daugther).In the main define a
daughter and call the display() method on it.

Problem 8
Write a probram with a mother class animal. Inside it define a name and an age variables, and
set_value() function.Then create two bases variables Zebra and Dolphin which write a message telling
the age, the name and giving some extra information (e.g. place of origin).

Static Polymorphism (overloading)


Problem 9
Create a class to print an integer and a character with two methods having the same name but different
sequence of the integer and the character parameters.

For example, if the parameters of the first method are of the form (int n, char c), then that of the second
method will be of the form (char c, int n).

Problem 10
Create a class to print the area of a square and a rectangle. The class has two methods with the same
name but different number of parameters. The method for printing area of rectangle has two
parameters which are length and breadth respetively while the other method for printing area of square
has one parameter which is side of square.

Problem 11
Create a class 'Student' with three data members which are name, age and address. The constructor of
the class assigns default values name as "unknown", age as '0' and address as "not available". It has two
members with the same name 'setInfo'. First method has two parameters for name and age and assigns
the same whereas the second method takes has three parameters which are assigned to name, age and
address respectively. Print the name, age and address of 10 students.

Hint - Use array of objects


Dynamic Polymorphism(over-riding)
Problem 12

Create a class 'Degree' having a method 'getDegree' that prints "I got
a degree". It has two subclasses namely 'Undergraduate' and
'Postgraduate' each having a method with the same name that prints "I
am an Undergraduate" and "I am a Postgraduate" respectively. Call the
method by creating an object of each of the three classes.
Problem 13

A boy has his money deposited $1000, $1500 and $2000 in banks-
Bank A, Bank B and Bank C respectively. We have to print the money
deposited by him in a particular bank.
Create a class 'Bank' with a method 'getBalance' which returns 0. Make
its three subclasses named 'BankA', 'BankB' and 'BankC' with a method
with the same name 'getBalance' which returns the amount deposited
in that particular bank. Call the method 'getBalance' by the object of
each of the three banks.
Problem 14

A class has an integer data member 'i' and a method named 'printNum'
to print thevalue of 'i'. Its subclass also has an integer data member 'j'
and a method named 'printNum' to print the value of 'j'. Make an
object of the subclass and use it to assign a value to 'i' and to 'j'. Now
call the method 'printNum' by this object.
NOTE: Hardcopy submission and implementation on laptop both will be
considered.

You might also like