Pages

Wednesday, July 31, 2013

C Vs LISP

C



printf("Enter the Limit");
scanf("%d",&n);
printf("Enter the numbers");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
.
.
.
.
.
for(i=0;i<n;i++)
printf("Array is %d",a[i]);




LISP



(defun main()

(print "Enter the Limit")

(setf  l(read))

(setf  ar ( make-array l))

(print "Enter the Elements")

(dotimes (i l)

(setf  (aref ar i)(read)))

(dotimes (i l)

(print (aref ar i))

)
)

Array Reading and Printing Using LISP

(defun main()

(print "Enter the Limit")

(setf  l(read))

(setf  ar ( make-array l))

(print "Enter the Elements")

(dotimes (i l)

(setf  (aref ar i)(read)))

(dotimes (i l)

(print (aref ar i))

)
)

Tuesday, July 30, 2013

Quick sort Using LISP - Main part....


Main Part:

(defun main()

(print "Enter the Limit")

(setf  l(read))

(setf  ar ( make-array l))

(print "Enter the Elements")

(dotimes (i l)

(setf  (aref ar i)(read)))

(qsort  0(- l 1)

(dotimes (i l)

(print (aref ar i))

)
)



Note:

1)The general function for extracting the element of any array is aref.
(aref array index1 index2 ...)
eg:-  
(aref ar i)

2)A multidimensional array is created as follows:
(make-array  dimension-list)
eg:-
( make-array l)

(setf  ar ( make-array l))

3)To set the value of an element in an array you say
(setf (aref array indices...) val) 

(setf variable-symbol expression) 
Evaluates expression, and stores its value in the variable associated with variable-symbol. Then it returns the value of expression.

4)Repeatedly evaluates its arguments. One example is dotimes. This macro is an iterator (a looping control structure). Like most iterators in Lisp, dotimes requires a variable. 
Here's the format:

(dotimes (var high-val optional-return-val) expr1 expr2 ...)
eg:-
(dotimes (x 4 "yo") (print "hello"))

5) Functions are created by calling a function-making macro. This macro is called defun.
A simple version of defuntakes the following general form:

(defun function-name-symbol (param1 param2 param3 ...) expr1 expr2 expr3 ...)
eg:-
>(defun do-hello-world ( )

"Hello, World!"
)

>(do-hello-world) 

Lisp Tutorials-Author(http://cs.gmu.edu/~sean/)

All contents from this article.....copied from "http://cs.gmu.edu/~sean/"






Lisp 1

Lisp 2

Lisp 3

LISP Study HUT

1) Lisp Tutorial Click
2) Lisp II Click
3) Lisp III Click

LISP

Example:

(defun double (x) (* x 2))              



GCL-window:

Quick Sort

Note from IITM NPTEL note



&





LISP in Windows

GCL




STEPs :

After Downloading:

1) Go to Download-Page
2) Right Click->Pin to start-menu
3) Type (HELP)
4) Type your program
5) (trace function-name)
6) (function-name argument)
7) Ctrl+c to QUIT   OR (bye)

LISP Rules

1) The notation followed should be prefix notation.

2) All operators must be within parenthesis.

3) The order of operations must be clarified using parenthesis.

4) A space must appear between operators and operands.

LISP

-List Processing.
-Typeless Language.
-LISTs is denoted using parenthesized collection of  sublists.
-Only ATOMs and LISTs

-Atoms as ( A B ( D E ) F )

Sunday, July 21, 2013

Viva Questions

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */

1) Abstraction with example ?
2) Encapsulation with example?
3) Polymorphism with example?
4) Class and example?
5)Object and example?
6)Advantages of inheritance?
7)Inheritance with example?
8)Difference between structure and class?
9)What is scope resolution operator and what is the notation of that?
10)Syntax for a class?
11)Syntax for creating and object?
12)How to call membership function from outside of a class?
13)What is access specifier and what they are??
14)Syntax for calling an object?
15)Syntax for a derived class?
16)What are the types of polymorphism?
17)Which of them are in compile-time polymorphism?
18)which of them are in run-time polymorphism?
19)What is binary operator and give example?
20)what is binary operator overloading?
21)Syntax for operator overloading?
22)What is unary operator  and give example?
23)What is unary operator overloading?
24)What is a virtual function?
25)What is pure virtual function?
26)Syntax for declaring pure virtual function & virtual function?

Will continue..................


Overriding method example

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */

#include <iostream.h>
#include<conio.h>
class arithmetic
{
  protected:
    int a, b, sum, sub;
  public:
    void values (int x, int y)
      {
a=x, b=y;
      }
    virtual int operations ()
      {
sum= a + b;
cout<< "Addition = "<< sum<<"\n";

      }
};

class Subtract: public arithmetic
{
  public:
    int operations ()
      {
sub= a - b;
cout<< "Difference = "<<sub <<"\n";
      }
};                        


int main()
{                      
    clrscr();
    arithmetic *arith;
   
Subtract subt;
    arithmetic ar;
 
    arith=&ar;
    arith->values(30,12);
    arith->operations();

    arith=&subt;
    arith->values(42,5);
    arith->operations();

getch();
return 0;
}

Operator overloading

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */

#include <iostream.h>
#include<conio.h>

int add(int a, int b, int c)
{
   return(a + b + c);
}

float add(float d, float e)
{
   return (d + e);
}

int main()
{          clrscr();
int add(int, int, int);
float add(float, float);
int a,b,c;
float d,e,sum;

   cout << "Enter three integers\n";
   cin >> a >> b >>c;
   sum = add(a, b, c);
   cout << "Sum of integers is " << sum << "\n";

   cout << "Enter two floating point numbers\n";
   cin >> d >> e;
   sum = add(d, e);
   cout << "Sum of floating point numbers is " << sum << "\n";
   getch();
   return 0;

}

Pure Virtual Function

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */
/* Pure Virtual Function */
#include<iostream.h>
#include<conio.h>
class B
{
public:
virtual void show()=0;
};
class D1:public B
{
public:
void show()
{
cout<<"D1"<<"\n";
}
};
class D2:public B
{
public:
void show()
{
cout<<"D2";
}
};
void main()
{
clrscr();
B *p;
//B base1;
D1 der1;
D2 der2;
//B base1;

//p=&base1;
//p->show();

p=&der1;
p->show();

p=&der2;
p->show();

getch();
}

Without "Virtual" Keyword......what are the outputs??

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */
/* Without Virtual Function */
/* Created a pointer in BaseClass B*/
#include<iostream.h>
#include<conio.h>
class B
{
public:
void show()
{
cout<<"B"<<"\n";
}
};
class D1:public B
{
public:
void show()
{
cout<<"D1"<<"\n";
}
};
class D2:public B
{
public:
void show()
{
cout<<"D2";
}
};
void main()
{
clrscr();
B *p;
B base1;
D1 der1;
D2 der2;

p=&base1;
p->show();

p=&der1;
p->show();

p=&der2;
p->show();

getch();
}

Virtual Function using C++

/* Programmer: ARUN ANOOP M
   Job Details: Asst.professor,CSE,MESCE */
/* Virtual Function */
#include<iostream.h>
#include<conio.h>
class B
{
public:
virtual void show()               //Vf are used to avoid duplication
{
cout<<"B"<<"\n";
}
};
class D1:public B
{
public:
void show()
{
cout<<"D1"<<"\n";
}
};
class D2:public B
{
public:
void show()
{
cout<<"D2";
}
};
void main()
{
clrscr();
B *p;
B base1;
D1 der1;
D2 der2;

p=&base1;
p->show();

p=&der1;
p->show();

p=&der2;
p->show();

getch();
}