المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Count Unique strings and Custom Calculator C#



C# Programming
07-19-2009, 08:30 AM
Hi All,

I have three exercises.Please provide sample code for the below requirements..


// Exercise -1


Provide code to sort a collection of Item. The code should sort the Item collection only one time, following this rule: The Items should be ordered by their names (following the standard C# API for string ordering), but if two Items have the same name, then those Items should be ordered by their cost, with the lower cost item to appear before the higher cost item.

The initial code solution should not use LINQ. Bonus points for providing a second solution using LINQ.



// Exercise -2

Provide code to analyze a String collection and generate a report that identifies what unique Strings are in the collection, along with a count of how many times each unique String appears in the collection.

Use Console.WriteLine to generate the simple report.
The initial code solution should not use LINQ. Bonus points for providing a second solution using LINQ.


EXAMPLE:

If the String collection has these five Strings:

House
Car
Dog
Car
Car

...the console report should look more or less like this:

Item - Count
---------------------
House - 1
Car - 3
Dog - 1

====


// Exercise -3
Provide code for a simple calculator that takes in from the command prompt a mathematical expression, and outputs to the command prompt the calculated value of the expression. The calculator need only handle input expressions with a single binary operator, and with integral operand values within the range 1 to 100.

The calculator should handle these five operators.

1. U
The U operator returns the addition of the two operands.
2. K
The K operator returns the greater of the two operands.
3. Y
The Y operator returns half of the multiplication of the two operands.
4. Z
The Z operator returns the value of the first operator divided by the second operator.
5. P
The P operator returns the value of the first operator plus twice the value of the second operator.



We have very creative business units, who will later want to have over eighty binary operators added to the calculator. So, describe what changes and/or additions would be necessary to make to the calculator code, in order to add handling for more binary operators.

EXAMPLE USES OF THE SIMPLE CALCULATOR:

input: 2 U 4
output: 6

input: 5 Y 3
output: 7

input: 6 P 7
output: 20

Thanks & Regards
Rao