Sie sind auf Seite 1von 67

INDEX

SNo. Topic Page No.


1. Program to print fibonacci series upto that term 3-4
2. Program to accept three numbers and arrange them in 5-7
descending order
3. Program to accept two numbers and swap its values 7-8
4. Program to check whether a number is Armstrong or 8-9
not
5. Program to multiply two matrices 10-12
6. Program to accept student’s details and displaying it 13-14
7. Program to calculate area of circle 15-16
8. Program to enter the students record and calculate 17-18
total percentage
9. Program to sort numbers in ascending order 19-20
10. Program to find number of characters in a string 21-22
11. Program to find sum and average sum of a matrix 23-24
12. Program to find the position of a character in a string 25-26
13. Program to find the sum of diagonal and post 27-29
diagonal of a matrix

Page 1 of 67
14. Program to find the sum of row and column of matrix 30-31
15. Program to find the transpose of a matrix 32-33
16. Program to check whether a number is palindrome or 34-35
not
17. Program to implement push and pop in a stack 36-39
18. Program to implement insert and delete in a queue 40-42
19. Program to implement push and pop in stack using 43-46
linked list
20. Program to implement insert and delete in a queue 47-50
21. SQL QUERIES 51-67

Page 2 of 67
PROGRAM TO PRINT FIBONACCI SERIES UPTO
THAT TERMS
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
unsigned long first,second,third,n;
first=0;
second=1;
cout<<”how many elements(>)5 ? \n”;
cin>>n;
cout<<”Fibonacci series”\n”;
cout<<first<<”\n”<<second;
for(int i=2;i<n;++i)
{
third=first+second;
cout<<”\n”<<third;
first=second;
second=third;
}
return 0;
}

Page 3 of 67
Page 4 of 67
PROGRAM TO ACCEPT THREE VALUES AND
ARRANGE IN DESCENDING ORDER
include<iostream.h>
void main()
{
float a,b,c,big,big2,big3;
cout<<”enter three numbers \n”;
cin>>a>>b>>c;
big=a;
if(b>big)
big=b;
if(c>big)
big=c;
if(a==big)
{ if(b>c)
{ big2=b;
big3=c;
}
else
{ big2=b;
big3=c;
}
else
{ big2=c;
big3=b;
}
}
else if(b==big)
{ if(a>c)
{ big2=a;
big3=c;
}
else
{ big2=c;
big3=a;
}
}
Page 5 of 67
else if(c==big)
{if(a>b)
{ big2=a;
big3=b;
}
else
{ big2=b;
big3=a;
}
}
cout<<big<<”,”<<big2<<”,”<<big3<<”\n”;
}

Page 6 of 67
PROGRAM TO ACCEPT TWO NUMBERS AND
SWAP ITS VALUE
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
void swap(int &, int&);
int a,b ;
cin>>a;
cin>>b;
cout<<”\n the original values are: \n”;
cout<<”a=”<< a<<”,b=”<<b<<”\n”;
swap(a,b);
cout<<”\n the value after swap() are :\n”;
cout<<”a=”<<a<<”,b=”<<b<<”\n”;
getch();
}
void swap(int &x,int &y)
{
int temp;
temp=x;
x=y;

Page 7 of 67
y=temp;
cout<<”\n the swapped values are: \n”;
cout<<”a=”<<x<<”,b=”<<y<<”\n”;
}

Page 8 of 67
PROGRAM TO CHECK WHETHER A NUMBER IS
ARMSTROONG OR NOT
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,r,sum=0,temp;
cout<<"enter the number: ";
cin>>n;
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
cout<<temp<<" is an armstrong number.... ";
else
cout<<temp<<" is not an armstrong number.... ";
getch();
}

