Вы находитесь на странице: 1из 10

C# .

NET Assignments

Visual Studio Assignments


1. Write a console application named VSPractice that produces following output: Hello World!!!
2. Create a solution workspace ConsoleApps and add a project consoleTest to it to display
Welcome message on command line.

Variables & Data Types


1. Write a program to read your name
2. Write a program to read your family names (father, mother, brother, sister) and print them as
follows
Output 1: Father, Mother, Brother, Sister, You
Output2: You, Sister, Brother, Mother, Father
Output3: Brother, Sister, You, Father, Mother
3. Write a program to print minimum and maximum values of all data types

Operators
1. Write a program to find biggest number among given 3 numbers using ternary operator?
2. Write a program to find the no. of bytes required in memory by all value types?
3. What is the output of following programs? First do it on book then verify it by executing in visual
studio?
a.
int d;
d = Convert.Tolnt32( !(30 < 20) );
What is the value of d?
b.

Console.WriteLine(13 / 2 + " " + 13 % 2);

c.

int num = 1, z = 5;
if (!(num <= 0))
Console.WriteLine( ++num + z++ + " " + ++z );
else
Console.WriteLine( --num + z--+ " " + --z );

d.

int a = 10, b = 20, c= 30;


int res = a < b ? a < c ? c : a : b;
Console.WriteLine(res);

Flow Control Statements


1. Write a program to find given number is even or odd?
2. Write a program to find the given number is prime or not?
www.gideeducation.com

Page 1

C# .NET Assignments
3. Write a program to find factorial of given number?
4. Write a program to find given number is palindrome or not?
5. Write a program to check given number is Armstrong number or not? (Armstrong number means
cubes of digits of number should be equal to number i.e. if number is 371 , cubes of each digit
(3*3*3) + (7*7*7) + (1*1*1) is equal to 371)
6. Write a program to print following pattern?
*
**
***
7.

****
Write a program to print diamond structure?
*

*
8. Write a program to print the prime numbers between two given numbers?
9. Write a program to print even and odd numbers between two given numbers?
10. Write a program to print Fibonacci series?

Arrays
1.
2.
3.
4.
5.

Write a program to read array elements and print them using for and foreach?
Write a program to print the array elements in reverse order?
Write a program to sort the elements of the array?
Write a program to check whether element is part of array or not?
Write a program to perform arithmetic operations (addition, subtraction, multiplication) on matrix
(two dimensional array)?

Strings
1.
2.
3.
4.
5.

Write a program to print length of a given string


Write a program to reverse a string
Write a program to find the no. of spaces in the given string
Write a program to find no. of words in given string
Write a program to print the words of string in the reverse order Example: I/P -How are you O/P you are How

www.gideeducation.com

Page 2

C# .NET Assignments
6. Write a program to print no. of occurrences of each character in given string Example: if string is I
Love India output should be I -3, L 1, o1, e1, n1, d1, a1

OOPS
1. Create a class Big and define two -member functions one function will take two integers data item
from the console and by use of another member function that will calculate the biggest out of two
and display the result.
2. Create a console application with a class Account having variables as id (int) and name (String).Add
property account-no which can be set and get. Add a ReadOnly property IntRate and WriteOnly
property Password for this class. In main method create objects of Account and test these
properties and print the results on the screen.
3. Input name, date of Birth of person and calculate Age in Year, Month and days assume that 1 year =
365 days and 1 month = 30 days.
4. 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.
5. 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.
6. Design a class called Stack. It will have the following member int[] data Create the following
methods void Push(int num); int Pop(); int Peek(); bool IsFull(); bool IsEmpty();
7. Create a student class having data members roll, class, name and marks in sub1, sub2, sub3. Display
the student details according to their percentage.
8. Define a class to represent a bank account of a customer including a member variables Name of the
depositor, Account number, type of account, balance amount in the account and the member
functions to assign initial values of member variables, to deposit an amount, to withdraw an amount
after checking, to display name and balance. Write a main program to test the program for n
number of customers.

