PCPF Lab Manual-Seit
PCPF Lab Manual-Seit
LAB MANUAL
Academic year (2024-25)
SUB-PCPF
Prepared By
PROF.PRASHALI R KAMBLE
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
LIST OF PRACTICAL
EXPERIMENT NO: 1
Requirements: turbo C
Theory: It is a process of wrapping code and data together into a single unit, for example, a
capsule which is mixed of several medicines.
For example 1: School bag is one of the most real examples of Encapsulation. School bag can keep
our books, pens, etc. Real-time
Example 2: When you log into your email accounts such as Gmail, Yahoo Mail, or Rediff mail,
there is
a lot of internal processes taking place in the backend and you have no control over it.
Code:
#include<iostream.h>
#include<conio.h>
class sum
{
private: int a,b,c;
public: void add()
{
clrscr();
cout<<"enter two numbers" ;
cin>>a>>b;
c=a+b;
cout<<"sum="<<c;
}
};
void main()
{
sum s;
s.add();
getch();
}
output
enter two numbers 5 6
sum= 11
EXPERIMENT NO: 2
Requirements: Turbo C
Theory: It allows us to create a new class (derived class) from an existing class (base class). The
derived class inherits the features from the base class and can have additional features of its
own.
Example1 class Animal { // eat() function // sleep() function };
class Dog : public Animal { // bark() function };
Code:
using namespace std;
class Parent
{p
ublic:
int id_p;
};
class Child : public Parent {
public:
int id_c;
};
int main()
{
Child obj1;
obj1.id_c = 7;
obj1.id_p = 91;
cout << "Child id is: " << obj1.id_c << '\n';
cout << "Parent id is: " << obj1.id_p << '\n';
return 0;
}
output
Child id is: 7
Parent id is: 91
EXPERIMENT NO: 3
TITLE: Initialization and Finalization
Aim: Write a program to initialize the information of a car with the argument passed to
it at
compile time.
Requirements: Turbo C
Objective: Understand data object orientation concept
Theory:
Constructors are used to initialize a value to the variable either at run time or at compile
time.
A constructor is a special type of member function that is called automatically when an
object is created.
A constructor has the same name as that of the class and it does not have a return type.
Types of constructor are 1.Default Constructor 2.Parameterized Constructor 3.Copy
Constructor
Code:
class Car // The class
{
public: // Access specifier
string brand; // Attribute
string model; // Attribute
int year; // Attribute
Car(string x, string y, int z) { // Constructor with parameters
{ brand = x;
model = y;
year = z;
}};
int main()
{
Car Obj1("BMW", "X5", 1999);
Car Obj2("Ford", "Mustang", 1969);
cout << Obj1.brand << " " << Obj1.model << " " <<
Obj1.year << "\n";
cout << Obj2.brand << " " << Obj2.model << " " <<
Obj2.year << "\n";
return 0;
}
output
BMW X5 1999
Ford Mustang 1969
Conclusion: Thus we studied concept of Initialization and Finalization
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
EXPERIMENT NO: 4
TITLE: Haskell
Aim: Write a program to execute operators in Haskell
Outcome: Design and Develop solution using functional and logic programming.
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
EXPERIMENT NO: 5
TITLE: LIST
Requirements: Any text editor to be able to edit Haskell code and Glasgow Haskell Compiler 8.0+
version.
Objective: Design and implement declarative programs in functional and logic programming
languages
Theory: It stores several elements of the same type. That means that we can have a list of
integers or a list of characters but we can't have a list that has a few integers and then a few
characters.
Outcome: Design and Develop solution using functional and logic programming.
1.a. Now u create a list of 5 Float numbers with name x and print its values
1.b. Now u creates a list of 3 chars with name y and print its values
1.c. Now u create a list of 3 Strings with name myname that contain your first name, middle
name and last name and print its values
Prelude> myname=["Anup","Shrikant","Kunte"]
Prelude> myname
["Anup","Shrikant","Kunte"]
CPCL Lab Manual
PHCET- S.E. (IT)Page 2
2. Execute these command and write down output (Learn use of ++ (concatination
operator))
2.a. Prelude>[1,2,3,4] ++ [9,10,11,12]
Output : [1,2,3,4,9,10,11,12]
Output : "what"
3. Learn how to work with cons (:) operator
3.a. Prelude>'A':" SMALL CAT"
Output: [1,4,6]
3.c. Prelude>1:4:6:[]
Output : [1,4,6]
3.d. Prelude>1:4:6
Output: Error
4. Indexing operator (!!) Note output o below commands and answer following:
5. Now we will make a table of basic functions on list you need to fill in missing entries:
Sr. Name Example Output Type signature
EXPERIMENT NO: 6
When we discuss exceptions, we must understand that they are different from Errors.
Errors are
impossible to recover while exceptions are recoverable. Errors only occur at run-time and
are caused bythe Java run time environment, while exceptions can occur at compile time
as well and the cause is the application itself, not the Java compiler.
In Java, exceptions that occur at compile time are called checked exceptions and run-
time exceptionsare called unchecked exceptions.
A basic example of an exception is shown
below:class SampleException{
args[]){try {
catch (Exception e) {
}
}
The code that needs to be executed in case an exception occurs should be placed within the
catch
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
block. In the finally block, you need to put in code that is executed irrespective of whether
an exceptionis thrown or not.
1. try : A try block is where you will put the code that may raise exceptions.
2. catch: The catch block is used to handle a given exception.
3. finally: The keyword ‘finally’ is used to define the code block that must be
executed irrespectiveof the occurrence of an exception.
OUTPUT
Program: using
C++ using
namespace std;
void main()
{
Try
{
//code that may raise
exceptionint data=100/0;
}
catch(ArithmeticException e)
{
cout(e);
}
//rest code of the
programcout("rest of
the code...");
}
Conclusion: Thus we studied Exception handling and Garbage collection using JAVA
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
EXPERIMENT NO: 7
TITLE: Garbage collection
Conclusion: Thus we studied Exception handling and Garbage collection using JAVA
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
EXPERIMENT NO: 8
TITLE: Thread management and synchronization
Theory:
Thread is actually a lightweight process. Multithreading is a specialized form of
multitasking and a
multitasking is the feature that allows your computer to run two or more programs
concurrently. In
general, there are two types of multitasking: process-based and thread-based. A
multithreaded
program contains two or more parts that can run concurrently. Each part of such a
program is called a
thread, and each thread defines a separate path of execution. A multithreaded program
contains two
or more parts that can run concurrently. Each part of such a program is called thread
and each thread
defines a separate path of execution. Thus, multithreading is a specialized form of
multitasking.
Threads exist in several states. Following are those states:
EXPERIMENT NO: 9
EXPERIMENT NO: 10
TITLE: SWI PROLOG
Objective: Design and implement declarative programs in functional and logic programming
language.
Theory: Prolog stands for programming in logic. it is a logic programming language for
artificial intelligence. An artificial intelligence developed in Prolog will examine the link
between a fact, a true statement, and a rule, a conditional statement, in order to come up with
a question, or end objective.
Logic Programming is the name given to a distinctive style of programming.
It is very different from that of conventional programming languages such as C,
C++ and Java.
Prolog is most widely used language.
The name stands for Programming in Logic.
rolog programs are often described as declarative.
There are only two components to any program: facts and rules.
The Prolog system reads in the program and simply stores it.
The user then types in a series of questions, known as queries, which the system
answers using the facts and rules available to it
This is a simple example, a series of queries and answers about animals. The
program consists of just seven lines.
Prolog has been used for a wide variety of applications.
Many of these are in Mathematics and Logic but many are not. Some examples
of the second type of application are:
1. programs for processing a 'natural language' text, to answer questions
about its meaning, translate it to another language etc.
2. advisory systems for legal applications
3. applications for training
4. an electronic support system for doctors
1. Numbers
In Prolog, all versions allow the use of integers. Any sequence of numbers from 0 to
9 is written as numbers. The numbers are preceded by + or - sign.
The use of numbers with decimal points is allowed by most versions of Prolog. Just
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
like the integer, they are written. It contains a single decimal point.
For Example:
278 , -64 , +8 , 057 , 4.32 , -7.91 , +8.45.
2. Atoms
Atoms do not have any numerical value.
Atoms are like the constants.
The atoms can be written in three different ways.
Any sequence of upper case or lower case letters, underscores, numerals,
starting with a lower case letter. For example,
Valid Atoms: jackson , toady_is_Saturday , smart_jack , x64_YZ .
Invalid Atoms: Weekend , Toady-is-Saturday , 64xyz
3. Variable
dog(fido).
dog(rover).
dog(henry).
cat(felix).
cat(michael).
cat(jane).
animal(X):-dog(X).
The first three lines are facts, with the obvious interpretation that fido, rover and
henry are all dogs. The next three facts say that felix, michael and jane are all
cats. The final line is a rule saying that anything (let us call it X) is an animal if it
is a dog.
Having loaded the program, the user is then faced with the two character symbol
?- which is called the system prompt.
Provide the knowledge base to the system
?- dog(fido).
true.
?- animal(felix).
false.
?- animal(rover).
true.
Outcome: Design and Develop solution based on declarative programming paradigm using
functional and logic programming.
EXPERIMENT NO: 11
TITLE: SWI PROLOG
Objective: Design and implement declarative programs in functional and logic programming
language.
Theory:
Prolog stands for programming in logic. it is a logic programming language for artificial
intelligence. An artificial intelligence developed in Prolog will examine the link between a
fact, a true statement, and a rule, a conditional statement, in order to come up with a question,
or end objective.
Unification in Prolog:
Prolog unification has one or more variables given values to make two call terms as identical,
and this process is called binding variables to values. In prolog unification, prolog agrees that
the two terms to unify, i.e., variables unify with anything, and hence they will unify with each
other. The process in which Prolog matched two terms is known as Prolog unification. The
concept is similar to unification logic. This matching process is done from left to right, and it
fails if there is no match found.
Resolution in Prolog:
Prolog resolution is the process of determining whether a rule can be proved. The process
uses unification to match variables and predicates, but the process known as resolution
concerns the depth-first search process for finding variable assignments that satisfy rules (and
the rules they refer recursively).
Operators in Prolog:
1.Arithmatic Operators
In arithmetic expression, + - * / symbols are special type of infix operator, and
these operators are also known as arithmetic operators.
In Prolog, operators are used as predicates but here operators are functions and
these operators return a numerical value.
Arithmetic expressions can include variables, numbers, operators, and
arithmetic functions.
These will be written in parentheses with their arguments.
These will return numerical values just like the arithmetic operators.
Example 1
?- A is 5.7 + 2.9 * 3
A = 14.4
Example 2
?- B is 6, C is B + 2.
B = 6,
C=8
Example 3
SARASWATI EDUCATION SOCIETY
YADAVRAO TASGAONKAR INSTITUTE OF ENGINEERING AND TECHNOLOGY
DR.N.Y.TASGAONKAR TECHNICAL EDUCATION CAMPUS, CHANDHAI AT.POST:-NASARAPUR, TAL: - KARJAT, DIST: - RAIGAD
?- A is sqrt(25).
A=5
Example 4
?- A is 7, B is -A - 3.
A = 7,
B = -10
Example 5
?- A is 30, B is 3, C is A + B + A * B + sin(A).
A = 30,
B = 3,
C = 123.5
Example 6
?- A is 5, A is 4+1.
A = 5.
Example 7
?- A is 5, A is 4+21.
false.
2. Relational Operators
The relational operators are =:=, >, <, >=, =/=, =<.
The relational operators compare the values of two arguments. If the first
argument's value is equal to, greater than, less than, greater than or equal to,
not equal to, less than or equal to the value of second argument, the goal
succeeds.
Both arguments can be arithmetic expression, bound variable or numbers.
Example 1:
?- 60 - 5 + 10 =:= 85 - 10*2.
yes
Example 2:
?- 59<63.
No
Outcome: Design and Develop solution based on declarative programming paradigm using
functional and logic programming.
EXPERIMENT NO: 12
Objective: Design and implement declarative programs in functional and logic programming
language.
Theory:
A list is a collection of items, not necessarily homogeneous. In Prolog, lists are
inbuilt data structures. Lists can be used to represent sets, stacks, queues, linked
lists, and several complex data structures such as trees, graphs, etc.
A list in Prolog is an ordered collection of items denoted as [i1, i2, …, in].
Unlike arrays in other programming languages where we can directly access any
element of the array, prolog lists allow direct access of the first element only which
is denoted as Head. Therefore we can write a prolog list as : [Head | Rest], where
Rest is the rest of the list excluding the first element Head.
Prolog lists allow nonhomogeneous data types of list items.
Nested lists of arbitrary depths are also allowed in prolog.
Pipe (|) operator:
In prolog, lists have got only one operator, called pipe, denoted by |. This operator
is used to append an element at the beginning of a list. The syntax of the pipe
operator is as follows :
[a | L]
Here L is a list and a is a single element.
For example: If, L = [b,c,d]
Then, [a | L] will result in [a,b,c,d]
Operations in List:
list_length([], 0).
list_length([_ | L], N) :-list_length(L, N1),N is N1 + 1.
list_sum([], 0).
list_sum([H | L], N) :-list_sum(L, N1),N is N1 + H.
?- list_sum([1,2,3], N).
N = 6.
?- list_sum([2,3,4], N).
N = 9.
is_member(X, [X | _ ]) :- !.
is_member(X, [ _ | Rest]) :- is_member(X, Rest).
?- is_member(f, [a, b, c, d]).
false.
?- is_member(k, [a, b, c, d]).
false.
?- is_member(d, [a, b, c, d]).
True
Outcome: Design and Develop solution based on declarative programming paradigm using
functional and logic programming.