Page 9 of 67
Page 10 of 67
PROGRAM TO MULTIPLY TWO MATRICES
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
int A[10][10], B[10][10], C[10][10], m, n, p, q, k, i, j ;
cout<<”\nenter the rows and columns of matrix A:”;
cin>>m>>n;
cout<<”\nenter the rows and columns of matrix B:”;
cin>>p>>q;
if(n==p)
{
cout<<”\nEnter the elements of the matrix A: \n”;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>A[i][j];
cout<<”\nEnter the elements of the matrix B: \n”;
for(i=0;i<p;i++)
for(j=0;j<q;j++)
cin>>B[i][j];
clrscr();
cout<<”\nmatrix A ia:”;
for(i=9;i<m;i++)
{ cout<<”\n”;
for(j=0;j<n;j++)
cout<<A[i][j]<<” “;
}
cout<<”\nmatrix B is:”;
for(i=0;i<p;i++)
{ cout<<”\n”;
for(j=0;j<q;j++)
cout<<B[i][j]<<” “;
}
cout<<”\n product of two matrices: “;
for(i=0;i<m;i++)

Page 11 of 67
{ cout<<”\n”;
for(j=0;j<q;j++)
{
C[i][j]=o;
for(k=0;k<n;k++)
C[i][j]=c[i][j] +A[i][j]*B[i][j];
cout<<C[i[[j]<<” “;
}
}
{
else
cout<<”\nMatrices are not compatible for multiplication....”;
getch();
}

Page 12 of 67
Page 13 of 67
PROGRAM TO ENTER STUDENT DETAILS AND
DISPLAYING IT.
#include <iostream.h>
#include<conio.h>
class stud
{
public:
char name[30],clas[10];
int rol,age;

void enter()
{
cout<<"Enter Student Name: ";
cin>>name;
cout<<"Enter Student Age: ";
cin>>age;
cout<<"Enter Student Roll number: ";
cin>>rol;
cout<<"Enter Student Class: ";
cin>>clas;
}

void display()
{
cout<<”\nstudent name:”<<name;
cout<<”\nage:”<<age;
cout<<”\nroll no:”<<rol;
cout<<”\nclass:”<<clas;
}
};

int main()
{clrscr();
class stud s;
s.enter();
s.display();
cin.get();
Page 14 of 67
getch();
return 0;
}

Page 15 of 67
PROGRAM TO CALCULATE AREA OF CIRCLE.
#include<iostream.h>
#include<conio.h>
class circle
{
float radius, area; //data members
public:
circle()
{
cout<<"\n Enter the value of Radius : ";
cin>>radius;
}
void calculate();
void display();
};
inline void circle :: calculate()
{
area = 3.14 * radius * radius;
}
inline void circle :: display()
{
cout<<"\n Area of Circle : "<<area;
}
int main()
{
circle cr;
cr.calculate();
cr.display();
getch();
return 0;
}

Page 16 of 67
Page 17 of 67
PROGRAM TO ENTER STUDENT RECORD AND
CALCULATING TOTAL PERCENTAGE.
#include <iostream.h>
#include<conio.h>
class student
{
private:
char name[30];
int rollNo;
int total;
float perc;
public:
void getDetails(void);
void putDetails(void);
};
void student::getDetails(void)
{
cout<< "Enter name: " ;
cin>> name;
cout<< "Enter roll number: ";
cin>>rollNo;
cout<< "Enter total marks outof 500: ";
cin>> total;

perc=(float)total/500*100;
}
void student::putDetails(void)
{
cout<< "Student details:\n";
cout<< "Name:"<< name <<",Roll Number:" <<rollNo<< ",Total:" << total <<
",Percentage:"<< perc;
}

int main()
{
clrscr();

Page 18 of 67
student std;
std.getDetails();
std.putDetails();
getch();
return 0;
}

Page 19 of 67
PROGRAM TO SORT NUMBERS IN THEIR ASCENDING
ORDER

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ar[10],i,j,tmp;
cout<<"Enter the elements of array: ";
for(i=0;i<10;i++)
cin>>ar[i];
for(i=0;i<9;i++)
{
for(j=i+1;j<10;j++)
{
if(ar[i]>ar[j])
{
tmp=ar[i];
ar[i]=ar[j];
ar[j]=tmp;
}
}
}
cout<<"\tAfter sorting...\n";
for(i=0;i<10;i++)
cout<<ar[i]<<" ";
getch();
}

Page 20 of 67
Page 21 of 67
PROGRAM TO FIND NO. OF CHARACTERS IN A
STRING
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char a[80],b;
int i,n=0;
cout<<"Enter the string: ";
gets(a);
cout<<"Enter the character you want to know quantity of: ";
cin>>b;
for(i=0;a[i]!='\0';i++)
if(b==a[i])
n++;
cout<<"\n\t"<<b<<" has arrived "<<n<<" times in the string...";
getch();
}

Page 22 of 67
Page 23 of 67
PROGRAM TO FIND THE SUM AND AVERAGE SUM OF
ELEMENTS OF A MATRIX

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,a[10][10],t=0,row,col;
cout<<"Enter the number of rows of matrix(max 10): ";
cin>>row;
cout<<"Enter the number of columns of matrix(max 10): ";
cin>>col;
cout<<"Enter your matrix: ";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
cin>>a[i][j];
}
cout<<"Your entered matrix: \n\t\t";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
cout<<a[i][j]<<"\t";
cout<<"\n\t\t";
}
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
t=t+a[i][j];
}
cout<<"\nSum of the matrix: "<<t;
cout<<"\nAverage sum of the matrix: "<<(float)t/(row*col);
getch();
}

