Professional Documents
Culture Documents
Page 1
1.
I.A. Marks : 25
Exam Hours: 03
Exam Marks: 50
Using circular representation for a polynomial, design, develop, and execute a program in
C to accept two polynomials, add them, and then print the resulting polynomial.
2.
Design, develop, and execute a program in C to convert a given valid
parenthesized infix arithmetic expression to postfix expression and then to print both the
expressions. The expression consists of single character operands and the binary
operators + (plus), - (minus), * (multiply) and / (divide).
3.
Design, develop, and execute a program in C to evaluate a valid postfix expression using
stack. Assume that the postfix expression is read as a single line consisting of nonnegative single digit operands and binary arithmetic operators. The arithmetic operators
are + (add), - (subtract), * (multiply) and / (divide).
4.
5.
6.
Design, develop, and execute a program in C++ to create a class called STRING and
implement the following operations. Display the results after every operation by
overloading the operator <<.
i. STRING s1 = VTU
ii. STRING s2 = BELGAUM
iii. STIRNG s3 = s1 + s2; (Use copy constructor)
7.
Design, develop, and execute a program in C++ to create a class called STACK using an
array of integers and to implement the following operations by overloading the operators
+ and - :
i. s1=s1 + element; where s1 is an object of the class STACK and element is an integer to
be pushed on to top of the stack.
ii. s1=s1- ; where s1 is an object of the class STACK and operator pops off the top elem
Handle the STACK Empty and STACK Full conditions. Also display the contents of the
stack after each operation, by overloading the operator <<.
Dept.of CSE
Page 2
9.
10.
Design, develop, and execute a program in C++ to create a class called LIST (linked list)
with member functions to insert an element at the front of the list as well as to delete an
element from the front of the list. Demonstrate all the functions after creating a list
object.
Design, develop, and execute a program in C to read a sparse matrix of integer values and
to search the sparse matrix for an element specified by the user. Print the result of the
search appropriately. Use the triple <row, column, value> to represent an element in the
sparse matrix.
Design, develop, and execute a program in C to create a max heap of integers by
accepting one element at a time and by inserting it immediately in to the heap. Use the
array representation for the heap. Display the array at the end of insertion phase.
11.
Design, develop, and execute a program in C to implement a doubly linked list where
each node consists of integers. The program should support the following operations:
i. Create a doubly linked list by adding each node at the front.
ii. Insert a new node to the left of the node whose key value is read as an input.
iii. Delete the node of a given data if it is found, otherwise display appropriate message.
iv. Display the contents of the list.
(Note: Only either (a,b and d) or (a, c and d) may be asked in the examination)
12.
Design, develop, and execute a program in C++ to create a class called DATE with
methods to accept two valid dates in the form dd/mm/yy and to implement the following
operations by overloading the operators + and -. After every operation the results are to
be displayed by overloading the operator <<.
i. no_of_days = d1 d2; where d1 and d2 are DATE objects, d1 >=d2 and no_of_days is
an integer.
ii. d2 = d1 + no_of_days; where d1 is a DATE object and no_of_days is an integer.
13.
Design, develop, and execute a program in C++ to create a class called OCTAL, which
has the characteristics of an octal number.Implement the following operations by writing
an appropriate constructor and an overloaded operator +.
i. OCTAL h = x ; where x is an integer
ii. int y = h + k ; where h is an OCTAL object and k is an integer.
Display the OCTAL result by overloading the operator <<. Also display the values of h
and y.
14.
Design, develop, and execute a program in C++ to create a class called BIN_TREE that
represents a Binary Tree, with member functions to perform inorder, preorder and
postorder traversals. Create a BIN_TREE object and demonstrate the traversals.
Note: In the examination each student picks one question from a lot of all the 14 questions.
Dept.of CSE
Page 3
Page 4
Page 5
Page 6
OUTPUT:
Enter the No of terms for Polynomial 1:2
Enter coefficient and exponent for term 1: 2 3
Enter coeficient and exponent for term 2:4 2
Enter the No of terms for Polynomial 2:3
Enter coefficient and exponent for term 1: 5 2
Enter coeficient and exponent for term 2:3 3
Enter coefficient and exponent for term 3: 4 1
Polynomial 1 is:2 x^3+4 x^2
Polynomial 2 is:3x^3+5 x^2+4 x^1
Added polynomial is:5 x^3+9 x^2+4 x^1
Page 7
Dept.of CSE
Page 8
OUTPUT:
Enter the infix expression: (((a+b)/c)*(a-b))
Dept.of CSE
Page 9
Page 10
Page 11
OUTPUT:
Enter a valid postfix expression:234*+
The result is: 14.000000
Enter a valid postfix expression:68321$*/The result is: 4.666667
Page 12
Page 13
OUTPUT:
1. Insert 2.delete
3.display
Enter your choice:1
Enter the item to be inserted:10
1. Insert 2.delete
3.display
Enter your choice:1
Enter the item to be inserted:20
4.exit
1. Insert 2.delete
3.display
Enter your choice:1
Enter the item to be inserted:30
4.exit
1. Insert 2.delete
3.display
Enter your choice:3
contents of the queue is:
10
20
30
1. Insert 2.delete
3.display
Enter your choice:2
10 is deleted
4.exit
4.exit
4.exit
Page 14
Member functions : to read the data, to calculate Net_Salary and to print the values
of all data members.
(All_Allowance (AA) = 123% of Basic , Income Tax (IT) = 30% of the gross salary
and Net_Salary = Basic + AA - IT).
#include<iostream.h>
#include<conio.h>
class Emp
{
char emp_name[10];
int emp_num;
float AA,IT,net_sal,basic;
public:
void read_data();
void emp_sal();
void print_data();
};
void Emp::read_data()
{
cout<<"\nEnter the employee num:";
cin>>emp_num;
cout<<"\nEnter the employee's name:";
cin>>emp_name;
cout<<"\nEnter the employee salary:";
cin>>basic;
}
void Emp::emp_sal()
{
float gross_sal;
AA=(123*basic)/100;
gross_sal=basic+AA;
IT=(30*gross_sal)/100;
net_sal=gross_sal-IT;
}
void Emp::print_data()
{
cout<<"*******************************";
cout<<"\nEname = "<<emp_name;
cout<<"\nEmp_num= "<<emp_num;
Dept.of CSE
Page 15
OUTPUT:
Enter number of emp:2
Enter the employee data
Enter the Details of a employee: 1
Enter the employee num:11
Enter the employee's name:kiran
Enter the employee salary:6000
*******************************
Ename = kiran
Emp_num= 11
IT = 2736
DA = 3120
net_sal= 6384
*******************************
Enter the Details of a employee: 2
Enter the employee num:12
Enter the employee's name:babu
Enter the employee salary:9000
Dept.of CSE
Page 16
6. Design,develop and execute a program in C++ to create a class called string and
implement the follwing operations. Display the results after every operation by
overloading the operator <<.
i. STRING s1=VTU
ii.STRING s2=BELGAUM
iii.STRING s3=s1+s2;(Use copy constructor).
#include<iostream.h>
#include<conio.h>
#include<string.h>
class STRING
{
char str[50];
public: STRING()
{
strcpy(str,"\0");
}
STRING(const char s[50])
{
strcpy(str,s);
}
STRING(const STRING & s);
STRING operator +(STRING s);
friend ostream & operator <<(ostream &,STRING);
};
STRING :: STRING(const STRING & s)
{
strcpy(str,s.str);
}
STRING STRING :: operator +(STRING s)
{
STRING temp;
Dept.of CSE
Page 17
OUTPUT:
The first string is:VTU
The second string is:BELGAUM
The concatenated string is:VTUBELGAUM
7. Design, develop and execute a program in C++ to create a class called STACK
using array of integers and to implement the following operations by overloading
the operators + and -:
Dept.of CSE
Page 18
Page 19
Page 20
OUTPUT:
1. push 2.pop 3.exit
Enter your option:1
Enter the element to push:10
The contents of the stack are:10
1.push 2 .pop 3.exit
Enter your option:1
Enter the element to push:20
The contents of the stack are:
20
10
1.push 2 .pop 3.exit
Enter your option:2
The element popped out is 20
1.push 2 .pop 3.exit
Enter your option:2
The element popped out is 10
The stack is empty
Page 21
as well as to delete an element from the front of the list. Demonstrate all the
functions after creating a list object.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class list
{
private: struct llist
{
int info;
struct llist *next;
};
typedef struct llist node;
node *start,*temp;
public: list()
{
start=NULL;
}
void insert()
{
temp=new node;
cout<<"enter the node to insert\n";
cin>>temp->info;
temp->next=start;
start=temp;
}
void remove()
{
if(start)
{
temp=start;
start=start->next;
cout<<"the node deleted is"<<temp->info;
}
else
cout<<"the list is empty";
}
void display();
Dept.of CSE
Page 22
OUTPUT:
Dept.of CSE
Page 23
4.exit
1.insert
2.delete
3.display
Enter your option:1
Enter the node to insert:13
4.exit
1.insert
2.delete
3.display
Enter your option:1
Enter the node to insert:14
4.exit
1.insert
2.delete
Enter your option:3
Contents of the list are:
14 13 12
3.display
4.exit
1.insert
2.delete
Enter your option:2
The node deleted is 14
3.display
4.exit
Page 24
OUTPUT:
Enter the row and col no: 4 4
Dept.of CSE
Page 25
10. Design, develop and execute a program in C to create a max heap of integers by
accepting one element at a time and by inserting it immediately into a heap. Use the
array representation for the heap. Display the array at the end of insertion phase.
#include<stdio.h>
#include<conio.h>
int m=0,heap[20];
void insert(int);
void main()
{
int i,a,n;
clrscr();
printf("Enter the number of items insert into heap array:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("\enter the item %d to insert into heap: ",i);
scanf("%d",&a);
insert(a);
}
printf("\nThe heap array is=");
for(i=1;i<=n;i++)
printf("%d ",heap[i]);
getch();
}
void insert(int item)
Dept.of CSE
Page 26
OUTPUT:
Enter the number of items insert into heap array: 5
Enter the item 1 to insert into heap: 10
Enter the item 2 to insert into heap: 90
Enter the item 3 to insert into heap: 40
Enter the item 4 to insert into heap: 50
Enter the item 5 to insert into heap: 100
The heap array is: 100 90 40 10 50
Dept.of CSE
Page 27
11. Design, develop and execute a program in C to implement a doubly linked list
where each node consists of integers. The program should support the following
operations:
i. Create a doubly linked list by adding each node at the front.
ii. Insert a new node to the left of the node whose key value is read as an input.
iii. Delete the node of a given data if it is found, otherwise display appropriate
message.
iv. Display the contents of the list.
#include<stdio.h>
#include<conio.h>
struct node1
{
struct node1 *left;
int info;
struct node1 *right;
};
typedef struct node1 node;
node *first,*temp;
void main()
{
int choice,item,key;
clrscr();
void create(int);
void insert(int,int);
void del(int);
void display();
first=NULL;
while(1)
{
printf("\n 1-> create\n 2-> insert left\n 3->delete \n 4->display \n 5 exit");
printf("\n enter your choice");
scanf("%d",&choice);
switch(choice)
{
Dept.of CSE
Page 28
Page 29
Page 30
Page 31
OUTPUT:
1->create 2->insert left
3->delete 4->display 5->exit
Enter your choice:1
Enter the elements of the list to insert and -1 to terminate
10 20 30 -1
1->create 2->insert left
3->delete 4->display 5->exit
Enter your choice:4
The elements are:30 20 10
1->create 2->insert left
3->delete 4->display 5->exit
Enter your choice:2
Enter the key value of the elements to be deleted:20
Item deleted is 20
13. Design, develop and execute a program in C++ to create a class called OCTAL
which has the characteristics of an octal number. Implement the following
operations by writing an appropriate constructor and overload operator +.
i. OCTAL h=x; where x is an integer
ii. int y=h+k; where h is an OCTAL object and k is an integer. Display the OCTAL
result by overloading the operator <<. Also display the values of h and y.
#include <iostream.h>
#include<conio.h>
#include <math.h>
#include <stdlib.h>
class octal
{
int octnum;
public: octal(int m=0)
{
int k,fact=1;
octnum=0;
while(m)
{
k=m%8;
octnum=octnum+k*fact;
fact*=10;
m=m/8;
Dept.of CSE
Page 32
Page 33
OUTPUT:
1.convert to octal
2.add to octal
Enter your choice:1
Enter the integer value to convert:10
Octal number is:12
1.convert to octal
2.add to octal
Enter your choice:2
Enter the octal number first:12
Integer value is:10
Enter the integer to be added:5
Dept.of CSE
3.exit
3.exit
Page 34
12. Design, develop and execute a program in C++ to create a class called DATE
with methods to accepts two valid dates in the form dd/mm/yy and to implement the
following operations by overloading the operators + and -.after every operation the
results are to be displayed by overloading the operator <<
i.no_of_days =d1-d2; where d1and d2 are DATE objects, d1>=d2 and no_of_days is
an integer.
ii.d2=d1+no_days; where d1 is a DATE object and no_of_days is an integer.
#include<iostream.h>
#include<conio.h>
class date
{
int day ,month,year;
public:
date(int d,int m,int y)
{
day=d;
month=m;
year=y;
}
int operator-(date d2);
date operator+(int n);
friend ostream & operator<<(ostream & o,date d);};
int a[13]={0,31,28,31,30,31,30, 31,31,30,31,30,31};
int b[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int date::operator-(date d2)
{
int n=0;
date d1(day,month,year);
while(d1.day!=d2.day||d1.month!=d2.month||d1.year!=d2.year)
{
d2.day++;
n++;
if(d2.year%4==0)
{
if(d2.day>b[d2.month])
{
d2.day=1;
d2.month++;
}
}
else
Dept.of CSE
Page 35
Page 36
OUTPUT:
1 to subtract 2 to add
3 to exit
Enter your choice:1
Enter the date1 in the format dd/mm/yy
26 04 2013
Enter the date2 in the format dd/mm/yy
26 04 2014
Difference is:365
Dept.of CSE
Page 37
14. Design, develop and execute a program in C++ to create a class called
BIN_TREE that represents a binary tree, with member functions to perform
inorder,preorder and postorder traversals. Create a BIN_TREE Object and
demonstrate the traversals.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class bin_tree
{
private: struct node
{
int info;
node *right,*left;
};
node *root,*temp,*scan,*father;
void inorder(node *ptr)
{
if(ptr)
{
inorder(ptr->left);
cout<<ptr->info<<" ";
inorder(ptr->right);
}
}
void preorder(node *ptr)
{
if(ptr)
{
cout<<ptr->info<<" ";
preorder(ptr->left);
preorder(ptr->right);
}
}
void postorder(node *ptr)
{
if(ptr)
{
Dept.of CSE
Page 38
Page 39
Page 40
OUTPUT:
Enter 1 to create binary tree
Enter 2 to display
Enter 3 to exit
Enter your choice:1
Enter the elements to create and -1 to terminate
40 50 100 -1
Enter 1 to create binary tree
Enter 2 to display
Enter 3 to exit
Enter your choice:2
1.in-order
2.pre-order
3.post-order 4.to return to main program
Enter your choice:1
Contents of the tree in in-order is:40 50 100
Enter your choice:3
Contents of the tree in post-order is:40 100 50
Dept.of CSE
Page 41