Professional Documents
Culture Documents
Assignment 2 - 10882603
Assignment 2 - 10882603
ASSIGNMENT 2
(SUBMIT ANSWER IN MS WORD OR PDF DOCUMENT)
ID: 10882603
Create a BankAccount class with private attributes accountNumber and balance. Implement
public methods Deposit() and Withdraw() to modify the balance. Use appropriate access
modifiers to encapsulate the attributes and ensure proper data manipulation.
Solution
using System;
class BankAccount
{
private string accountNumber;
private decimal balance;
Q2. Employee
Construct an Employee class with private attributes name, designation, and salary. Implement
public properties to manipulate these attributes. Utilize access modifiers to enforce
encapsulation and control access to the class members.
Solution
class Employee
{
private string name;
private string designation;
private decimal salary;
Q3. Student
Design a Student class with private attributes name, age, and grade. Include public methods
to set and retrieve these attributes. Use appropriate access modifiers to encapsulate the
attributes and control their accessibility.
Solution
class Student
{
private string name;
private int age;
private int grade;
Q4. Car
Develop a Car class with private attributes make, model, and year. Implement public
properties to access these attributes. Ensure appropriate access modifiers to provide
controlled access to the class members.
Solution
class Car
{
private string make;
private string model;
private int year;
Create a class called LibraryBook with private attributes title (string), author (string), and
available (bool). Implement public methods to get and set the availability of the book, as well
as to retrieve the book's title and author. Use appropriate access modifiers to encapsulate the
data properly.
Solution
class LibraryBook
{
private string title;
private string author;
private bool available;