Page 24 of 67
Page 25 of 67
PROGRAM TO SEARCH THE POSITION OF A
CHARACTER IN A STRING

#include<iostream.h>
#include<conio.h>
int search(char arr[],int item,int l);
void main()
{
char ar[50],it;
int limit,pos;
clrscr();
cout<<"Enter the limit: ";
cin>>limit;
for(i=0;i<limit;i++)
cin>>ar[i];
cout<<"Enter the element to be search for: ";
cin>>it;
pos=search(ar,it,limit);
if(pos>-1)
cout<<"Search successful, position is "<<pos;
else
cout<<"Unsuccessful search";
getch();
}
int search(char arr[],int item,int l)
{
int ps=-1;
for(int i=0;i<l;i++)
{
if(arr[i]==item)
{
ps=i+1;
break;
}
}
return(ps)
}
Page 26 of 67
Page 27 of 67
PROGRAM TO FIND SUM OF DIAGONAL AND POST
DIAGONAL OF A 3X3 MATRIX

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],t=0,q=0;
cout<<"Enter the matrix: ";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
cin>>a[i][j];
}
cout<<"Your entered matrix: \n\t\t";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<a[i][j]<<"\t";
cout<<"\n\t\t";
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
t=t+a[i][j];
if((i+j)==2)
q=q+a[i][j];
}
}
cout<<"\nSum of the diagonal: "<<t;
cout<<"\nSum of the post diagonal: "<<q;
getch();
}

Page 28 of 67
Page 29 of 67
PROGRAM TO FIND SUM OF ROWS AND COLUMNS
OF A 3X3 MATRIX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,a[3][3],smr1=0,smr2=0,smr3=0,smc1=0,smc2=0,smc3=0;
cout<<"Enter the elements of the array: ";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[i][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if (j==0)
smc1=smc1+a[i][j];
else if(j==1)
smc2=smc2+a[i][j];
else if(j==2)
smc3=smc3+a[i][j];
if(i==0)
smr1=smr1+a[i][j];
else if(i==1)
smr2=smr2+a[i][j];
else if(i==2)
smr3=smr3+a[i][j];
}
}
cout<<"Sum of 1st row: "<<smr1;
cout<<"Sum of 2nd row: "<<smr2;
cout<<"Sum of 3rd row: "<<smr3;
cout<<"Sum of 1st column: "<<smc1;

Page 30 of 67
cout<<"Sum of 2nd column: "<<smc2;
cout<<"Sum of 3rd column: "<<smc3;
getch();
}

