You are on page 1of 31

1.

Student Result Preparation System using Class

#include<iostream.h>

#include<conio.h>

#include<string.h>

class marksheet

int lang,maths,che,phy,eng,tot,rno;

float avg;

char name[20],result[10],grade[10];

public:

void getdata();

void calculate();

void display();

};

void marksheet::getdata()

cout<<"Enter your register number"<<"\t:";

cin>>rno;

cout<<"Enter your name"<<"\t:";

cin>>name;

cout<<"Enter language mark"<<"\t:";

cin>>lang;

cout<<"Enter english mark"<<"\t:";

cin>>eng;

1
cout<<"Enter maths mark"<<"\t:";

cin>>maths;

cout<<"Enter Physics mark"<<"\t:";

cin>>phy;

cout<<"Enter Chemistry mark"<<"\t:";

cin>>che;

void marksheet::calculate()

tot=lang+eng+maths+phy+che;

avg=tot/5;

if(lang>=40&&eng>=40&&maths>=40&&phy>=40&&che>=40)

strcpy(result,"pass");
Student Result Preparation System
else AIM:
To write a C++ program to prepare student result
strcpy(result,"fail"); using classes and objects.

if(strcmp(result,"pass")==0) ALGORITHM:
STEP 1: Start the program.
{ STEP 2: Declare the data members.
STEP 3: Define the data members outside of the class.
if(avg>=90) STEP 4: Read the student details. (i.e.) Rollno, Name, 5
Subject marks.
strcpy(grade,"S grade"); STEP 5: Calculate total and average marks.
tot= lang + eng + maths + phy + che and avg = tot/3
else if(avg<90&&avg>=80)
STEP 6: Calculate the grade and result using average.
strcpy(grade,"A grade"); STEP 7: Display the student record.
STEP 8: Stop the program.
else if(avg<80&&avg>=70)

strcpy(grade,"B grade");

2
else if(avg<70&&avg>=60)

strcpy(grade,"C grade");

else if(avg<60&&avg>=50)

strcpy(grade,"D grade");

else

strcpy(grade,"E grade");

else

strcpy(grade,"F grade");

void marksheet::display()

{
cout<<"\n STUDENT MARKSHEET\n";

cout<<"\nRegister Number : "<<rno<<"\n";

cout<<"Name \t\t: "<<name<<"\n";

cout<<"Language \t: "<<lang<<"\n";

cout<<"English \t: "<<eng<<"\n";

cout<<"Mathematics \t: "<<maths<<"\n";

cout<<"Physics \t: "<<phy<<"\n";

cout<<"Chemistry \t: "<<che<<"\n";

cout<<"\t\t\tTotal \t: "<<tot<<"\n";

cout<<"\t\t\tAverage : "<<avg<<"\n";

cout<<"\t\t\tResult \t: "<<result<<"\n";

cout<<"\t\t\tGrade : "<<grade;

3
}

void main()

clrscr();

cout<<"\t\t STUDENT MARK SHEET \n\n";

marksheet ms;

ms.getdata();

ms.calculate();

ms.display();
CONSTRUCTOR
getch(); AIM:
To write a C++ program to display the details of student
} using Constructor.

2. CONSTRUCTOR ALGORITHM:
STEP 1: Start the program.
#include<iostream.h> STEP 2: Declare the data members and constructors in class.
#include<conio.h> STEP 3: Define the constructors in class.
#include<string.h> STEP 4: Write the display().
STEP 5: create object for class Student in main( ).
class Student STEP 6: Call display() and show the values of students.
{
STEP 8: Stop the program.
int Roll;
char Name[25];
float Marks;

public:

Student(int r,char nm[],float m) //Constructor 1 : Parameterize


Constructor
{
Roll = r;
strcpy(Name,nm);
Marks = m;
}

Student(Student &S) //Constructor 2 : Copy Constructor


{

4
Roll = S.Roll;
strcpy(Name,S.Name);
Marks = S.Marks;
}

void Display()
{
cout<<"\n\tRoll : "<<Roll;
cout<<"\n\tName : "<<Name;
cout<<"\n\tMarks : "<<Marks;
}
};