www.gideeducation.com

Page 3

C# .NET Assignments
9. 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.

10. Create a class called user_time that has separate integer members for hours, minutes and seconds.
One constructor should initialize this data to 0, and another should initialize it to fixed values. A
member function should display it in HH:MM:SS format. The final two member functions should add
and subtract two objects of time passed as arguments. A main () program should create two
initialized user_time objects. Then it should add the two initialized together, leaving the result in the
third user_time object. Finally it should display the value of third variable.
11. Write a program to read the employee details (ID, Name, Salary,DeptID), print them according to
Salary in ascending order and print them according to their department.
Department ID -1
Employee Details
Department ID -2
Employee Details
12. 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

www.gideeducation.com

Page 4

C# .NET Assignments
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
exampleextensions include adding a "delete" command or the ability to sort the cars in the catalog
by yearor price.
13. An electricity board charges the following rates to domestic users to discourage large consumption
of energy.
For the first 100 units -40 P per unit
For the next 200 units 50 P per unit
Beyond 300 units -60 P per unit
All users are charged a minimum of Rs. 100 /-. If the total cost is more than Rs. 250/-then an
additional surcharge of 15% is added. Write a program to read the names of users and numbers of
units consumed and print out the charges with names.
14. A bookshop maintains the inventory of books that are being sold at the shop. The list includes
details such as author, title, price, publisher and stock position. Whenever a customer wants a book,
the sales person inputs the title and author and the system searches the list and displays whether it
www.gideeducation.com

Page 5

C# .NET Assignments
is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays
the book details and requests for the number of copies required, If the requested copies are
available, the total cost of the requested copies is displayed; otherwise the message Required
copies not in stock is displayed. Design a system using a class called books with suitable member
functions and constructors, Use new operators in constructors to allocate memory space required.
15. Write a program using array of objects which store player name match played and run scored for
given number of players involve member func Hons to obtain player with maximum match played,
maximum run scored and maximum average.
16. Five candidates contest an election. The candidates are numbered 1 to 5 and marking the candidate
number on the ballot paper does the voting. Write a program to read the ballots and count the
votes cast for each candidate using an array variable count. In case a number read is outside the
range 1 to 5 the ballot should be considered as a Spoilt ballot and the program should also count
the number of spoilt ballots.

Inheritance & Polymorphism


1. Implement a base class Person. Derive classes Student and Instructor from Person. A Person has a
name and a birthday. A student has a batch, course and an Instructor has a salary. Write the class
definitions, the constructor and the member function print () for all classes.
2. Define a class library having class Mould with instance variables as protected color (string), and
price (int). 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.
3. Derive a class Manager from Employee. Add a data field named Department of type String, supply
print() method that prints the Managers name , department and salary. Derive a class Executive
form Manager. Supply function print() that prints the string Executive followed by the information
stored in Manager base object.
4. 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_id
(string).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 derivefrom both account and

www.gideeducation.com

Page 6

C# .NET Assignments
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?
5. Implement a base class Account and derived classes Savings and Checking. In the base class, supply
member function deposit and withdraw. Provide a function daily-interest that computes and adds
daily-interest. For calculations, assume that every month has 30 days. Checking accounts yield
interest of 5% monthly on balances over Rs. 1000/-. Savings account yield interest of 6% on the
entire balance. Write a driver program that makes a months worth of deposits and withdraws and
calculate the interest every day.
6. Write a base class Worker and derived classes HourlyWorker and SalariedWorker .Every worker has
a name and a salary rate. Write a virtual function ComputePay (in hour) that computes weekly pay
for every worker. An hourly worker gets paid the hourly wages for the actual number of hours
worked. The hours are at most 40 per week. If it is greater than 40, the worker gets 1.5 times of the
hourly rate for excess hour. The salaried worker gets paid the hourly wage for 40 hours, no matter
what the actual number of hours is.
7. Design and implement classes Politician, MP and MLA.MP and MLA and derived classes of
Politician. Politician is a derived class from Person (Name and Phone Number).A Politician, in
addition to name and phone number, has a party and a state. Class MP has a rank LS / RS. Class MLA
has in addition one identification number. Your design will include methods to initialize, access and
filing in.

