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

Lab Session 4: Classes and Objects: Student Name: Maryam Raza Depart: BSCS Section A

The document provides instructions for 4 exercises in a lab session on classes and objects in C#. The first exercise involves creating an Employee class with attributes like name, ID, department, etc and methods to print the employee information. The second asks to create a Box class with width, height, depth attributes and a method to calculate volume. The third involves creating a Student class with attributes like name, department, marks etc and methods related to calculating total, percentage and grade. The fourth exercise is about creating a SavingsAccount class with a static interest rate and method to calculate monthly interest and update balances.

Uploaded by

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

Lab Session 4: Classes and Objects: Student Name: Maryam Raza Depart: BSCS Section A

The document provides instructions for 4 exercises in a lab session on classes and objects in C#. The first exercise involves creating an Employee class with attributes like name, ID, department, etc and methods to print the employee information. The second asks to create a Box class with width, height, depth attributes and a method to calculate volume. The third involves creating a Student class with attributes like name, department, marks etc and methods related to calculating total, percentage and grade. The fourth exercise is about creating a SavingsAccount class with a static interest rate and method to calculate monthly interest and update balances.

Uploaded by

maryam raza
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Lab Session 4: Classes and Objects

Student Name: Maryam Raza

Depart: BSCS Section A

Exercises
1. Write a class Employee having data members to store the following
information: Name, Father’s

Name, CNIC, Department, Salary and Designation. Write a method void printInfo()
that prints

all information of the employee. Also write a class to test all methods of
Employee class.
2. Write a class Box having data members to store the following information:
Width, Height and Depth

and method to store the volume of a box using formula (width*height*depth).

 Create two objects myBox1 and myBox2 for the above class.
 Print values of width, depth and height for each object.
 Calculate volume for both objects.
3. Write a class Student having attributes to store the following data: Name,
Fathers’ Name,

Department, Degree, Enrolment, Seat number, and Marks of three subjects. Add
the following

methods in the above class.

 int getTotal() : This methods returns the total of marks


 void printTotal() Prints the total marks of Student
 float getPercentage() this method calculates the percentage of a student
 void printPercentatge() this method prints the percentage of student
 char getGrade() this method calculates and returns the grade.
 void printGrade() this method prints the grade of a student.
 void printInfo() This method prints all information of the student.

Also write a class to test all methods of Student class.


4. Create class SavingsAccount. Use a static variable annualInterestRate (type
double) to store the

annual interest rate for all account holders. The class also contains an instance
variable

savingsBalance indicating the amount the saver currently has on deposit. Provide
method

calculateMonthlyInterest() to calculate the monthly interest by multiplying the


savingsBalance by

annualInterestRate divided by 12, this interest should be added to


savingsBalance. Provide a static

method modifyInterestRate() that sets the annualInterestRate to a new value.

Write another class TestSavingsAccount that instantiates two savingsAccount


objects, saver1 and

saver2, with balances of Rs. 20,000.00/- and Rs. 300,000.00/- respectively. Set
annualInterestRate

to 4%, then calculate the monthly interest and print the new balances for both
savers. Then set the

annualInterestRate to 5%, calculate the next month’s interest and print the new
balances for both

savers.

Add more methods in SavingsAccount class if needed.

You might also like