1a
AIM:
To Write a C++ Program using Call by Reference, Call by Value and Call by Address.
OBJECTIVE:
THEORY:
Calling the function by passing the value as an argument is known as call by value. Calling
the function by passing the address of the variable as an argument is known as call by address.
Calling the function by using the reference of the variable is known as call by reference.
ALGORITHM:
20
: 20
10
: 10
20
: 20
10
RESULT:
Thus a C++ program for illustration of Call by Reference, Call by Value and Call by
Address has been executed successfully.
Viva Questions:
ACET/ECE/DSOOPS/2013-14
Ex No. 1b
AIM:
ALGORITHM:
4.
5.
6.
7.
OUTPUT:
MARKLIST
ACET/ECE/DSOOPS/2013-14
M1
M2
M3
1001
Vijay
78
90
89
257
85
1002
Raju
67
70
68
215
68
RESULT:
Thus a C++ program for classes and objects mark list preparation has been executed
successfully.
Viva Questions:
1.What is meant by array?
2. List the types of arrays.
3. How will you initialize three dimensional arrays?
4. Is it possible to store string values to an array?
5. Is it possible to create array of objects in C++?
Ex No. 1c
OPERATOR OVERLOADING
AIM:
To write a C++ program for basic operations by using unary operator overloading function.
OBJECTIVE:
THEORY:
Calling or overloading the function by using the unary operator is called unary operator
overloading. E.g.
class math
}}
void main ()
int a;
public:
math a;
math() { cin>>a;}
void operator ++() { cout<< c=a+5;
a++;
}
ALGORITHM:
STEP 4: Create a class and get a value from the main and perform the operation
STEP 5: When any operator in the main is executed then it calls the corresponding
function
STEP 6: This process of calling and accessing the function by using operator is called as
operator overloading
STEP 7: Now the corresponding operator is done and the value is return that value and stop
the program
OUTPUT :
Thus a C++ program for illustration of unary operator overloading has been written and
executed successfully.
Viva Questions:
1.What are unary operators?
2.What is the difference between unary operators and binary operators?
3.How can you define operator overloading function?
4.What is the use of operator overloading?
5.What is the syntax for unary operator overloading?
6. What is the syntax for binary operator overloading?
Ex No. 1d
SINGLE INHERITANCE
AIM:
To write a C++ program for getting a mark list of the Student using Single Inheritance
OBJECTIVE:
THEORY:
Deriving the Properties of single base class in the single derived class .It increases the
reusability of the classes. The colon ( : ) is used for inheriting the base class in the derived class.
E.g.
ACET/ECE/DSOOPS/2013-14
class math()
add() {
cout<<c=a+b;
int a,b;
math()
{ cin>>a>>b;}
void main() {
}int c;
add a;}
ALGORITHM:
Rollno: 101
Name: Ram
Mark1: 70
Mark2: 80
Total:120
RESULT:
Thus the Mark list preparation using Single Inheritance has been written and verified
successfully.
Viva Questions:
1.What do you understand by the term inheritance?
2.List the types of inheritance.
3.What is the use of inheritance?
4.Mention the available access specifiers in C++.
5.Is it possible to use constructor in inheritance?
6.What is multilevel inheritance?
EX No. 2
ACET/ECE/DSOOPS/2013-14
AIM:
ALGORITHM:
1.
2.
3.
Functions create(),insert(),search(),display(),del().
4.
Declare the required number of variables and assign a value for required variables.
5.
Get the option from the user whether to create,insert,delete, Search or display the list.
6.
For create operation, get the number of elements from the user.
7.
For insert operation operation, get the position where to insert a number in the list and get
the value to be inserted, insert the number after that position.
8.
For deletion operation,get then position in the list to be Deleted and delete the value from
that position.
9.
For search operation,get the value to be searched. Search the Number and display its
position and if the value is not available, Then display that the value is not available in the
list.
10. For display operation, display all the values in the list.
11. Stop the process.
ACET/ECE/DSOOPS/2013-14
Output:
Array Implementation of Linked List.
_____________________________________
1. Creation.
2. Insertion.
496725
3. Deletion.
4. Searching.
5. Display.
6. Exit.
deleted : 4
49725
49625
49725
be
inserted : 2
49625
RESULT:
Thus a C program for Array Implementation of Linked List has been written and executed
successfully.
Viva Questions:
1.Is list a linear or non linear data structure?
2.Can you insert elements at the middle of a list?
3.Write the steps to delete an element from list.
4.What is the different between linear and non linear data structures?
5.What is ADT?
EX No. 3
ACET/ECE/DSOOPS/2013-14
AIM:
Understand the difference between array & linked list implementation in list ADT.
ALGORITHM:
1.
2.
3.
4.
Functions create(),insert(),search(),display(),del().
5.
declare the required number of variables and assign a value for required variables.
6.
Get the option from the user whether to create,insert,delete,Search or display the list.
7.
For create operation, get the number of elements from the user.
8.
For insert operation , get the position where to insert a number in the list and get the value
to be inserted, insert the number after that position.
9.
For deletion operation, get then position in the list to be Deleted and delete the value from
that position.
10. For search operation, get the value to be searched. Search the Number and display its
position and if the value is not available, Then display that the value is not available in the
list.
11. For display operation,display all the values in the list.
12. Stop the process.
OUTPUT:
RESULT:
Thus a C++ program for Linked list Creation of List ADT has been written and executed
successfully.
Viva questions:
1.What is linked list?
2.What is the difference between array list and linked list?
3.How will you search an element at linked list?
4.How will you delete an element from linked list?
5. How will you insert an element into linked list?
6.What is the procedure to insert an element at the beginning of linked list?
ACET/ECE/DSOOPS/2013-14
EX No.4
AIM:
Understand the difference between cursor & linked list implementation of list ADT.
ALGORITHM:
10
Thus the Cursor implementation of List ADT has been written and executed successfully.
Viva Questions:
1.What is the use of cursor?
2.How will you serach an element in cursor list?
3.How will you delete an element from cursor list?
4. How will you insert an element to cursor list?
5.what is the difference between cursor list and array list?
ACET/ECE/DSOOPS/2013-14
11
EX No. 5.A
STACK ADT
ARRAY IMPLEMENTATION OF STACK
AIM:
1.
2.
3.
4.
5.
For push operations, read the element from the user and check
a. Whether the stack is full. If so, display stack overflow
b. Otherwise insert it to the top of the stack.
6.
7.
8.
OUTPUT:
12
45 67 32
Enter Your Choice...: 2
The Top Item is poped out.
Enter Your Choice...: 3
The items pushed in the are....
45 67
Enter Your Choice...: 4
RESULT:
Thus the Array implementation of Stack has been written and executed successfully.
Viva Questions:
1.
2.
3.
4.
5.
6.
7.
8.
Ex. NO 5.B.
AIM:
1.
2.
3.
4.
5.
For push operations, read the element from the user and check
a. Whether the stack is full. If so, display stack overflow
b. Otherwise insert it to the top of the stack.
6.
7.
8.
ACET/ECE/DSOOPS/2013-14
13
OUTPUT:
ACET/ECE/DSOOPS/2013-14
14
Ex No. 6
AIM:
1. Use the stack created in 5A or 5B to convert the given infix expression to postfix
expression.
2. Start the process
3. Q is the arithmetic expression of infix form. equivalent postfix expression P is needed by
stack application.
4. scan Q from left to right and repeat steps 4 to 7 for each element of Q until stack is empty.
5. if an operand is encountered add it to P
6. if left paranthesis is encountered push it to stack
7. if an operator is encountered
a) repeatedly pop from stack and add P each operator which has the same precedence
as or higher precedence than that operator.
b) Add that operator to stack
8. if a right paranthesis is encountered tyhen
a)repeatedly pop from stack and add to P each operator.
b)remove the left paranthesis
8. Print results.
OUTPUT:
a+b
ab+
RESULT:
Thus the given infix expression has been converted to postfix expression successfully.
Viva Questions:
1. Write the prefix and postfix form of the expression (A+B)/(C-D)
2. What is infix notation?
3. What is prefix notation?
4. What is postfix notation?
5. What are the various operations performed on the stack?
6. Is it possible to have more than one stack in an array.
7. Name any two applications of stack?
8. What are the postfix and prefix forms of the expression?
A+B*(C-D)/(P-R)
Postfix form: ABCD-*PR-/+
Prefix form: +A/*B-CD-PR
ACET/ECE/DSOOPS/2013-14
15
Ex No. 7.A.
QUEUE ADT
ARRAY IMPLEMENTATION OF QUEUE ADT
AIM:
1.
2.
3.
4.
5.
QUEUE OPERATIONS
****************
1.Enqueue
2.Dequeue
3.Display
4.Exit
Enter Your choice...: 1
Enter the item to be inserted.. : 56
The Element is inserted into the Queue.
Enter Your choice...: 1
Enter the item to be inserted.. : 34
The Element is inserted into the Queue.
Enter Your choice...: 1
Enter the item to be inserted.. : 78
ACET/ECE/DSOOPS/2013-14
16
Thus the Array implementation of Queue ADT has been executed and verified successfully.
Viva Questions:
1. What is meant by Queue?
2. List the applications of Queue.
3. What is meant by enqueue?
4. What is meant by dequeue?
5. What are the various operations performed on the Queue?
6. How do you test for an empty queue?
7. What is the difference between Stack & queue?
8.What kind of data structure is queue?
Ex.No. 7.B.
ACET/ECE/DSOOPS/2013-14
17
AIM:
1.
2.
3.
4.
5.
6.
7.
8.
OUTPUT:
Thus the Linked list implementation of Queue ADT has been executed and verified
successfully.
Viva Questions:
1. How will you implement Queue using linked list?
ACET/ECE/DSOOPS/2013-14
18
Ex No. 8
ACET/ECE/DSOOPS/2013-14
19
AIM:
1.
2.
3.
4.
5.
6.
7.
Calculate the mid position and check whether the value in the
Mid position is > or < the search value.
8.
last=mid position 1
10. If available then return the location of the element else display
The search element is not there.
11. Stop the process.
OUTPUT:
Binary Search
Enter the number of elements in the Array : 7
Enter the Elements one by one...
45 23 78 21 56 33 66
The sorted array is ....
21
23
33
45
56
66
78
Enter the element to be searched..
56
The Element 56 is found at the position 5
RESULT:
Thus the program for Binary search has been verified successfully.
Viva questions:
ACET/ECE/DSOOPS/2013-14
20
1.
2.
3.
4.
5.
6.
Ex No. 9
HEAP SORT
AIM:
ACET/ECE/DSOOPS/2013-14
21
1.
2.
3.
Get the limit of elements to be sorted and also get the elements One by one and store it
sequentially in an array..
4.
5.
In create_heap(a,n),construct a complete binary tree such that First element of array a[0]
will be the root.The left and right Childs are a[2k+1] and a[2k+2] respectively.
6.
7.
Keep the last node(now root) at the proper position,and for each node,
8.
9.
OUTPUT:
Thus the given numbers have been sorted by using Heap sort successfully.
VivaQuestions:
1.
2.
3.
4.
5.
6.
7.
Ex No.10
QUICK SORT
AIM:
ACET/ECE/DSOOPS/2013-14
22
1.
2.
3.
4.
5.
Call the function quick() to sort the elements using quick sort
Algorithm and declare the sorted elements.
6.
7.
Assign a[0]=a[left],i=a[left],j=a[right].
8.
a) Scan the array from left to right and check (a[i]<=pivot && i<right)for each
element.Stop left
scanning keep the location in i.
b) Scan the array from right to left and check (a[j]>=pivot && j>left) for each
element.Stop right scanning and keep the location in j.
c)Check the values at the position i and j.If i<j then call swap(a,i,j) to interchange the
values and repeat the steps a) & b) till i<j. else
swap(a,left,j)
quick(a,left,j-1)
quick(a,j+1,right)
9.
Repeat the step 8 for left and right partitions until we get the partitions of only one element.
Thus the sorted array of numbers using Quick sort has been executed and verified
successfully.
Viva Questions:
ACET/ECE/DSOOPS/2013-14
23
1.
2.
3.
4.
5.
6.
EX.NO:11
ACET/ECE/DSOOPS/2013-14
24
Aim:
To write a C++ program to add two complex numbers using object as argument.
Algorithm:
Step 1: Create a class as complex.
Step 2: Declare the data members as real and img.
Step 3: Declare the member functions as
void getdata()
void show()
void sum(complex c1,complex c2)
Step 4: getdata() method is used to get the values .
Step 5: show() method is used to display the values.
Step 6: sum() method is used to perform addition operation using object as argument.
Step 7: In main, create the object for Complex class.
Step 8: Call the function using objectname.functionname();
Output:
Enter the real and img part 4 5
Enter the real and img part 2 3
The complex number of c1:
4+5i
The complex number of c2:
2+3i
The result is:
6+8i
Result:
Thus the C++ program of add two complex numbers using object as argument was verified
successfully.
Viva Questions:
1.What is meant by object?
2.How many objects can be created for a class?
3.What is the syntax for creating an object?
4.How will you create array of objects?And how can you acces array of objects?
5.How will you set pointer to objects?
EX.NO:12
ACET/ECE/DSOOPS/2013-14
25
Aim:
To write a C++ program to overload new and delete operators.
Algorithm:
Step1: Declare the class as Vector.
Step 2: Declare the data member as *array;
Step 3: Declare the member function as
void *operator new(int size)
void operator delete(void * x)
void read()
void sum()
Step 4: In the main, create the object for the Vector class.
Step 5: Allocate the memory space for the array elements using new operator.
Step 6: Read function is used to get the array elements.
Step 7: Add the elements in the array using for loop in the sum function and display the
result.
Step 8: Delete the memory space by delete operator.
Output:
Enter Vector data...
Vector[0]=?1
Vector[1]=?5
Vector[2]=?8
Vector[3]=?7
Vector[4]=?4
Vector[5]=?6
Vector[6]=?1
Vector[7]=?8
Vector[8]=?9
Vector[9]=?10
The sum is 59
Result:
Thus the C++ program to overload new and delete operators was verified successfully.
Viva Questions:
1.What is meant by dynamic allocation?
2.What is the use of new operator?
3.What is the use of delete operator?
4.What do you understand by the term garbage collection?how it is performed in C++?
5.Define vector classes.
ACET/ECE/DSOOPS/2013-14
26
27
28
29
ACET/ECE/DSOOPS/2013-14
30