C# Lab Assignment:
Question 1. Program to Print Pascal triangle?
Question 2. WAP to print the ARMSTRONG Number?
Question 3. WAP to implement String Using array’s?
Question 4.Lookup theSystem.DateTimestructure. This type contains a large amount of functionality that allows a user to perform all sorts of interesting operations with dates and times. Use System.DateTime along with System.Console to implement a simple C# program that does the following:
- Ask the user for their birthday. It will probably easiest to ask year, then month, then day rather than parsing a combined string reliably.
- Calculate the age of the user.
- Check to see if the age of the user is impossible. For example, if the user is not yet born, output an error message. If the user claims to be 135 years old, then let them know that's not possible.
- Output the age of the user to the console.
- If it is the user's birthday, output a nice message.
- Compute the user's astrological sign according to both the Western (sun sign) and Chinese astrological systems. If you are not familiar with these astrological systems, look them up on the web.
- Output the computed signs to the console. Optionally output additional information (e.g. horoscope of the day) about the user based on their sign.
Questions 5.Create a reference type calledPerson. Populate thePersonclass with the following properties to store the following information:
- First name
- Last name
- Email address
- Date of birth
Add constructors that accept the following parameter lists:
- All four parameters
- First, Last, Email
- First, Last, Date of birth
Add read-only properties that return the following computed information:
- Adult - whether or not the person is over 18
- Sun sign - the traditional western sun sign of this person
- Chinese sign - the chinese astrological sign (animal) of this person
- Birthday - whether or not today is the person's birthday
- Screen name - a default screen name that you might see being offered to a first time user of AOL or Yahoo (e.g. John Doe born on Feburary 25th, 1980 might bejdoe225orjohndoe022580)
Question 6.Create an interface calledPayable. This is the interface that will be used by the accounting department's software (which you are not responsible for authoring) for all things that they need to write checks for. ThePayableinterface should contain three functions:
- Retrieve amount due
- Add to amount due
- Payment address
Derive anEmployeeclass from thePersonclass. TheEmployeeclass should add the following properties:
- Salary
- Mailing address
In addition, theEmployeeclass should implement thePayableinterface. The implementation of the functions specified in thePayableinterface should make sense. In other words, the payment address should be the mailing address of the employee. In order to make this work right, you will need to allocate an internally protected state variable that keeps track of the amount of money due. This state variable will obviously be modified by the functions defined in the interface. You can of course, try to do this with a property and add this property to thePayableinterface.
Question7.WAP to implement SET,Get Properties?
Question8.Create a console application to calculate area of circle. Accept radius from user Calculate circle area and print it
Create a console application to build simple calculator Calculator will have following functions Accept 2 numbers Perform Add/Sub/Div/Mult Print Result.
Question 9.Create a class Customer with following member fields
private int CustId, internal string CustName, public string CustNumber
Create an instance of Customer class and check accessibility of all fields
Add a static field int NoOfCustomers to Customer class
Create multiple instances of Customer class. On each new instance increment NoOfCustomers by 1
Print NoOfCustomers
Make CustNumber field as Read only
Add a constant field string CompanyName to Customer class
Question 10.Create a class Customer with following member fields private int CustId, internal string CustName, public string CustNumber
Add a static field int NoOfCustomers
Add a method PrintCustomer() to print customer details
Add PrintCustomer methods of different method signatures
Add a static method PrintNoOfCustomers(). This method should print value of NoOfCustomers field
Question 11.Create a class Employee with fields protected int EmpId, protected string EmpName,private EmpSalary Create a subclass Contractor for base class Employee. Define a constructor for Contractor. Can you initialize all variables defined in the base class?Create instance of subclass Contractor. Are base class constructors accessible?Invoke Contractor's constructor. Which all constructors are getting invoked?
Define a field in Contractor matching its definition in the base class Employee. Is that allowed?
Question 12.Create a class Employee,Create a subclass Contractor for base class Employee
Seal Contractor class,Check if you are able to create sub class TempContractor for base class Contractor?
Question13.Create a class MyHelper static class
Add a static field int icount in MyHelper class
Add a static constructor to MyHelper class. Initialise icount to 10
Add a static method PrintCount in Myhelper class
Check if you are able to call MyHelper.PrintCount method from main method
Question 14.Create base class Customer and subclasses SilverCustomer and GoldCustomer
Define discount() method in Customer class whcih returns 20% discount
Overload discount method in the subclasses and return different discount value
Define base class variable as "Customer cust"
Assign different objects of Customer, SilverCustomer and GoldCustomer to variable cust one after other and invoke discount method each time. What is the discount % returned each time?
Question 15.In the earlier assignment, how will you access the discount() method of Customer class from SilverCustomer and GoldCustomer classes?
Question 16.Continue earlier assignment
Define another discount method in Customer class taking String location as parameter. Can it be invoked?
Can this method be invoked from SilverCustomer or GoldCustomer classes?
Try to overload this discount(String) method in SilverCustomer class. Try to invoke it. Does the program run?
Question 17.Continue earlier assignment:
Define a new method getCustomer. This should return instance of Customer or SilverCustomer or GoldCustomer class randomly.
Main method will call getCustomer and then invoke the discount() method on the object received. Execute and observe the results.
Now create a new PlatinumCustomer class extending Customer class. Implement discount() method in this class
How do you invoke discount method of PlatinumCustomer class without changing main method?
Question 18:Create a class ContactDetails
Add private fields string stdcode, string city, string email
Add property StdCode with both get and set accessors defined.
In set accessor check if set stdcode is “020” if yes then set city = “Pune” else reject value
Add property City with only get accessor defined
Add property Email with both get and set accessors
From Main method try setting property StdCode with value “020” check the value of property City
From Main method try setting property StdCode with value “023” check the value of property City.
Question 19.Create an array of integers
Sort the array using a standard sorting algorithm such as Bubble sort etc
Question 20.Create a class Customer
Add a property City
Create an array of type Customer
Print Customer details who are from Pune city
Question 21.Create a class Customer:
Add a property City
Create an array of type Customer
Print Customer details who are from Pune city
Question 22.Create a new interface BaseCalculator to develop a simple CalculatorDefine two methods sum and divide in the interface. Can you implement the methods inside the interface?Create a new class which implements above interface. Do you need to implement both the methods here?Now define one more interface ScientificCalculator and add couple of methodsDerive ScientificCalculator from BaseCalculator interface
Create a class to implement ScientificCalculator interface, Check which methods needs to be implemented in new class?
Question 23.Continue earlier assignment:
Define a variable whose type is an interface for the BaseCalculator,Assign an object of BaseCalculator implementation,Invoke methods defined by the interface using the interface reference. Does the program execute?
In class implementing BaseCalculator interface add a method,Check this method is accessible from variable whose type is interface BaseCalculator.
Question 24.Continue earlier assignment
Create an interface AdvanceCalculator
Add couple of methods in this interface
Ensure that one of the method's signature is same as ScientificCalculator interface's method signature
Create a class implenting ScientificCalculator and AdvanceCalculator interfaces
Check what happens to method whose signature is common to ScientificCalculator and AdvanceCalculator interfaces
Question 25.Define a method doCalc() in a class. It accepts an int parameter iVal
Perform following calculation "return 100/iVal;"
Invoke it from main method by passing zero value. What happens when you execute?
Introduce try-catch block around the method call. Which exception you need to catch for a meaningful message?
Introduce a finally block after the catch block. When does it get called?
In the catch block make sure that you print the complete stack trace of error.
Write following code below the method call doCalc() "String str = argv[2];". Which exception is thrown on execution?
Handle the exception using another catch block.
Question 26.Continue earlier assignment
Immediately after the try block add a catch block without any exception type, do you get any error during compilation time?If you remove the all catch blocks, do you get any error during compilation time?
Question 27.Define a custom exception
Throw it using throw keywordHandle it in a catch block and examine various properties of exception
Question 28.Create a string
Assign it with large string value consisting of no of words
Access the string character by character and print
Access the string word by word and print
Split the string by using full stop character. Print the resultant strings.
Count no. of times a character has appeared in the string e.g. Char A - 132 times B - 50 times etc
Find a pattern in the string such as "AB" and replace it with some other string
Question 29.Create a class Circle
Create an Enum Colors containng various color values such as GREEN/RED etc
Create a field CircleColor in Circle class which of type Enum colors
Create an instance of Circle class and set Color value to CircleColor
Print the Color value of CircleColor
Question 30.Create abstract class Car
Define an abstract method ignition()
Define a non-abstract/normal method changeGear(). Is this allowed?
Create concrete classe Sedan. Overload ignition method
Create instance of Sedan and invoke ignition() and changeGear() methods. Does the program execute?
Define a variable noOfWheels in Car class. Can it be accessed in Sedan class?
Question 31.Continue earlier assignment
Create an abstract class SUV extending Car class. Do you need to implement all abstract methods of Car class here?
Define method 4WheelDrive() in SUV class
Create a concrete class Safari extending SUV class. Which methods must be implemented here?
Question 32.Create a class Magazine
Write a method Subscribe in Magazine class. This method should receive a delgate as parameter for call back.
Write a method Publish(). This method should call all subscribed instances
Create a class Subscriber
Create a call back method ReceiveMagazine. This method should be used as call back method
Question 33.Create an instance of Magazine class
Create multiple instances of Subscriber class and subscribe with Magazine instance created
Call Publish() method of Magazine class and check if all subscribed instances are notified.