├── README.md ├── prolog ├── factorial.pl ├── fibo.pl ├── quadratic.pl ├── areaequitri.pl ├── sincos.pl └── areaofisoceles.pl ├── haskell ├── mapf.hs ├── quadraticequation.hs ├── evennumber.hs ├── fibolist.hs ├── fibonacci.hs ├── sumofnnumbers.hs ├── sumlist.hs ├── lengthlist.hs ├── multlist.hs ├── repeathigherorder.hs ├── squarelist.hs ├── arithmetic.hs ├── factorial.hs ├── prodlist.hs ├── merge_sort.hs └── areaofpolygons.hs ├── java ├── exception.java └── threads.java ├── c ├── samenamedifftype.c ├── callbyvalueandreference.c └── globalandlocalvar.c └── cpp ├── exception.cpp ├── polymorphism.cpp ├── finalization.cpp ├── encap.cpp ├── callbyvalueandreference.cpp ├── singleinheritance.cpp └── dynamicbinding.cpp /README.md: -------------------------------------------------------------------------------- 1 | # PCPF || CPPL 2 | pcpf codes sem 3 3 | c,c++,java,haskell and prolog 4 | -------------------------------------------------------------------------------- /prolog/factorial.pl: -------------------------------------------------------------------------------- 1 | fact(0,1). 2 | fact(N,F):-X is N-1, 3 | fact(X,V), 4 | F is N*V. 5 | -------------------------------------------------------------------------------- /prolog/fibo.pl: -------------------------------------------------------------------------------- 1 | fibo(0,0). 2 | fibo(1,1). 3 | fibo(N,F):-N>1,X is N-1,Y is N-2,fibo(X,A),fibo(Y,B),F is A+B. 4 | -------------------------------------------------------------------------------- /prolog/quadratic.pl: -------------------------------------------------------------------------------- 1 | start:- write('X= '),read(X), 2 | S is X*X+4*X-5, 3 | write(S). 4 | 5 | ?-start. 6 | X=2. 7 | 7. 8 | -------------------------------------------------------------------------------- /haskell/mapf.hs: -------------------------------------------------------------------------------- 1 | -- higher order function in haskell 2 | mapf::(a->b)->[a]->[b] 3 | mapf f xs=[f x | x <-xs] 4 | main = do 5 | print(mapf (*2)[1,4,6]) 6 | print(mapf (+2)[1,4,6]) 7 | 8 | -------------------------------------------------------------------------------- /haskell/quadraticequation.hs: -------------------------------------------------------------------------------- 1 | -- compute x^2+4x-5 2 | main = do 3 | putStrLn"Enter the value of x" 4 | ain<- getLine 5 | let a=(read ain:: Float) 6 | let c=a*a+4*a-5 7 | print(c) 8 | 9 | -------------------------------------------------------------------------------- /prolog/areaequitri.pl: -------------------------------------------------------------------------------- 1 | area:- 2 | write('Enter the length of side of equilateral triangle:'), 3 | read(Lside), 4 | write('The area of the triangle is :'), 5 | A is (sqrt(3)*Lside*Lside/4), 6 | write(A). 7 | -------------------------------------------------------------------------------- /haskell/evennumber.hs: -------------------------------------------------------------------------------- 1 | isEven:: Int-> Bool 2 | isEven x|x `mod`2==0=True 3 | |otherwise =False 4 | main = do 5 | putStrLn"Enter a number" 6 | ain <- getLine 7 | let a = (read ain::Int) 8 | print(isEven a) 9 | -------------------------------------------------------------------------------- /haskell/fibolist.hs: -------------------------------------------------------------------------------- 1 | fibo :: Int -> Int 2 | fibo 0 = 0 3 | fibo 1 = 1 4 | fibo x = fibo(x-1) + fibo(x-2) 5 | 6 | fiboList x = map fibo[1..x] 7 | 8 | main = do 9 | putStrLn("Enter a number: ") 10 | x <- readLn 11 | print(fiboList x) 12 | -------------------------------------------------------------------------------- /prolog/sincos.pl: -------------------------------------------------------------------------------- 1 | calc:- 2 | write("Enter the angle in radians"),nl, 3 | read(X), 4 | Y is cos(X), 5 | Z is sin(X), 6 | write("The cos of the angle is:"),nl, 7 | write(Y),nl, 8 | write("The sin of the angle is:"),nl, 9 | write(Z). 10 | -------------------------------------------------------------------------------- /haskell/fibonacci.hs: -------------------------------------------------------------------------------- 1 | -- fibonacci 2 | fibo::Int->Int 3 | fibo n|n==0=0 4 | fibo n|n==1=1 5 | fibo n|n/=0&&n/=1=fibo(n-1)+fibo(n-2) 6 | 7 | main = do 8 | putStrLn("Enter a number") 9 | nin<- getLine 10 | let n=(read nin :: Int) 11 | print(fibo n) 12 | -------------------------------------------------------------------------------- /haskell/sumofnnumbers.hs: -------------------------------------------------------------------------------- 1 | -- Sum of n natural numbers 2 | fun::Int->Int 3 | fun n|n==0=0 4 | fun n|n/=0=n+fun(n-1) 5 | 6 | main = do 7 | putStrLn("Enter a number") 8 | nin<- getLine 9 | let n=(read nin :: Int) 10 | putStrLn("The sum of natural numbers is") 11 | print(fun n) 12 | -------------------------------------------------------------------------------- /java/exception.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class ExceptionH{ 4 | public static void main(String[] args){ 5 | int a=10; 6 | int b=0; 7 | try{ 8 | int c= a/b; 9 | System.out.println("The answer of the division is: "+c); 10 | } 11 | catch (Exception e){ 12 | System.out.println(e); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /prolog/areaofisoceles.pl: -------------------------------------------------------------------------------- 1 | area:- 2 | write('Enter the length of 1st side of isoceles triangle:'), 3 | read(S1), 4 | write('Enter the length of the equal sides of isoceles triangle:'), 5 | read(S2), 6 | write('The area of the triangle is :'), 7 | S is (S1+S1+S2)/2, 8 | A is (sqrt(S*(S-S1)*(S-S2)*(S-S2))), 9 | write(A). 10 | -------------------------------------------------------------------------------- /c/samenamedifftype.c: -------------------------------------------------------------------------------- 1 | #include 2 | char a='p'; 3 | void f1(){ 4 | int a = 100; 5 | printf("\nThe value of integer a in f2 is %d\n\n",a); 6 | } 7 | void main(){ 8 | printf("\nThe value of character a at entry in main is %c\n",a); 9 | a = 'q'; 10 | f1(); 11 | printf("The value of character a after modification in main is %c\n",a); 12 | } 13 | -------------------------------------------------------------------------------- /cpp/exception.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int a=10,b=0; 7 | try { 8 | if (b > 0) { 9 | cout << "\n Division is possible, it is "< 2 | using namespace std; 3 | class Calc{ 4 | public: 5 | Calc(){} 6 | int Add(int a,int b){ 7 | return (a+b); 8 | } 9 | int Add(int a,int b, int c){ 10 | return (a+b+c); 11 | } 12 | }; 13 | int main(){ 14 | Calc a; 15 | cout<<"Addition of 10 and 20 is "<a)->a->a 4 | repeat f x=f(f x) 5 | square x=x*x 6 | double x=x*2 7 | half x=x/2 8 | main=do 9 | putStrLn"Enter a number to repeat square,double and half" 10 | ain<-getLine 11 | let a=(read ain::Float) 12 | print(Main.repeat square a) 13 | print(Main.repeat double a) 14 | print(Main.repeat half a) 15 | 16 | -------------------------------------------------------------------------------- /haskell/squarelist.hs: -------------------------------------------------------------------------------- 1 | square[]=[] 2 | square (x:xs) =[x*x] ++square(xs) 3 | main = do 4 | putStrLn"Enter 1st element of the list:" 5 | ain<-getLine 6 | let a=(read ain :: Int) 7 | putStrLn"Enter 2nd element of the list:" 8 | bin<-getLine 9 | let b=(read bin :: Int) 10 | putStrLn"Enter 3rd element of the list:" 11 | cin<-getLine 12 | let c=(read cin :: Int) 13 | let list1=[a,b,c] 14 | print(square list1) 15 | -------------------------------------------------------------------------------- /cpp/finalization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | class regpoly{ 4 | private: 5 | int nside; 6 | protected: 7 | int lside; 8 | public: 9 | regpoly(){}; 10 | regpoly(int n,int l){ 11 | nside=n; 12 | lside=l; 13 | } 14 | void show(){ 15 | cout<<"\nA regular polygon has "< dataTypeReturned 4 | fact::Int -> Int 5 | -- first exit conditon 6 | fact n|n==0=1 7 | -- function variable |(binding) if n==0 then return 1 8 | fact n|n/=0=n*fact(n-1) 9 | -- if n is not equal to 0 then return n*fact(n-1) 10 | main = do 11 | putStrLn("Enter a number") 12 | nin <- getLine 13 | let n = (read nin :: Int) 14 | putStrLn("Factorial of the number is ") 15 | print(fact n) 16 | -------------------------------------------------------------------------------- /c/callbyvalueandreference.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | // call by value 4 | void swap(int x,int y){ 5 | int f; 6 | f=x; 7 | x=y; 8 | y=f; 9 | printf("x=%d y=%d\n",x,y); 10 | } 11 | // call by reference 12 | void swapx(int *x,int *y){ 13 | int t; 14 | t=*x; 15 | *x=*y; 16 | *y=t; 17 | printf("x=%d y=%d\n",*x,*y); 18 | } 19 | int main(){ 20 | int a=5,b=10; 21 | swap(a,b); 22 | printf("a = %d,b=%d \n",a,b); 23 | int d=20,e=30; 24 | swapx(&d,&e); 25 | printf("a=%d b=%d\n",d,e); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /cpp/encap.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | class regpoly { 3 | private: int nsides; 4 | protected: int lside; 5 | public: regpoly(int n, int l) // Declaration and Definition of Parameterised constructor 6 | { 7 | nsides = n; lside = l; 8 | } void show() // Declaration and Definition of method 9 | { 10 | std::cout << "The regular polygon has " < 2 | using namespace std; 3 | void swap(int x,int y){ 4 | int temp; 5 | temp=x; 6 | x=y; 7 | y=temp; 8 | cout<<"the value of x is "< 2 | using namespace std; 3 | class regpoly{ 4 | private: 5 | int nside; 6 | protected: 7 | int lside; 8 | public: 9 | regpoly(){}; 10 | regpoly(int n,int l){ 11 | nside=n; 12 | lside=l; 13 | } 14 | virtual void show(){ 15 | cout<<"\nA regular polygon has "<show(); 40 | e= new equitri(3); 41 | e->show(); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /c/globalandlocalvar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | extern char c='z'; 4 | char a='p'; 5 | void fun1(){ 6 | printf("\n value of a at entry in function 1 is: %c",a); 7 | a='r'; 8 | printf("\n value of a at exiting function 1 is: %c",a); 9 | } 10 | void fun2(){ 11 | char b='j'; 12 | int i; 13 | printf("\n value of b at entry in function 2 is: %c",b); 14 | b='k'; 15 | for(i=1;i<3;i++){ 16 | char d=b++; 17 | printf("\n value of d after modification in function 2 is: %c",d); 18 | } 19 | printf("\n value of b after modification in function 2 is: %c",b); 20 | } 21 | void main(){ 22 | printf("\n value of c at entry in main is %c",c); 23 | printf("\n value of a at entry in main is %c",a); 24 | c='y'; 25 | a='q'; 26 | fun1(); 27 | fun2(); 28 | printf("\n value of c after modification in main is %c",c); 29 | printf("\n value of a after modification in main is %c",a); 30 | } 31 | -------------------------------------------------------------------------------- /haskell/prodlist.hs: -------------------------------------------------------------------------------- 1 | prod:: [Int]->[Int]->[Int] 2 | prod(n:ns)(m:ms)= [n*m] ++prod ns ms 3 | prod [] []=[] 4 | main = do 5 | putStrLn"For the first List" 6 | putStrLn"Enter 1st element of the list:" 7 | ain<-getLine 8 | let a=(read ain :: Int) 9 | putStrLn"Enter 2nd element of the list:" 10 | bin<-getLine 11 | let b=(read bin :: Int) 12 | putStrLn"Enter 3rd element of the list:" 13 | cin<-getLine 14 | let c=(read cin :: Int) 15 | let list1=[a,b,c] 16 | putStrLn"For the second List" 17 | putStrLn"Enter 1st element of the list:" 18 | din<-getLine 19 | let d=(read din :: Int) 20 | putStrLn"Enter 2nd element of the list:" 21 | ein<-getLine 22 | let e=(read ein :: Int) 23 | putStrLn"Enter 3rd element of the list:" 24 | fin<-getLine 25 | let f=(read fin :: Int) 26 | let list2=[d,e,f] 27 | putStrLn"The product of the two lists is:" 28 | print(prod list1 list2) 29 | -------------------------------------------------------------------------------- /haskell/merge_sort.hs: -------------------------------------------------------------------------------- 1 | mergeList [] [] z =reverse z 2 | mergeList (x:xs) [] z= mergeList xs [] (x:z) 3 | mergeList [] (y:ys) z= mergeList [] ys (y:z) 4 | mergeList(x:xs)(y:ys)z=if x <= y then mergeList xs (y:ys) (x:z) else mergeList (x:xs) ys (y:z) 5 | 6 | main = do 7 | putStrLn("first list") 8 | putStrLn ("Enter first number: ") 9 | ain <- getLine 10 | let a = (read ain :: Int) 11 | putStrLn ("Enter second number: ") 12 | bin <- getLine 13 | let b = (read bin :: Int) 14 | putStrLn ("Enter third number: ") 15 | cin <- getLine 16 | let c = (read cin :: Int) 17 | putStrLn ("Second List") 18 | putStrLn ("Enter first number: ") 19 | din <- getLine 20 | let d = (read din :: Int) 21 | putStrLn ("Enter second number: ") 22 | ein <- getLine 23 | let e = (read ein :: Int) 24 | putStrLn ("Enter third number: ") 25 | fin <- getLine 26 | let f = (read fin :: Int) 27 | let list1 = [a,b,c] 28 | let list2 = [d,e,f] 29 | print(mergeList list1 list2 []) 30 | -------------------------------------------------------------------------------- /haskell/areaofpolygons.hs: -------------------------------------------------------------------------------- 1 | --area of triangle 2 | main = do 3 | putStrLn("Enter magnitude of 3 sides of triangle") 4 | ain <- getLine 5 | let a = (read ain :: Float) 6 | bin <- getLine 7 | let b = (read bin :: Float) 8 | cin <- getLine 9 | let c = (read cin :: Float) 10 | -- int doesnt work 11 | let s =(a+b+c)/2 12 | let area= sqrt(s*(s-a)*(s-b)*(s-c)) 13 | putStrLn("The area of triangle is ") 14 | print(area) 15 | 16 | -- area of square 17 | main = do 18 | putStrLn("Enter magnitude of side of square") 19 | ain <- getLine 20 | let a = (read ain :: Float) 21 | let area= a*a 22 | putStrLn("The area of square is ") 23 | print(area) 24 | 25 | -- perimeter of rectangle 26 | main = do 27 | putStrLn("Enter magnitude of length and breadth of rectangle") 28 | lin <- getLine 29 | let l = (read lin :: Float) 30 | bin <- getLine 31 | let b = (read bin :: Float) 32 | let peri= 2*(l+b) 33 | putStrLn("The perimeter of rectangle is ") 34 | print(peri) 35 | 36 | -- volume of sphere 37 | main = do 38 | putStrLn("Enter radius of sphere") 39 | rin <- getLine 40 | let r = (read rin :: Float) 41 | let vol= (4*pi*r*r*r)/3 42 | putStrLn("The volume of sphere is ") 43 | print(vol) 44 | --------------------------------------------------------------------------------