void main()
{
clrscr();
Student S1(2,"Sumit",89);
Student S2(S1);
cout<<" \t\t\t CONSTRUCTOR";
cout<<"\n\n\tValues in object S1 \n";
S1.Display();

cout<<"\n\n\tValues in object S2 \n";


S2.Display();
MULTIPLE INHERITANCE
getch();
} AIM:
To write a C++ program to calculate and display the marks of
student using Multiple Inheritance.
3.MULTIPLE INHERITANCE
ALGORITHM:
#include<iostream.h> STEP 1: Start the program.
#include<conio.h> STEP 2: Declare the base class student and define get() to get the
student details.
class student STEP 3: Define the other class sports and define getsm() to get
{ sports mark.
protected: STEP 4: Create a derived class statement and define display() to
int rno, m1, m2; find out the total and average.
public: STEP 5: Create object for class Statement in main( ) and call get (),
getsm() and display().
void get() STEP 8: Stop the program.
{
cout << "\n Enter the Roll no :";
cin>>rno;
cout << "Enter the two marks :";
cin >> m1>>m2;

5
}
};

class sports
{
protected:
int sm; // sm = Sports mark
public:

void getsm()
{
cout << "\nEnter the sports mark :";
cin>>sm;

}
};

class statement : public student, public sports


{
int tot, avg;
public:

void display()
{
tot = (m1 + m2 + sm);
avg = tot / 3;
cout<<"\n\t RESULT ";
cout << "\n\n\tRoll No : " << rno << "\n\tTotal : " << tot;
cout << "\n\tAverage : " << avg;
}
};

void main()
{
clrscr();
statement obj;
cout<<"\t\t MULTIPLE INHERITANCE ";
obj.get();
obj.getsm();
obj.display();
getch();
}

4.Multilevel Inheritance

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

6
#include<string.h>
class student // base class
{
private:
int rl;
char nm[20];
public:
void read(){
cout<<"Enter Roll no and Name "<<endl;
cin>>rl>>nm;
}
void display(){
cout<<"Roll NO :"<<rl<<endl;
cout<<"Name : "<<nm<<endl;
}
};
class marks : public student // derived class from student
{
protected:
int s1;
int s2;
int s3;
public:
void getmarks(){
cout<<"Enter three subject marks :"<<endl;
cin>>s1>>s2>>s3;
}
void putmarks(){
cout<<"Subject 1:"<<s1<<endl;
cout<<"Subject 2:"<<s2<<endl;
cout<<"Subject 3:"<<s3<<endl;
}
};
class result : public marks // derived class from marks
{
private:
int t;
float p;
char div[10];
public:
void process(){
t= s1+s2+s3;
p = t/3.0;
p>=60?strcpy(div,"first"):p>=50?strcpy(div, "second"):
strcpy(div,"third");
}
void printresult() {

7
cout<<"Total = "<<t<<endl;
cout<<"Percentage = "<<p<<endl;
cout<<"Class = "<<div<<endl;
}
}; Multilevel Inheritance
void main() AIM:
{ To write a C++ program to prepare student result using
result x; Multilevel Inheritance.
clrscr(); ALGORITHM:
x.read(); STEP 1: Start the program.
x.getmarks(); STEP 2: Declare the base class student and define read() to
x.process(); get the student details and display ( ).
x.display(); STEP 3: Create a derived class marks and define getmarks()
x.putmarks(); and putmarks().
STEP 4: Create the derived class result and define process()
x.printresult();
to find out the total, percent and class and define printresult
getch();
().
}
STEP 5: Create object for class result in main( ) and call all the
functions.
STEP 6: Stop the program.
5. Hybrid Inheritance

#include <iostream.h>
# include<conio.h>
class A
{
public:
int x;
};
class B : public A
{
public:
B() //constructor to initialize x in base class A
{
x = 10;
}
};
class C
{
public:
int y;
C() //constructor to initialize y
{
y = 4;
}
};
class D : public B, public C //D is derived from class B and class C

