Sei sulla pagina 1di 5

C-Sharp Assignments

1. Define a console-program to create an array of integers. Initialize the array and assign the values
in array. Define a method to pass the array and modify array elements. Display array elements by
using for-each loop.

2. Define a console application to display all the arguments passed to command line while running
the application. The user can pass any number of arguments that should be displayed. Use length
property of array and for-next loop. If there are no arguments in command line display message
‘No Arguments’
3. Create a console application to display different messages depending on the command line
argument value. Use Select-case statements.(similar to switch block)

4. Define a console application with a class ‘Employee’ with variables as emp_id (int), name
(String) and Grade (double).Define five different constructors for this class to initialize the
variable values. Define Finalize method to display the Grade value. Define a for loop in Main for
4 iterations and inside for loop create Employee object. After the for loop call Garbage Collector.

5. Create a class library and define class ‘User’. In User class define the public, protected and Friend
functions. Create a console application and add a reference to this library and call the user
methods by creating the object. Which are the functions allowed to call here?

6. Create a console application to demonstrate the different styles of message boxes by calling
MsgBox functions with different parameters and icons as well. Check and display the result of
MsgBox on the screen for each MagBox (i.e. which MsgBox button user has
clicked.yes|no|Cancel)

7. Define a console application project to display the different formatting styles used in display
methods(i.e. Console.writeLine())

8. Create a console application with a class ‘Account’ having variables as id (int) and name
(String).Add property ‘account-no’ which can be set andget. Add a ‘ReadOnly’ property ‘IntRate’
and‘WriteOnly’property ‘Password’ for this class. Add a shared property ‘Branch’ with set/get
methods. In main method create objects of ‘Account’ and test these properties and print the
results on the screen.

9. Define a class library with three namespaces as ‘admin’, ‘HR’,’Sales’.Add three classes as
‘User’,’ Manager’ and ‘Executive’ in these namespaces respectively. Define different protected
and Friend methods in these classes and test their access outside library in a console application.

10. Define a class library having class ‘Mould’ with instance variables as protected color (string), and
‘public price (int).Add a shared variable size(int) has private access. Add public methods to
change the size, to get the price and read the color. In console application define a subclass
‘Statue’ deriving from ‘Mould’ and having overridden method for getting the price and color.
Add a shadowing method for reading/setting the size of statue objects. Define a main method and
test all these combinations
11. Create a console application. Add class ‘Account’ having variables as num (integer) name
(String), bal (double), ac_code (byte).define four different constructors to initialize these
variables. Define a class ‘User’ deriving from ‘account class. In user class add variables as
group_no (int) and mail_idString).Define three constructors for User class and within them call
different parameterized constructors of Account. Can we call these base class constructors as
second or last statement in User constructors? Define another class ‘’Admin’. Can the User class
derive from both ‘account’ and ‘Admin’ classes? How to make Class Admin such that No class
can derive from it?.How to make Account class such that some methods will not be allowed to
override ?

12. Define a interface ‘Human’ with methods as walk’ and ‘speak’. Define a class ‘User’
implementing ‘Human’. Define a work() method in User class. Add a class ‘Person’ also
implementing Human. Add a method ‘Behave’ in Person class. In Main method create objects of
Person and User and assign them to ‘Human’ type and call Human methods. Can the work and
Behave methods be called through Human types? Can we create the interface objects by calling
interface Constructors ? Justify your answer.

13. Define an interface ‘WorldBank’ having methods as ‘setHousingLoans’ and


‘GrantRuralAid(String countryName). Define interface ‘RBI’ inheriting WorldBank’. Define a
class ‘SBI’ implementing RBI.In main method create SBI objects and assign them to WorldBank’
and RBI types and call their respective methods.

14. Define a interface ‘User’ and ‘Employee’. Add methods ‘work(int hours) and get Salary() in
Employeee.Add methods checkMail and celebrateVacation in User. Define a class Person
implementing both these interfaces and add a method MakeFood in Person. In main method
create single object of Person and use it to represent User and Employee types at a time and call
respective methods. Can User type call Employee methods and Employee type call User
methods? Can User and Employee call the MakeFood method of Person ?

