Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

OUTSIDE DELHI . 2006

Q.1. Introduction class stack
{ int data[10] :
int top ;
public :
stack( ) { top = - 1; }
void push( ) ; //to push an element into the stack
void pop( ) ; //to pop an element from the stack
void Delete(int ITEM) ; //To delete all elements which are equal to ITEM.
} ;
Complete the class with all function definitions. Use another stack to transfer data temporarily.

Solution:

void stack::push( )
{ if(top>=9)
cout<<”Stack Overflow…”;
else
{ top++;
cout<<”\nEnter the element to be inserted…”;
cin>>data[top];
}
}
void stack::pop( )
{ if(top= =-1)
cout<<”\nStack Underflow”;
else
{ cout<<”\nThe element to be deleted = “<<data[top];
top--;
}
}
void stack::Delete(int ITEM)
{
}

Q.2. Write a function in C++ to perform Insert operation in dynamically allocated Queue containing
names of students.
struct NODE
{ char Name[20];
NODE *Link;
};

Solution:

class Queue
{
NODE *front,*rear;
public:
Queue( )
{ front = rear = NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Insert( )
{
NODE *ptr;
ptr=new NODE;
if(ptr= = NULL)
{
cout<<”\nNo memory to create a new node….”;
exit(1);
}
cout<<”\nEnter the name….”;
gets(ptrName);
ptrLink=NULL;
if(rear= = NULL)
front=rear=ptr;
else
{
rearLink=ptr;
rear=ptr;
}
}

Paper By Mr. Ravi Kiran
Email Id : [email protected]