CPPL Practical
CPPL Practical
#include<iostream>
class staff
string name;
int empId;
string pos;
cin>>name;
cin>>empId;
cin>>pos;
void display()
};
{};
int main()
typist t1;
t1.getdata();
t1.display();
return 0;
#include<iostream>
class Area{
public: int getArea(int l, int b){
return l*b;
};
class Perimeter{
return 2*(l+b);
};
int len;
int bth;
public: Rect(){
len=8;
bth=10;
int area(){
int perim(){
return Perimeter::getPerim(len,bth);
};
int main(){
Rect r;
return 0;
class Employee {
System.out.println("Hello");
#include<iostream>
#include<string>
class Strings{
getline(cin,input);
void reverse(){
int len=input.length();
for(int i=len-1;i>=0;i--){
cout<<input[i];
cout<<endl;
};
reverse();
};
int main(){
Reverse r;
r.getInput();
r.displayRev();
return 0;
}
String name;
int age;
name = xname;
String getname() {
return name;
age = xage;
int getage() {
return age;
System.out.println("Hello World");
b1.setname("John ");
b1.setage(19);
b2.setname("Lucy");
b2.setage(34);
void action() {
System.out.println("This is a dog");
void sound() {
System.out.println("Animal barks");
System.out.println("Hello");
d.sound();
d.action();
d.atype();
import java.util.Scanner;
double len;
double bth;
double rad;
double side;
}
public class Koala {
a.len = sc.nextDouble();
a.bth = sc.nextDouble();
System.out.println("\n");
b.rad = sc.nextDouble();
System.out.println("\n");
c.side = sc.nextDouble();
sc.close();
main :: IO()
main :: IO()
main = do
let num1 = 36
let num2 = 25
div1::Double->Double->Double b1<-getLine
exp1::Int->Int->Int print(add1 a b)
mod1::Int->Int->Int print(mult1 a b)
main=do print(mod1 a b
11) APPLY TWICE, MULT THREE AND APPLY STRING USING HASKELL
facto::Int->Int revString::String->String
main=do main=do
print(facto 5) print(revString"bunny")
divide::Double->Double
divide x=x/10.0
main::IO()
main=do
let num=500
triangle::Double->Double->Double
triangle b h=0.5*b*h
circle::Double->Double
circle r=pi*r^2
main::IO()
main=do
let b=5.0
let h=4.0
let r=6.0
doublePass::[Int]->[Int] spaces::Int->String
main=do main=do
triples::Int->[(Int,Int,Int)]
triples n=[(x,y,z) | x <-[1..n],y <- [1..n], z <- [1..n], x^2 + y^2 == z^2]
main=do
print(triples 10)
facts::Int->[Int]
main = do
print(facts 20)
nums::[Int] fibs::[Integer]
main::IO() main::IO()
main=do main=do
Save knowledge in knowledge base or file and continue with queries on prolog prompt.
and1(true,true):-true.
?- and1(true,true).
true
list_concat( [] , L ,L).
subset(L, L).
subset1([Head|Tail],[Head|R]):-subset1(Tail,R).
factorial(1,1).
factorial(N,Res):-M is N-1,
factorial(M,NextRes),Res is NextRes*N.
23) FIBONACCI SERIES IN PROLOG
fibo(0,0).
fibo(1,1).
fibo(N1,Res1),fibo(N2,Res2),
Res is Res1+Res2.
fibonacci(N):-between(0,N,I),fibo(I,Res),
fibonacci(_).
sum (0,0).
sum (N, S):-( N > 0 ->( N1 is N-1, sum( N1, S1), S is N+S1);
Directly give commands without creating file :assert, asserta, assertz, retract commands
?- Animal(X).
fido;
juno.
System.out.println("Welcome to SFIT");
System.out.println("Welcome to INFT");
System.out.println("Hello World");
d2.start();
System.out.println("Hello World");
t1.start();
import java.util.*;
int n = sc.nextInt();
x.start();
sc.close();
#include<thread>
void fnc1(){
cout<<"Thread 1 is running\n"<<endl;
void fnc2(){
cout<<"Thread 2 is running"<<endl;
int main(){
cout<<"Hello World"<<endl;
thread t1(fnc1);
t1.join();
thread t2(fnc2);
t2.join();
return 0;
#include<iostream>
#include<thread>
void fnc1(){
cout<<"Thread 1 is running"<<endl;
void fnc2(){
cout<<"Thread 2 is running"<<endl;
int main(){
cout<<"Hello World"<<endl;
thread t1(fnc1);
thread t2(fnc2);
thread::id x=t1.get_id();
thread::id y=t2.get_id();
t1.join();
t2.join();
return 0;
}
31) THREAD SYNCHRONIZATION IN JAVA
t1.start();
t2.start();
class Table {
try {
Thread.sleep(500);
} catch (Exception e) {
System.out.println(e);
Table t;
Mythread1(Table T1) {
this.t = T1;
t.print(4);
Table t;
Mythread2(Table T2) {
this.t = T2;
t.print(13);
} }
32) EXCEPTION HANDLING USING TRY CATCH IN JAVA
try {
} catch (ArithmeticException e) {
try {
return x / y;
} catch (ArithmeticException e) {
throw e;