0% found this document useful (0 votes)
14 views8 pages

C# Class Design Exercises Guide

The document outlines a series of programming exercises focused on object-oriented programming concepts in C#. It includes the creation of various classes such as Month, Student, Human, Member, Shape, BankAccount, Employee, and Marks, each with specific properties and methods. The exercises emphasize encapsulation, inheritance, and the implementation of abstract classes and methods.

Uploaded by

nattsamm12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

C# Class Design Exercises Guide

The document outlines a series of programming exercises focused on object-oriented programming concepts in C#. It includes the creation of various classes such as Month, Student, Human, Member, Shape, BankAccount, Employee, and Marks, each with specific properties and methods. The exercises emphasize encapsulation, inheritance, and the implementation of abstract classes and methods.

Uploaded by

nattsamm12
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXERCISE 9:

❑Create a Month class that has a single data member of (private)


month number.
▪Create a public properties for month number variable.
▪Include a member method that returns the name of the month and another
method that returns the number of days in the month.
▪The DisplayDetail( ) method should return the name and number of days.
❑Write a second class to test your Month class (TestMonth).
▪The second class should allow the user to input a month number.
▪Display the name of the month associated with the number entered and the
number of days in that month. For this exercise, use 28 for February. If the
user inputs an invalid entry, display an appropriate message.

11/12/2024 ANDARGACHEW A. 63
EXERCISES 10:
1. Define a class Student, which contains the following
information about students: full name, course, subject,
university, e-mail and phone number.
2. Declare several constructors for the class Student,
which have different lists of parameters (for complete
information about a student or part of it).
3. Modify the current source code of Student class so as to
encapsulate the data in the class using C# properties.
11/12/2024 ANDARGACHEW A. 64
EXERCISE-11
❑Define a class Human with properties "first name" and
"last name". Define the class Student inheriting Human,
which has the property "mark". Define the class Worker
inheriting Human with the property "wage" and "hours
worked". Implement a "calculate hourly wage" method,
which calculates a worker’s hourly pay rate based on
wage and hours worked. Write the corresponding
constructors and encapsulate all data in properties.

11/12/2024 ANDARGACHEW A. 87
EXERCISE-12
❑Create a class named 'Member' having the following
members: Name, Age, Phone number, Address, and Salary
▪It also has a method named ‘PrintSalary' which prints the salary of the
members.
❑Two classes 'Employee' and 'Manager' inherits the 'Member'
class.
▪The 'Employee' and 'Manager' classes have data members
'specialization' and 'department' respectively.
❑Now, assign name, age, phone number, address and salary to
an employee and a manager by making an object of both of
these classes and print the same.

11/12/2024 ANDARGACHEW A. 89
EXERCISE-13
❑Define an abstract class Shape with abstract method
CalculateSurface() and fields width and height.
❑Define two additional classes for a triangle and a rectangle, which
implement CalculateSurface(). This method has to return the areas of
the rectangle (height*width) and the triangle (height*width/2).
❑Define a class for a circle with an appropriate constructor, which
initializes the two fields (height and width) with the same value (the
radius) and implement the abstract method for calculating the area.
❑Create three different shapes (rectangle, triangle, circle) and
calculate the area of each shape.

11/12/2024 ANDARGACHEW A. 111


EXERCISE-14
❑Write a C# program to create an abstract class
BankAccount with abstract methods deposit() and
withdraw().
▪Includes two private attributes account number and balance in
BankAccoutn class.
▪Create SavingsAccount class that inherits the BankAccount class
and implement the respective methods to handle deposits and
withdrawal.
▪Includes one private attribute amount in SavingsAccount class.
▪Use appropriate constructor and properties for each class

11/12/2024 ANDARGACHEW A. 112


EXERCISE-15
❑Write a C# program to create an abstract class Employee
with abstract methods calculateSalary() and displayInfo().
Add name and base salary attributes.
▪Create subclasses Manager and Programmer that extend the
Employee class and implement the respective methods to calculate
salary and display information for each role.
▪Include one private attribute bonus in Manager class and calculate
salary by adding base salary with bonus.
▪Include two private attributes over time hour and hourly rate in
Programmer class and calculate salary by adding base salary with
product of over time hours and hourly rate.
▪Use appropriate constructor and properties for each class.

11/12/2024 ANDARGACHEW A. 113


EXERCISE-16
❑We have to calculate the percentage of marks obtained in
three subjects (each out of 100) by student A and in four
subjects (each out of 100) by student B.
▪Create an abstract class 'Marks' with an abstract method
'getPercentage'.
▪It is inherited by two other classes 'A' and 'B' each having a method
with the same name which returns the percentage of the students.
▪The constructor of student A takes the marks in three subjects as its
parameters and the marks in four subjects as its parameters for student
B.
▪Create an object for each of the two classes and print the percentage
of marks for both the students.

11/12/2024 ANDARGACHEW A. 114

You might also like