C# Answers

Questions answered by Experts: 1 362

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

The code has some bugs. It is supposed to raise an event, whenever the File is downloaded


delegate void DownloadCompeteHandler(int perc);

public class FileDownloader

{

protected string resourceUrl;

protected string resourceSavePath;

event DownloadCompeteHandler DownLoadComplete;

public FileDownloader(string url,string savepath)

{

this.resourceUrl = url;

this. resourceSavePath = savepath;

}

public void DownLoadResource()

{

for (int i = 1; i <= 4; i++)

{

for (int j = 1; i <= 10000; i++);

OnDownLoadComplete(i * 25);

}

}

protected void OnDownLoadComplete( )

{

if (DownLoadComplete == null)

DownLoadComplete( );

}

}

public static void Main(string[] args)

{

FileDownloader fd =

new FileDownloader("http://www.microsoft.com/vstudio/expressv10.zip", "d:\\setups");

fd.DownLoadComplete += new Handler();

fd.DownLoadResource();

Console.ReadKey();

}

static void fd_DownLoadComplete(int perc)

{

Console.SetCursorPosition(10, 10);

Console.Write("Downloading {0} Percent Complete", perc);

}


Lab-11

Q1. ICICI Bank want’s to implement SMS alert fascility to the customers whenever they pay the Credit Card Bill. The CreditCard class contains the following fields.

CreditCardNo, CardHolderName, BalanceAmount, CreditLimit.


The class has three functions. GetBalance(), GetCreditLimit(), and MakePayment(). Whenever the MakePayment() method is called, it should update the BalanceAmount and raise an event. The event should send a message. ( You don’t need to write a logic to send the sms. Only print the message saying amount is credited.)


Task to be performed:

Define a class CreditCard

Define a Delegate to Handle the Event

Define an event which will be raised whenever the payment is made.

Create a Console client application, and try the functionality.


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.


LATEST TUTORIALS
APPROVED BY CLIENTS