Professional Documents
Culture Documents
Final Practical File-Grade 12 2
Final Practical File-Grade 12 2
BANNERGHATTA
2023-24
PRACTICAL FILE
(Subject-Computer Science)
7-stop
OUTPUT FOR THE ABOVE PROGRAM-
VDT TABLE
Variable method Description
Sb.append(str) Appends the string
Sb.insert(index,str) Inserts the string at
specified index
PROGRAM:- 2-
STRING BUFFER PROFRAM USING THE FUNCTION
APPEND
1-initialize a StringBuffer object to create a mutable character sequence.
7-stop
VDT TABLE
Variable method Description
Sb.append(str) Appends the string
Sb.insert(index,str) Inserts the string at
specified index
PROGRAM:- 3-
USING STRINGBUFFER PROGRAM:- USING INSERT
FUNCTION
PROGRAM:-- 4
PROGRAM:- TO USE RECCURSION PROGRAM:-
USING THE CONCEPT OF TOWER OF HANOI
PROGRAM:--
OUTPUT FOR THE ABOVE PROGRAM-
VDT TABLE-
VARIABLE METHOD DESCRIPTION
Main method Where the tower of
Hanoi problem is
initiated
String destination The name of destination
peg
Int nt The array
PROGRAM:- 5
1. Define a base class employee with fields ( name) and methods and ).
2. Create a derived class Dog that inherits from Animal. The Dog class adds a new
method
3. In the employee constructor, use super(name) to call the constructor of the
superclass employee and initialize the name field.
4. In the main method, create objects of both the base and derived classes
employee
5. Use methods from both the base and derived classes on their respective
objects. This demonstrates how the derived class inherits the methods and
fields from the base class and can also have its own specialized methods.
OUTPUT FOR THE ABOVE PROGRAM-
PROGRAM:- 7
WRITE A PROGRAM:- USING THE CLASS
NAME OF SALARY AND USING THE
FUNCTION OF INHERTICANCE
Define a base class Employee with fields ( name and baseSalary) and a method
calculateSalary() that calculates the salary based on the base salary.
1. Create a derived class Manager that inherits from Employee. The Manager class
adds a new field bonus and overrides the calculateSalary() method to include the
bonus.
2. In the Manager constructor, use super(name, baseSalary) to call the constructor of
the superclass ( Employee) and initialize the name and base salary fields.
3. In the main method, create objects of both the base and derived classes
(employee and manager).
4. Calculate and print the salaries for both employees using their respective
calculateSalary() methods. This demonstrates how the derived class can override
methods from the base class to provide specialized behavior.
VDT TABLE
Variable method Description
Sb.append(str) Appends the string
Sb.insert(index,str) Inserts the string at
specified index
->PROGRAM:- 10-
Write a PROGRAM:- using recursive
function and display the OUTPUT FOR THE
ABOVE PROGRAM
description
Variable method
Recursive case Calls the function
itself
If condition A condition that
checks wheather the
problem can be
solved directly
->PROGRAM:- 11
VDT TABLE-
->PROGRAM:- 12
WRITE A PROGRAM:- USING THE CONCEPT OF
POLYMORPHISM
->OUTPUT FOR THE ABOVE PROGRAM
VDT TABLE-
Variable method description
myAnimal=new cat() Assigning an instance
of a different subclass
to the same
reference
Class animal A reference variable
of the superclass type
that can hold objects
of the superclass
->PROGRAM:- 13
->Write a PROGRAM:- using function
overloading
1. These methods are overloaded because they have the same name ( add) but
different parameter lists.
2. In the main method, we create an instance of the Calculator class and call each
version of the add method with different argument types.
->OUTPUT FOR THE ABOVE PROGRAM-
VDT TABLE-
Variable method description
Int x An integer parameter
for one version of the
mymethod method
Double y A double parameter
for another version of
the “mymethod”
method
String s A string parameter
for yet another
version of mymethod
PROGRAM:- 14-
->WRITE A PROGRAM:- USING FUNCTION
OVEERIDING
OUTPUT FOR THE ABOVE PROGRAM-
VDT TABLE
PROGRAM:- 15
Algorithm
PROGRAM:--
VDT TABLE
PROGRAM:- 16-
Algorithm
VDT TABLE-
PROGRAM:- 17: Arrays
Algorithm:
cssCopy code
1 . Initialize a variable sum to 0 . 2 . Iterate through each element of the array. a . Add the current element to
the sum. 3 . Print the sum.
Variable Description
PROGRAM:-18 : Inheritance
Description: Create a base class Shape and derive two classes Circle and Rectangle
from it. Implement inheritance concepts.
Algorithm:
sqlCopy code
1. Define the base class Shape with properties and methods. 2. Create the Circle class inheriting from
Shape. 3. Create the Rectangle class inheriting from Shape. 4. Implement methods in the derived classes. 5.
Create objects of both derived classes and demonstrate inheritance.
Algorithm:
kotlinCopy code
1. Define a base class with a method . 2. Create derived classes that override the method. 3. Demonstrate
polymorphism by calling the method on objects of derived classes.
Algorithm:
cssCopy code
1 . Initialize an array to hold stack elements and a variable top to track the top element. 2 . Implement push
and pop operations using array manipulation. 3 . Perform various stack operations (push, pop, peek).
vatiable description
stack Array to hold stack
data
top Index of the top
element