15. Define an abstract class ‘Bank’ having abstract methods as ‘CreateAccount’ ‘depositAmount’ and
‘withDrawAmount’.Add method definitions for ‘CalculateInterest’ and ‘SetIntereset’ as Non-
Overridable.Define two classes ‘BharatiBank’ and ‘RupeeBank’ to derive from bank class.In
main ,method create objects of BharatiBank’ and RupeeBank’ to represent Bank type and call
their respective methods. Can Bank type call the derived classes own methods that re not defined
in bank ?

16. Design appropriate classes to perform Matrix Addition and Matrix Multiplication

17. Design custom exception Handlers for a Boiler class.Throw the custom exception
BoilerException when the pressure is more than 2000 units or less than 500 units
It should have the following Members and Methods.
Members :double pressure

Methods :void Increase(); --> Increase by 100 units

void Decrease(); --> Decrease by 100 units


18. Design a Calculator User Interface that looks exactly like the cacl.exe in Windows

19. Design the following classes. Choose the appropriate constructors, properties and methods as
needed other than the ones mentioned. Represent a two dimensional Point class. It will have the
following members

x
y

Create a method called

double Distance(Point otherPoint);

that returns the distance from the current point to the other point

20. Design a class called Stack. It will have the following member

int[] data

Create the following methods

o void Push(int num);


o int Pop();
o int Peek();
o bool IsFull();
o bool IsEmpty();

21. Design a class called Sorter It will have the following member

int[] data

Create the follwoing methods


o void BubbleSort();
o void SelectionSort();
o void InsertionSort();

22. Design a class called Searcher It will have the following member

int[] data

Create the following methods

int LinearSearch(int searchData); This returns the position of the first occurance in the array

int BinarySearch(int searchData); This returns the position of the first occurance in the array

23. Used Car Dealership Inventory

Your task is to create a simple text-based "Console Application" in C# to maintain a catalog of used
cars. The catalog keeps track of each car's make, model, year, and sale price.

The program begins with an empty catalog. The user is prompted to enter one of three possible
commands:

add - add a car to the catalog


list - list all cars in the catalog
quit - quit the application

If an unknown command is entered, the user should be informed and asked to enter another
command. If the add or list commands are entered, the operation for that command is carried out, then
the user is prompted for another command. The application continues until the quit command is
entered.

The add command

If the add command is entered, the user will then be prompted to enter the car's make, model, year,
and sales price, one-by-one. The make (e.g. Isuzu) and model (e.g. Trooper) can be arbitrary strings,
while the year (e.g. 1990) should be an integer and the sales price (e.g. 2599.99) should be a floating
point value. After the data is entered, the record should be stored in memory to be recalled later by the
list command. You may assume that the catalog will never hold more than 20 cars.

You are not required to do any error checking on the data that is entered. For the purpose of keeping
the assignment simple, the program may behave arbitrarily badly if the user enters improperly
formatted input.

The list command

If the user enters the list command, the contents of the catalog should be displayed to the screen,
nicely formatted. The format of the output should resemble the example trace below. Regardless of
the precision of the stored sales price, the value should be formatted in dollars and cents. If no items
exist in the catalog, the command should output a message stating so. Otherwise, after printing out the
details of each car, the number of cars and total price of all cars should be printed.

Example program trace


Welcome to Mullet Joe's Gently Used Autos!

Enter command: show

Sorry, but "show" is not a valid command. Please try again.

Enter command: list

There are currently no cars in the catalog.

Enter command: add


Make: Volkswagen
Model: Jetta
Year: 1999
Sales Price ($): 9450

Enter command: add


Make: Toyota
Model: Prius
Year: 2006
Sales Price ($): 27999.90

Enter command: list

1999 Volkswagen Jetta $9,450.00


2006 Toyota Prius $27,999.90

Number of cars: 2
Total inventory: $37,449.90

Enter command: quit

Good bye!

Extending the assignment

For extra practice, feel free to extend this assignment in any way that you choose. Some example
extensions include adding a "delete" command or the ability to sort the cars in the catalog by year
or price.

Potrebbero piacerti anche