Page 31 of 67
PROGRAM TO FIND TRANSPOSE OF A MATRIX

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],i,j;
cout<<"Enter the Elements of matrix :";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cin>>a[i][j];
}
cout<<"Entered array :\n\t\t";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<a[i][j]<<"\t";
cout<<"\n\t\t";
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
b[j][i]=a[i][j];
}
cout<<"\nTranspose of the entered matrix :\n\t\t";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
cout<<b[i][j]<<"\t";
cout<<"\n\t\t";
}
getch();
}

Page 32 of 67
Page 33 of 67
PROGRAM TO CHECK WHETHER THE STRING IS
PALINDROME OR NOT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
clrscr();
char a[20],b[20];
int i,l;
cout<<"Enter the word: ";
gets(a);
for(i=0;i<20;i++)
b[i]=’\0’;
l=strlen(a);
for(i=0;a[i]!='\0';i++)
b[l-i-1]=a[i];
i=strcmp(a,b);
if(i==0)
cout<<"\n\tIt is a palindrome...";
else
cout<<"\n\tIt is not a palindrome.”;
getch();
}

Page 34 of 67
Page 35 of 67
PROGRAM TO IMPLEMENT PUSH AND POP IN A
STACK

#include<iostream.h>
#include<conio.h>
#include<process.h>
#define size 5
class stack
{
int a[size];
int top;
public:
stack()
{
top=-1;
}
void push(int);
int pop();
void display();
};
void stack::push(int item)
{
if(top==size-1)
cout<<endl<<"stack is overflow";
else
{
top++;
a[top]=item;
cout<<"element "<<item<<" has been pushed";
getch();
}
}
int stack::pop()
{
if(top==-1)
{

Page 36 of 67
cout<<endl<<"stack is underflow";
return-1;
}
else
{
int item=a[top];
top--;
cout<<"item "<<item<<" has been popped";
getch();
return item;
}
}
void stack::display()
{
int i;
cout<<"elements- ";
for(i=top;i>=0;i--)
cout<<a[i]<<"\t";
getch();
}
void main()
{
clrscr();
stack s1;
int choice,val;
do
{
clrscr();
cout<<endl<<"main menu";
cout<<endl<<"1.push";
cout<<endl<<"2.pop";
cout<<endl<<"3.display";
cout<<endl<<"4.Quit";
cout<<endl<<"enter your choice:";
cin>>choice;
switch(choice)
{

Page 37 of 67
case 1:cout<<endl<<"enter the value to be pushed:";
cin>>val;
s1.push(val);
break;
case 2:int i;
i=s1.pop();
if(i!=-1)
cout<<endl<<"the value popped is:"<<i;
break;
case 3:s1.display();
break;
case 4:exit(0);
}
}
while(1);
getch();
}

Page 38 of 67
Page 39 of 67
PROGRAM TO IMPLEMENT INSERT AND DELETE IN A
QUEUE

#include<iostreamn.h>
#include<conio.h>
#include<process.h>
#define size 5
class queue
{
int front, rear;
int a[size];
public:
queue()
{
front=0;rear=0;
}
void addQ(int item)
{
if(rear==size)
cout<<"Queue is Full"<<endl;
else
a[rear++]=item;
}
int delQ()
{
if(front==rear)
{ cout<<"Queue is empty"<<endl;
return 0; }
else
return a[front++];
}
void display()
{
int i;
if(front==rear)
{

Page 40 of 67
cout<<"\nEmpty Queue";
return;
}
else { for(i=front;i<rear;i++)
cout<<a[i]<<"\t";
} }
};
void main()
{
queue q1;
int item;
clrscr();
int choice;
do
{
clrscr();
cout<<endl<<"MAIN MENU";
cout<<endl<<" 1.Add\n 2.Delete\n 3.Display\n 4.Quit";
cout<<endl<<"Enter the choice";
cin>>choice;
switch(choice)
{
case 1:
cout<<endl<<"Enter an element";
cin>>item;
q1.addQ(item);
cout<<"element "<<item<<" has been added to queue";
break;
case 2:
item=q1.delQ();
cout<<"Deleted item from queue is : "<<item;
break;
case 3:
cout<<"elements of queue is- ";
q1.display();
break;
case 4:

Page 41 of 67
exit(0);
}
getch();
}while(1);
}

