Sei sulla pagina 1di 3

C#.

NET Lab Exercises 1

1. Create a solution workspace ‘ConsoleApps’ and add a project ‘consoleTest’ to


it to display ‘Welcome’ message on command line.
2. Add another console project in above solution to display Symmetrical Rangoli
pattern as shown on the command line using loop control statements

* *******
** ******
*** and *****
**** ****
***** ***
****** **
******* *
3. Define a program similar to in assignment 2 above which will display user
specified characters from command line in the Rangolis instead of ‘*’
character.i.e.

CCCCCC
CCCCC
CCCC
CCC
CC
C

and ?
??
???
????
?????
??????
4. Define a class named 'myClass' and having following variables and
methods
Variables:
shared Name string type
integer Num
Constructor:
Define the constructor to initialize Num and Name variables to specified
values.
shared methods
setName (String newName) to assign newName to Name variable
Instance method
getName to return the value of Name variable and print the "GetName"
message.
Define two properties as ‘id’ and ‘balance’ and provide set/get methods.
Define the test program to create the instances of 'myClass' and assign
different values to its properties and print them.
5. Define a program to demonstrate type casting/conversion from string to byte,
short, long and int parameters use implicit and explicit casting provide type
casting to double and float parameters by giving higher and smaller range
values and print the values before and after conversions.
6. Define a class to print a message when the class objects are destroyed by
the garbage-collector. (i.e. Provide finalize ( ) method.) In main ( ) create
objects and call garbage collector to destroy the objects
7. Define an Account class with parameters as int no, string type double balance
Define different overloaded constructors and call the other constructors in
overloaded constructors. Print the messages in respective constructors.
8. Define a class ‘Shape’ with different methods with same name ‘DrawShape’
but with different set of parameters. Define these overloaded methods and
demonstrate their use in main ( ) method. Use method overloading.
9. Define a ‘Base’ class with variables int acc_no, string Br_name;
Define the method as
Public sub SetNumber (integer no)
this.acc_no=no;
End sub

Public sub SetName ( String s )


Br_name=s;
End sub

define a class ‘Child’ inheriting ‘Base’ class with variables such as


int acc_no and method as
Public Function getAccountNumber ( ) as integer

integer t= acc_no;
return t;
End sub

in main( ) method of child class create objects of base and child classes
and assign values to these objects call the respective methods using
these objects and print their messages And values.
10. Create 2 base classes namely Account and Person (Account class will have
the properties for AccountId, Type, Balance and Person will have FirstName,
LastName and Address)
• Create derived classes deriving from the base classes namely
SavingAccount (base Account), BankCustomer (base Person)

11. Create a class library with following methods


– Function to Add two integers (Public)
– Use namespaces in library
– Function to Subtract two integers (Protected)
– Function to find whether the given number is positive (Private)
should be used for next function
– Function to find the factorial of positive integer (Friend) if the
number is not positive send back message accordingly
– Function to find the square root of a given integer (Protected
Friend)
• Create a console application which uses the above class library
• Create another class in the previous library which inherits the first class
and try using the protected methods

****************

Potrebbero piacerti anche