Overloading
1. Complete the Matrix Addition, Subtraction and Multiplication using Class and Operator Overloading.
2. Write a program that overload the operator * where A is a 2D matrix. User the expression as: 1)
A*2, 2) A*A, 3) 2*A.
3. Write a program to construct a class MyString which has one string and length of that string as
data members. Overload the following operators: a) -for string copy, b) == for string comparison
c) + for string concatenation.

Abstract Class & Interface


1. Define an abstract class Bank having abstract methods as CreateAccount depositAmount and
withDrawAmount. Add method definitions for CalculateInterest and SetIntereset as NonOverridable. 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
www.gideeducation.com

Page 7

C# .NET Assignments
respective methods. Can Bank type call the derived classes own methods that are not defined in
bank?
2. Define an interface WorldBank having methods as setHousingLoans andGrantRuralAid (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.
3. Define an 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
4. 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?

Collections
1. Practice the programs taught in class
2. Convert the OOPs programs 7 (Student Management), 11 (Employee Management) using Custom
Collection and Custom Sorting.

Delegates & Events


1. Write a program to implement a delegate called StrMod that takes one string parameter
and returns a string.
a. Create a class DelegateTest, two static methods are declared namely Replace and
Reverse having the following signatures.
static string Replace(string str);
static string Reverse(string str);
Replace inserts space between the characters on input string. For ex. If input string is
ILoveIndia output be I L o v e I n d I a
Reverse is used to reverse a string. For ex. If the input string is ILoveIndia output
be aidnIevolL

www.gideeducation.com

Page 8

C# .NET Assignments

Generics
1. Convert the OOPs programs 7 (Student Management), 11 (Employee Management) using Custom
Generic Collection and Generic Custom Sorting. Both should be done in single program.

File System
1.
2.
3.
4.

Write a program to create a text file named MyDataFile that contain some data in D:\
Create a folder called TestFolder in D:\
Copy the file into the folder
Write a program to print all the subfolders and files present in the path C:\Program Files\Internet
Explorer. (Need to display folders of subfolders also till the depth 0)

XML
1. Write a program to work on below XML file
a. Add a new employee with dynamic data to the xml file
b. Display the employee names who work for department 3
c. Display the employee names who salary is > 10000
d. Delete a Employee with specific id
e. Update the salary and deptid of specific employee
<Employees>
<Employee ID=1111>
<Name>
<First>Adam</First>
<Last>Kessler</Last>
</Name>
<Salary>23000</Salary>
<DeptID>4</DeptID>
</Employee>
</Employees>

Exception Handling
1. Design custom exception Handlers for a Boiler class. Throw the custom exceptionBoilerException
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

www.gideeducation.com

Page 9

C# .NET Assignments

Threading
1. Create a class with methods and invoke them with different threads

Assemblies
1. 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?
2. Define a class library with three namespaces as Admin, HR and Sales. Add three classes as
User, Manager and Executive in these namespaces respectively. Define different protected and
public methods in these classes and test their access outside library in a console application.
3. Create a class library with following methods
a. Function to Add two integers (Public)
b. Function to Subtract two integers (Protected)
c. Function to find whether the given number is positive (Private)should be used for next
function
d. Function to find the factorial of positive integer (internal) if the number is not positive send
back message accordingly
e. Function to find the square root of a given integer (ProtectedInternal)
4. 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

Reflection
1. Define a class with five members, Methods, Properties and invoke all using Reflection.

www.gideeducation.com

Page 10

Вам также может понравиться