8
{
public:
void sum() Hybrid Inheritance
{ AIM:
cout << "Sum= " << x + y; To write a C++ program to calculate the sum
} of two numbers using Hybrid Inheritance.
}; ALGORITHM:
STEP 1: Start the program.
int main() STEP 2: Declare the base class A .
{ STEP 3: Create a derived class B and declare x =
clrscr(); 10.
D obj1;//object of derived class D STEP 4: Declare the class C and initialize y = 4.
STEP 5: Create a derived class D with base classes
obj1.sum();
B and C.
getch();
STEP 6: Calculate the sum of x and y.
return 0;
STEP 7: Create object for class D and call sum().
} //end of program
STEP 8: Stop the program.
String Reverse
AIM:
6. String Reverse
To write a C++ program to reverse the given string using
One- dimensional array.
#include<iostream.h>
#include<conio.h> ALGORITHM:
#include<stdio.h> STEP 1: Start the program.
#include<string.h> STEP 2: Read the string.
STEP 3: Find the string length.
int main () STEP 4: using for loop, reverse the string.
{ STEP 5: Print the reversed string.
clrscr(); STEP 6: Stop the program.
char str[50], temp;
int i, j;
cout <<"\n\t\t STRING REVERSE \n";
cout << "Enter a string : ";
gets(str);
j = strlen(str) - 1;
for (i = 0; i < j; i++,j--)
{
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
cout << "\nReverse string : " << str;
getch();
return 0; Two Dimensional Array
} AIM:
To write a C++ program, to print the lower triangular
7.Two Dimensional Array of a given matrix.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Read the elements of the matrix. 9
STEP 3: If i<j, print empty space otherwise print the
element.
STEP 4: Stop the program.
#include<iostream.h>
#include<conio.h>
void lower(int [3][3],int, int);
int main()
{
clrscr();
int matrix[3][3], row = 3, col = 3;
cout<<"\t\t\tLower triangular matrix \n";
cout<<"\n Enter the elements of matrix A";
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
cin>>matrix[i][j];
}
}
cout << "\n Lower triangular matrix: \n";
lower(matrix, row, col);
getch();
return 0;
}
void lower(int matrix[3][3], int row, int col)
{
int i, j;
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
if (i < j)
{
cout << " " << " ";
}
else
cout << matrix[i][j] << " ";
}
cout << endl;
}
}