Page 42 of 67
PROGRAM TO IMPLEMENT PUSH AND POP IN STACK
USING LINKED LIST

#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int data;
node *next;
};

class stack
{
node *top;
public:
stack()
{
top=NULL;
}
void push();
void pop();
void display();
~stack();
};

void stack::push()
{
node *temp;
temp=new node;
cout<<"Enter data:";
cin>>temp->data;
temp->next=top;
top=temp;
cout<<"element "<<temp->data<<" has been pushed";
}

Page 43 of 67
void stack::pop()
{
if(top!=NULL)
{
node *temp=top;
top=top->next;
cout<<temp->data<<" element popped";
delete temp;
}
else
cout<<endl<<"Stack is Empty";
}

void stack::display()
{
node *temp=top;
cout<<"elements to display- ";
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
stack::~stack()
{
while(top!=NULL)
{
node *temp=top;
top=top->next;
delete temp;
}
}
int main()
{
clrscr();
stack st;

Page 44 of 67
int ch;
do
{
clrscr();
cout<<"Main Menu";
cout<<"\n1.Push Element";
cout<<endl<<"2.Pop Element";
cout<<endl<<"3.Display Stack";
cout<<endl<<"4.Exit";
cout<<endl<<"Enter your choice";
cin>>ch;
switch(ch)
{
case 1:st.push();
break;
case 2:st.pop();
break;
case 3:st.display();
break;
case 4:exit(0);
}
getch();
}
while(1);
getch();
}

Page 45 of 67
Page 46 of 67
PROGRAM TO IMPLEMEMT INSERT AND DELETE IN
QUEUE USING LINKED LIST

#include<iostream.h>
#include<conio.h>
#include<process.h>
struct node
{
int data;
node*next;
};
class queue
{
node *rear,*front;
public:
queue()
{
rear=NULL;front=NULL;
}
void qinsert();
void qdelete();
void qdisplay();
~queue();
};
void queue::qinsert()
{
node *temp;
temp=new node;
cout<<"Data:";
cin>>temp->data;
temp->next=NULL;
if(rear==NULL)
{
rear=temp;
front=temp;
}

Page 47 of 67
else
{
rear->next=temp;
rear=temp;
}
}
void queue::qdelete()
{
if(front!=NULL)
{
node*temp=front;
cout<<front->data<<endl<<"Element Deleted\n";
front=front->next;
delete temp;
if(front==NULL)
{
rear=NULL;
}
}
else
cout<<endl<<"Queue Empty..";
}
void queue::qdisplay()
{
node *temp=front;
while(temp!=NULL)
{
cout<<temp->data<<endl;
temp=temp->next;
}
}
queue::~queue()
{
while(front!=NULL)
{
node *temp=front;
front=front->next;

Page 48 of 67
delete temp;
}
}

int main()
{
clrscr();
queue obj;
char ch;
do
{
clrscr();
cout<<"Main Menu";
cout<<"\nA.Insert\nB.Delete\nC.Display\nD.Exit";
cout<<endl<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case 'A':
case 'a':
obj.qinsert();
break;
case 'B':
case 'b':
obj.qdelete();
break;
case 'C':
case 'c':
obj.qdisplay();
break;
case 'D':
case 'd':
exit(0);
}
getch();
}
while(1);

Page 49 of 67
}

Page 50 of 67
SQL-1

Page 51 of 67
Page 52 of 67
SQL-2

Page 53 of 67
Page 54 of 67
SQL-3

Page 55 of 67
SQL-4

Page 56 of 67
SQL- 5

Page 57 of 67
SQL-6

Page 58 of 67
SQL-7

Page 59 of 67
SQL-9

Page 60 of 67
SQL-10

Page 61 of 67
SQL-11

Page 62 of 67
SQL-12

Page 63 of 67
SQL-13

Page 64 of 67
Page 65 of 67
SQL-14

Page 66 of 67
SQL-15

Page 67 of 67

Das könnte Ihnen auch gefallen