Q2. Do a peer review of this code and suggest if any improvements can be done.
Task : Mahesh has suggested that we should define one function called PerformArithmeticOperation( ) which will take 2 numbers and the Delegate as parameters. Instead of calling / executing the delegate from Main() function, let this function manage the delegate call. You have to implement this functionality.
Hint: The PerformArithmeticOperation() function signature is:
static void PerformArithmeticOperation( int num1, int num2, MyDelegate arOperation){…}
Lab-10
Q.1) You need to perform Arithmetic operations on two numbers. The operations include Add Numbers, Multiply Numbers, Divide Numbers, Subtract Numbers and Find Max Number.
Task 1: Define a class ArithmeticOperation having the above methods.
Task 2: Define a Delegate which can call these methods.
Task 3: Create a console application to accept two numbers and arithmetic operation to be performed from the user. Based on the choice, the Delegate instance will hold the address of the appropriate method.
Task 4: Execute the delegate to get the required result.
You need to maintain file extensions along with file types in dictionary class
Tasks:
• Create a new dictionary of strings, with string keys.
• Add some elements to dictionary. There should not be duplicate keys, but some of values can be duplicates.
• The Add method throws an exception if new key is already in dictionary. Test this by adding a duplicate key.
• The indexer can be used to change value associated with a key. Try changing the value of any record and display the updated value.
• If a key does not exist, setting the indexer for that key adds a new key/value pair. Try this by adding a new value.
• The indexer throws an exception if requested key is not in dictionary. Try printing any such key which is not present and handle exception.
• When you use foreach to enumerate dictionary elements, the elements are retrieved as Key/Value Pair objects. Use a foreach loop to print the values and test this.
• Use the Remove method to remove a key/value pair.
Sameer has written a code to create the Hash Table. The code is given below.
class Program
{
static void Main()
{
}
static Hashtable GetHashtable()
{
// Create and return new Hashtable.
Hashtable hashtable = new Hashtable();
hashtable.Add("Area", 1000);
hashtable.Add("Perimeter", 55);
hashtable.Add("Mortgage", 540);
return hashtable;
}
}
You need to perform some tasks on this code. Write the functionality in the main method.
Task 1: See if the Hashtable contains the key “Perimeter”.
Task 2: Print the value of “Area” with indexer.
Task 3: Remove the entry for “Mortgage”
We need to maintain the list of RTO districts. e.g. MH01 – Mumbai, MH 04 – Thane etc. Write a program which uses a Hashtable to maintain this list.
Task 1: Create a console application to maintain the list. It should display a menu to perform the following tasks:
• Add Record in Hashtable
• Search record
• Display All Records
• To display Total count of Records at any point
• Remove any particular record
Manish has developed the code for the same. The requirement is given below. You need to review the code, find out any issues / bugs with the code and correct the same. Also you need to develop a Console based Client application for the same requirement. The Client application should allow Adding new Employee’s of specified type, Searching Records, Delete Records and View all records operations.
Problem Statement: XYZ computer Systems PVT Ltd. wants to develop an application to maintain employee details. You have to develop a .NET Application to accept new employee details and store the details in a Collection.
steps:
Task 1: Create a private DLL with a class Called Employee. Employee class will have Employee Number, Name and Basic Salary, and PF attributes. Define appropriate properties to access the attributes. Write 2 constructors, one default & one parameterized, to assign the values of the attributes when the object is created.
Task 2: Use List<Employee>collection.
Create a console application to accept Product Details like ProductNo, Name, Rate and Stock.
[Use Array List Collection]
Display the Menu to perform the following:
================
a. Adding New Product
b. Deleting Currently Searched Product
c. Searching Product
Searching will work as shown below:
• User will enter ProductNo.
• If the product with that productno exists in Collection, then the details should be shown, otherwise show appropriate message.
d. Save the New Product – The products should get saved in the sorted order of ProductNo.
You need to maintain a Contact List in a generic List Collection. You need to perform the following tasks: i. AddContact() – To add contact detail to List
ii. DisplayContact() – To display particular contact detail from List
iii. EditContact() – To modiy particular contact detail from List
iv. ShowAllContacts() – To display all contact details from List
Task 1: Create the Contact class with the following properties:
public int ContactNo{get;set;}
public string ContactName{get;set;}
public string CellNo{get;set;}
Task 2: Create a Console application and write the Code for the required functionality mentioned above.
Hint: a. There is a loop in Main() function which accepts the selection option
b. There are additional 4 static functions to perform required tasks which are called based on selection c. Use the List generic collection to maintain the list.
Implement a class MeraSet, which abstracts a mathematical Set of integral numbers. Maximum members can be 100. Implement MeraSet3 class similar to last assignment. Make it unlimited, ie. use new and delete to extend or contract memory size of underlying array as required. Initially make it size 1, and grow it to two when you have the first insert, and so on. Similarly reduce size by 1 when a member element is removed.
Implement following Member functions:
int Insert(int e) ; // adds value e to the set and returns 1, if the value already exists or the set has already 100 members, then it does not add and return -1.
int Size(); // return size of the set
int Remove(int e); // removes e from Set, and return 1. If e is not member of set, returns -1.
void Print(); // prints the members of the set in set notation e.g. Set = {1,2,3,8,-3 }
operator + ; // returns union of two sets
operator -; // returns difference set of two sets i.e. A-B
Make private member variables and more functions as you like.
Implement a class MeraSet, which abstracts a mathematical Set of integral numbers. Maximum members can be 100. Implement following Member functions:
int Insert(int e) ; // adds value e to the set and returns 1, if the value already exists or the set has already 100 members, then it does not add and return -1.
int Size(); // return size of the set
int Remove(int e); // removes e from Set, and return 1. If e is not member of set, returns -1.
void Print(); // prints the members of the set in set notation e.g. Set = {1,2,3,8,-3 }
operator + ; // returns union of two sets
operator -; // returns difference set of two sets i.e. A-B
Make private member variables and more functions as you like.