8.Text File Manipulation

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
int main()
{ clrscr();
ifstream fin("example.txt"); //opening text file
int line=1,word=1,size;
char ch;
cout<<"To count number of lines, words and Text
totalFile
sizeManipulation
of the file" ;
AIM:
fin.seekg(0,ios::end); To write a C++ program to count number of lines, words and total size
size=fin.tellg(); of the file
ALGORITHM:
STEP 1: Start the program.
STEP 2: Open the text file example.txt.
10
STEP 3: Calculate the total size of the file.
STEP 4: Count the number of lines and number of words from the text file.
STEP 5: Print the counted number of lines, words and total size of the file.
fin.seekg(0,ios::beg);

while(fin)
{
fin.get(ch);
if(ch==' '||ch=='\n')
word++;

if(ch=='\n')
line++;
}
cout<<"Lines="<<line<<"\nWords="<<word<<"\nSize="<<size<<"\n";
fin.close(); //closing file
getch();
return 0;

9.Binary file Manipulation

#include<fstream.h> Binary file Manipulation


#include<conio.h> AIM:
#include<stdlib.h> To write a C++ program to search a record from the binary file.
ALGORITHM:
class student STEP 1: Start the program.
{ STEP 2: Open the binary file.
int rollno; STEP 3: Read necessary details of the student and insert in the existing
char name[20]; file.
char branch[3];
STEP 4: Use roll number to search a record. If the roll number is
float marks;
present in the file it prints the details of the student.
char grade;
STEP 5: Otherwise it will print record not found.
STEP 6: Close the binary file.
public:
STEP 7: Stop the program.
void getdata()
{
cout<<"Rollno: ";
cin>>rollno;
cout<<"Name: ";
cin>>name;
cout<<"Branch: ";
cin>>branch;
cout<<"Marks: ";
cin>>marks;

if(marks>=75)
{
grade = 'A';
}
else if(marks>=60)
{
grade = 'B';
}
else if(marks>=50)
{

11
grade = 'C';
}
else if(marks>=40)
{
grade = 'D';
}
else
{
grade = 'F';
}
}

void putdata()
{
cout<<"Rollno: "<<rollno<<"\tName: "<<name<<"\n";
cout<<"Marks: "<<marks<<"\tGrade: "<<grade<<"\n";
}

int getrno()
{
return rollno;
}
}stud1;

void main()
{
clrscr();
cout<<"\t\t\tBinary file Manipulation\n";
fstream fio("marks.dat", ios::in | ios::out);
char ans='y';
while(ans=='y' || ans=='Y')
{
stud1.getdata();
fio.write((char *)&stud1, sizeof(stud1));
cout<<"Record added to the file\n";
cout<<"\nWant to enter more ? (y/n)..";
cin>>ans;
}

clrscr();
int rno;
long pos;
char found='f';

cout<<"Enter rollno of student to be search for: ";


cin>>rno;

fio.seekg(0);
while(!fio.eof())
{
pos=fio.tellg();
fio.read((char *)&stud1, sizeof(stud1));
if(stud1.getrno() == rno)
{

12
stud1.putdata();
fio.seekg(pos);
found='t';
break;
}
}
if(found=='f')
{
cout<<"\nRecord not found in the file..!!\n";
cout<<"Press any key to exit...\n";
getch();
exit(2);
}

fio.close();
getch(); Linear Search
} AIM:
To write a C++ program to search an element using linear search.
10. Linear Search ALGORITHM:
STEP 1: Start the program.
Pg: 430 STEP 2: Enter the size of the array.
STEP 3: Enter the elements of the array.
STEP 4: Enter the element to be search.
STEP 5: Invoke Lsearch( ).
STEP 6: If the search element found, return the item.
STEP 7: Otherwise, print element not found.
STEP 8: Stop the Program.

11.Binary Search Binary Search


AIM:
Pg: 432 To write a C++ program to search an element using binary
search.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Enter the size of the array.
STEP 3: Enter the elements of the array.
STEP 4: Enter the element to be search.
STEP 5: Invoke Bsearch( ).
STEP 6: Set beg = 0, last =size-1, find mid =(beg+last)/2.
STEP 7: If item = ar[mid], return mid.
STEP 8: Otherwise check item > ar[mid], set beg =mid+1 and repeat
mid =(beg + last)/2.
STEP 9: Otherwise set last = mid -1 and repeat mid =(beg + last)/2.
STEP 10: Print the searched element.
STEP 11: Otherwise, print element not found.
STEP 12: Stop the Program.

13
Selection Sort
12.Selection Sort AIM:
To write a C++ program to sort the elements using selection sort.
ALGORITHM:
Pg: 444 STEP 1: Start the program.
STEP 2: Enter the size of the array.
STEP 3: Enter the elements of the array.
STEP 4: Invoke selsort(ar, n ).
STEP 5: Repeat step 6 to 9 for i =0 to size-1
STEP 6: Set small = ar[i] and pos = i.
STEP 7: Repeat step 8 for j = i+1 to size.
STEP 8: If ar[j]<small, then set small = ar[j] and pos = j.
STEP 9: Interchange ar[i] and ar[pos] using temporary variable.
STEP 10: Print the array after each pass.
STEP 11: Print the sorted array.
STEP 12: Stop the Program.

13.Bubble sort
Bubble sort
Pg: 446 AIM:
To write a C++ program to sort the elements using bubble sort.

ALGORITHM:
STEP 1: Start the program.
STEP 2: Enter the size of the array.
STEP 3: Enter the elements of the array.
STEP 4: Invoke bubblesort(ar, n ).
STEP 5: Repeat step 6 to 9 for i =0 to size-1
STEP 6: Repeat step 8 for j = 0 to size-1-i.
STEP 7: If ar[j]> Ar[j+1], interchange ar[j] and ar[j+1] using temporary
variable.
STEP 8: Print the array after each pass.
STEP 9: Print the sorted array.
STEP 10: Stop the Program.

14.Insertion Sort
Insertion Sort
Pg: 448 AIM:
To write a C++ program to sort the elements using insertion sort.
ALGORITHM:
STEP 1: Start the program.
STEP 2: Enter the size of the array.
STEP 3: Enter the elements of the array.
STEP 4: Invoke inssort(ar,n).
STEP 5: Repeat step 6 to 10 for i =0 to size
STEP 6: Set tmp = ar[i] and j = i-1.
STEP 7: Repeat step 8 while tmp < ar[j].
STEP 8: Set ar[j+1] = ar [j] and j = j-1.
STEP 9: Set ar[j+1] = tmp.
STEP 10: Print the array after each pass.
STEP 11: Print the sorted array.
STEP 12: Stop the Program. 14
Stack using array
15. Stack using array
AIM:
#include<iostream.h> To write a C++ program to implement stack operations using
#include<stdio.h> array.
#include<conio.h> ALGORITHM:
#include<stdlib.h> STEP 1: Start the program.
STEP 2: Define necessary data members and member functions in the
#define SIZE 5 class Stack.
STEP 3: Enter the choice of stack menu.
class Stack { STEP 4: If choice = 1, call push( ) to insert the new element.
private: STEP 5: If choice = 2, call pop( ) to delete the element.
int item, i; STEP 6: If choice = 3, call display( ) to show the stack list.
int data[SIZE]; STEP 7: If choice is any other values exit the program.
int top; STEP 8: Stop the Program.

public:

Stack() {
top = 0;

void push() {
if (top == SIZE)
cout << "\n\t Stack is Full!";
else {
cout << "\nEnter the value to be pushed : ";
cin>>item;
cout << "\n Position : " << top << ", Pushed Value :" << item;
data[top++] = item;
}
}

void pop() {
if (top == 0)
cout << "\n Stack is Empty!";
else {
--top;
cout << "\n Position : " << top << ", Popped Value :" <<
data[top];
}
}

void display() {
cout << "\n Stack Size : " << top;
for (i = (top - 1); i >= 0; i--)
cout << "\n Position : " << i << ", Value :" << data[i];
}
};

int main() {

15
clrscr();
int choice, exit = 1;
Stack S;
cout << "\n\t\t\t Stack Using Array";
do {
cout << "\n\n Main Menu";

cout << "\n\n1.Push \n2.Pop \n3.Display \nOthers to exit";


cout << "\n\nEnter Your Choice : ";
cin>>choice;
switch (choice) {
case 1:
S.push();
break;
case 2:
S.pop();
break;
case 3:
S.display();
break;
default:
exit = 0;
break;
}
} while (exit);

return 0;
}

16. Stack using linked list Stack using linked list


#include<iostream.h> AIM:
#include<conio.h> To write a C++ program to implement stack operations using
linked list.
struct node ALGORITHM:
{ STEP 1: Start the program.
int data; STEP 2: Define a structure node with two members data and next
struct node *next; STEP 3: Define necessary data members and member functions in the
}; class Stack.
STEP 4: Enter the choice of stack menu.
class stack STEP 5: If choice = 1, call push( ) to insert the new element.
{ STEP 6: If choice = 2, call pop( ) to delete the element.
struct node *top; STEP 7: If choice = 3, call display( ) to show the stack list.
public: STEP 8: If choice is any other values exit the program.
stack() STEP 9: Stop the Program.
{
top=NULL;
}
void push()
{

16
int value;
struct node *ptr;
cout<<"\nPUSH Operation\n";
cout<<"Enter a number to insert: ";
cin>>value;
ptr=new node;
ptr->data=value;
ptr->next=NULL;
if(top!=NULL)
ptr->next=top;
top=ptr;
cout<<"\nNew item is inserted to the stack!!!";
}

void pop()
{
struct node *temp;
if(top==NULL)
{
cout<<"\nThe stack is empty!!!";
}
temp=top;
top=top->next;
cout<<"\nPOP Operation........\nPoped value is "<<temp->data;
delete temp;
}
void show() // to show the stack
{
struct node *ptr1=top;
cout<<"\nThe stack is\n";
while(ptr1!=NULL)
{
cout<<ptr1->data<<" ->";
ptr1=ptr1->next;
}
cout<<"NULL\n";
}
};

int main()
{
clrscr();
stack s;
int choice;
while(1)
{
cout<<"\n\n\t\tSTACK USING LINKED LIST\n\n";
cout<<"1:PUSH\n2:POP\n3:DISPLAY STACK\n4:EXIT";
cout<<"\n\nEnter your choice(1-4): ";
cin>>choice;
switch(choice)
{

17
case 1:
s.push();
break;
case 2:
s.pop();
break;
case 3:
s.show();
break;
case 4:
return 0;
break;
default:
cout<<"\nPlease enter correct choice(1-4)!!";
break;
}
}
return 0;
}

17.QUEUE USING ARRAY Queue using array


#include<iostream.h>
#include<conio.h> AIM:
To write a C++ program to implement queue operations using
#include<stdlib.h>
array.
#define SIZE 5
ALGORITHM:
int q[SIZE],front=0,rear=0;
STEP 1: Start the program.
void main()
STEP 2: Enter the choice of queue menu.
{
STEP 3: If choice = 1, call ins( ) to insert the queue element in the rear.
int ch;
STEP 4: If choice = 2, call del( ) to delete the element from the front.
clrscr();
STEP 5: If choice = 3, call display( ) to show the list of elements in the
void ins(); queue.
void del(); STEP 6: If choice is any other values exit the program.
void display(); STEP 7: Stop the Program.
cout<<"\t\t\t QUEUE USING ARRAY";
while(1)
{
cout<<"\n\n 1.Insert element";
cout<<"\n 2.Delete element";
cout<<"\n 3.Display";
cout<<"\n 4.Exit";
cout<<"\n\n Enter your choice:";
cin>>ch;
clrscr();
switch(ch)
{
case 1:
ins();
break;
case 2:
del();

18
break;
case 3:
display();
break;
case 4:
exit(0);
default:
cout<<"\n Invalid choice";
}
}
}
void ins()
{
int n;
if (rear==SIZE && front==0)
cout<<"\nQueue is full";
else
{
cout<<"\nEnter the element to insert:";
cin>>n;
q[rear]=n;
}
rear++;
}
void del()
{
int n,i;
if (front==rear)
cout<<"\nQueue is empty";
else
{
n=q[front];
front++;
cout<<"\n"<<n<<" - removed from the queue\n";
}
}
void display()
{
int i,temp=front;
if (front==rear)
cout<<"\nQueue is empty";
else
{
cout<<"\n Elements in the queue:";
for(i=temp;i<rear;i++)
{
cout<<q[i]<<" ";
}
}}

19
18.QUEUE USING LINKED LIST

#include<iostream.h> Queue using linked list


#include<stdlib.h>
#include<conio.h> AIM:
To write a C++ program to implement queue operations using
struct node linked list.
{ ALGORITHM:
int data; STEP 1: Start the program.
struct node *next; STEP 2: Define a structure node with two members data and next
}*front=NULL,*rear,*temp; STEP 4: Enter the choice of queue menu.
STEP 5: If choice = 1, call ins( ) to insert the element in the rear
void ins() position.
{ STEP 6: If choice = 2, call pop( ) to delete the element from the front.
temp=new node; STEP 7: If choice = 3, call display( ) to show the stack list.
cout<<"Enter data:"; STEP 8: If choice is any other values exit the program.
cin>>temp->data; STEP 9: Stop the Program.
temp->next=NULL;

if(front==NULL)
front=rear=temp;
else
{
rear->next=temp;
rear=temp;
}
}

void del()
{
if(front==NULL)
cout<<"Queue is empty\n";
else
{
temp=front;
front=front->next;
cout<<"Deleted node is "<<temp->data<<"\n";
delete(temp);
}
}

void dis()
{
if(front==NULL)
cout<<"Queue is empty\n";
else
{
temp=front;
while(temp!=NULL)
{
cout<<temp->data<<"->";

20
temp=temp->next;
}
}
}

int main()
{
clrscr();
int ch;
cout<<"Queue Using Linked List";
while(1)
{
cout<<"\n\n*** Menu ***"<<"\n1.Insert\n2.Delete\n3.Display\n4.Exit";
cout<<"\n\nEnter your choice(1-4):";
cin>>ch;
cout<<"\n";

switch(ch)
{
case 1: ins();
break;
case 2: del();
break;
case 3: dis();
break;
case 4: exit(0);
break;
default: cout<<"Wrong Choice!!!";
}
}
getch();
return 0;
}

19.CIRCULAR QUEUE Circular Queue

#include <iostream.h> AIM:


To write a C++ program to implement circular queue operations.
#include<conio.h>
#define MAX 5
ALGORITHM:
STEP 1: Start the program.
class C_Queue
STEP 2: Define necessary data members and member functions in the
{
class C_Queue.
private:
STEP 4: Enter the choice of circular queue menu.
int *data;
STEP 5: If choice = 1, call insert( ) to insert the element .
int front, rear; STEP 6: If choice = 2, call pop( ) to delete the element.
public: STEP 7: If choice = 3, call display( ) to show the circular queue.
C_Queue() STEP 8: If choice is any other values exit the program.
{ STEP 9: Stop the Program.
data = new int [MAX];

21
rear = front = -1;
}

void insert(int item)


{
if ((front == 0 && rear == MAX-1) || (front == rear+1))
{
cout<<"\n Queue Overflow \n";
return;
}
if (front == -1)
{
front = 0;
rear = 0;
}
else
{
if (rear == MAX - 1)
rear = 0;
else
rear = rear + 1;
}
data[rear] = item ;
}

void del()
{
if (front == -1)
{
cout<<"\nQueue Underflow\n";
return ;
}
cout<<"\n Element deleted from queue is : "<<data[front]<<endl;
if (front == rear)
{
front = -1;
rear = -1;
}
else
{
if (front == MAX - 1)
front = 0;
else
front = front + 1;
}
}

void display()
{
int f_pos = front, r_pos = rear;
if (front == -1)
{

22
cout<<"\n Queue is empty\n";
return;
}
cout<<"\n Queue elements : ";
if (f_pos <= r_pos)
{
while (f_pos <= r_pos)
{
cout<<data[f_pos]<<" ";
f_pos++;
}
}
else
{
while (f_pos <= MAX - 1)
{
cout<<data[f_pos]<<" ";
f_pos++;
}
f_pos = 0;
while (f_pos <= r_pos)
{
cout<<data[f_pos]<<" ";
f_pos++;
}
}
cout<<endl;
}
};

int main()
{
clrscr();
int choice, item;
C_Queue cq;
cout<<"\t\t\t CIRCULAR QUEUE \n";
do
{
cout<<"\n1.Insert\n";
cout<<"2.Delete\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cout<<"\nEnter your choice : ";
cin>>choice;
switch(choice)
{
case 1:
cout<<"\nEnter the element to insert : ";
cin>>item;
cq.insert(item);
break;
case 2:

23
cq.del();
break;
case 3:
cq.display();
break;
case 4:
break;
default:
cout<<"Wrong choice\n";
}
}
while(choice != 4);
getch();
return 0;
}

24
Index for SQL

Consider the tables given below and answer the questions that follow:

Table: Employee

No Name Salary Zone Age Grade Dept


1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 31 A 10
3 Naveen 32000 West 40 20
4 Uday 38000 North 38 C 30
5 Nupur 32000 East 26 B 20

Table: Department

Dept DName MinSal MaxSal HOD


10 Sales 25000 32000 1
20 Finance 30000 50000 5
30 Admin 25000 40000 7

Write SQL commands to:

Create Table
1. Create the table Employee.
2. Create the table Department.
Insert data in a table
3. Insert data in the table Employee
4. Insert data in the table Department.
Simple Select
5. Display the details of all the employees.
Conditional Select using Where Clause
6. Display the details of all the employees who are below 30 years of age.
Using NULL
7. Display the details of all the employees whose Grade is not NULL.
Using DISTINCT Clause
8. Display the names of various zones from the table Employee. A zone name should
appear only once.
Using Logical Operators (NOT, AND, OR)
9. Display the details of all the employees of department 10 who are above 30 years of
age.

25
Using IN Operator
10. Display the names of all the employees who are working in department 20 or 30.
(Using IN operator)
Using BETWEEN Operator
11. Display the details of all the employees whose grade is between ‘A’ and ‘C’.
(Using BETWEEN operator)
Using LIKE Operator
12. Display the name, salary, and age of all the employees whose names start with ‘M’.
Using Aggregate functions
13. Display the sum and average of the salaries of all the employees.
14. Display the highest and the lowest salaries being paid in department 10.
Using ORDER BY clause
15. Display the details of all the employees in the ascending order of their grades and
within grades in the descending order of their salaries.
Using GROUP BY clause
16. Display the highest salary, lowest salary, and average salary of each zone.
Using UPDATE, DELETE, ALTER TABLE
17. Put the grade B for all those whose grade is A.
18. Increase the salary of all the employees above 30 years of age by 10%.
JOIN of two tables
19. Display the details of all the employees who work in Sales department.
20. Display the Name and Department Name of all the employees.

26
27
28
29
30
31

You might also like