Professional Documents
Culture Documents
AREA CALCULATION
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
struct point
intx,y;
};
point p[3];
float temp;
temp = 0.5*b*h;
float temp;
temp = (s1+s2+s3)/2;
float temp;
temp = (p1.x*(p2.y-p3.y))+(p2.x*(p3.y-p1.y))+(p3.x*(p1.y-p2.y));
void main()
floatbase,ht,a,b,c;
intch;
char c1;
do
{ clrscr();
cout<<"\t\t\t-------------------\n";
cout<<"\t\t\t-------------------\n";
cin>>ch;
switch(ch)
case 1:
cin>>base;
cin>>c;
area(base,c);
break;
case 2:
for(int i = 0;i<3;i++)
cin>>p[i].x;
cin>>p[i].y;
area(p[0],p[1],p[2]);
break;
case 3:
cin>>a;
cin>>b;
cin>>c;
area(a,b,c);
break;
cin>>c1;
}
while(c1 == 'Y' ||c1 == 'y');
OUTPUT:
2. ELECTRICITY BILL
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
structbl
int no;
char name[20];
floatunit,bill;
}a;
void main()
clrscr();
cout<<"Enter consumer number:";
cin>>a.no;
gets(a.name);
cin>>a.unit;
if(a.unit<=100)
a.bill=a.unit*0.4;
if(a.unit>100 &&a.unit<=200)
a.bill=(a.unit-100)*0.5+40;
if(a.unit>200 &&a.unit<=300)
a.bill=(a.unit-200)*0.75+90;
if(a.unit>300)
a.bill=(a.unit-300)*1+165;
cout<<"\nBill";
cout<<"\nConsumer No:"<<a.no;
cout<<"\nName:"<<a.name;
cout<<"\nUnits consumed:"<<a.unit;
cout<<"\nNet amount=Rs"<<a.bill;
getch();
OUTPUT:
3. STUDENT MARK & AVERAGE LIST
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
int i;
class student
private:
intadmno;
charsname[21];
float mark[5],total;
float calculate();
public:
voidtakedata();
voidshowdata();
}s;
float student::calculate()
float per;
total=0;
for(i=0;i<5;i++)
total+=mark[i];
per=total/5;
return per;
void student::showdata()
cout<<"\nAdmission no:"<<admno;
cout<<"\nName:"<<sname;
cout<<"\nMarks-";
for(i=0;i<5;i++)
cout<<"\nSubject"<<i+1<<":"<<mark[i];
cout<<"\nTotal="<<total;
cout<<"\nAverage="<<calculate();
void student::takedata()
cin>>admno;
cout<<"Enter name:";
gets(sname);
for(i=0;i<5;i++)
cin>>mark[i];
calculate();
showdata();
void main()
clrscr();
s.takedata();
getch();
OUTPUT:
4. AREA OF A CIRCLE USING ASSIGNMENT OPERATOR
#include<iostream.h>
#include<conio.h>
class circle
floatradius,area;
public:
circle(float r)
radius=r;
area=3.14*r*r;
circle(circle &c)
{
radius=c.radius+1;
area=3.14*radius*radius;
void display()
cout<<"\nRadius="<<radius;
cout<<"\nArea="<<area;
};
void main()
float rad;
clrscr();
cout<<"Enter radius:";
cin>>rad;
circle c1(rad);
c1.display();
circle c2(c1);
c2.display();
getch();
OUTPUT:
5. FINDING VOWELS, DIGITS, CONSONANTS,WHITE SPACES
#include<iostream.h>
#include<string.h>
#include<conio.h>
int main()
clrscr();
char line[150];
inti,v,c,d,s;
v=c=d=s=0;
cin.getline(line, 150);
for(i=0;line[i]!='\0';++i)
if(line[i]=='a'
|| line[i]=='e'
|| line[i]=='i'
|| line[i]=='o'
|| line[i]=='u'
|| line[i]=='A'
|| line[i]=='E'
|| line[i]=='I'
|| line[i]=='O'
|| line[i]=='U')
++v;
|| (line[i]>='A'&& line[i]<='Z'))
++c;
else if(line[i]>='0'&&c<='9')
++d;
++s;
getch();
return 0;
OUTPUT:
6. TELEPHONE BILL
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
classaddr
int block;
char street[20];
char city[20];
public:
void input()
cout<"Enter Address:\n";
cin>>block;
gets(city);
void output()
cout<<"Address :"<<block<<endl;
puts(street);
puts(city);
};
Class telephonebill
char name[100];
addr address;
longphone_no;
intcalls,rent;
floatcharge,subtotal,subcharge,total;
public:
telephonebill()
rent=500;
void input()
{
cout<<"Enter name:";
gets(name);
cin>>phone_no;
address.input();
cin>>calls;
voidcalbill()
charge =0.0;
if(calls<=150)charge=0.0;
else if(calls<=300)charge=(calls-150)*1.0;
else if(calls<=450)charge=150+((calls-450)*1.5);
else charge=375+((calls-450)*2.0);
subcharge=0.2*charge;
total=rent+charge+subcharge;
void output()
cout<<"\nName:"<<name;
cout<<"\nPhone Number:"<<phone_no;
cout<<"\nNumber of calls:"<<calls;
cout<<"\nBill is:"<<total<<"/-\n";
}
};
int n;
void main()
clrscr();
telephonebill t[10];
cout<<"\t\t\t----------------------\n";
cout<<"\t\t\tTelephone Bill\n";
cout<<"------------------------\n";
cin>>n;
for(int i=0;i<n;i++)
t[i].input();
t[i].calbill();
for(i=0;i<n;i++)
t[i].output();
getch();
OUTPUT:
7.Simple calculator
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
clrscr();
float a, b, res;
do
cout<<"1.Addition\n";
cout<<"2.Subtraction\n";
cout<<"3.Multiplication\n";
cout<<"4.Division\n";
cout<<"5.Exit\n\n";
cout<<"Enter Your Choice : ";
cin>>choice;
switch(choice)
cin>>a>>b;
res=a+b;
cout<<"Result = "<<res;
break;
cin>>a>>b;
res=a-b;
cout<<"Result = "<<res;
break;
cin>>a>>b;
res=a*b;
cout<<"Result = "<<res;
break;
cin>>a>>b;
res=a/b;
cout<<"Result = "<<res;
break;
break;
break;
}
cout<<"\n------------------------------------\n";
getch();
Output
#include <iostream.h>
#include <iomanip.h>
struct Time
intHrs;
int Min;
};
void main()
Time t1,t2,t3;
Time Larger(Time,Time); // prototype
voidDisplayTime(Time); // prototype
cout<<endl;
cin>>t1.Hrs;
cin>>t1.Min;
cin>>t2.Hrs;
cin>>t2.Min;
t3=Larger(t1,t2);
DisplayTime(t3);
Time temp;
if (tt1.Hrs>tt2.Hrs)
temp=tt1;
else
if (tt1.Hrs<tt2.Hrs)
temp=tt2;
else
if (tt1.Min>tt2.Min)
temp=tt1;
else
temp=tt2;
return temp;
voidDisplayTime(Time tt)
cout.fill('0');
cout<<setw(2)<<tt.Hrs<<":"
<<setw(2)<<tt.Min<<endl;
OUTPUT:
9. Copy constructor
#include<conio.h>
#include<iostream.h>
#include<string.h>
class student
int roll;
int age;
char name[30];
public:
student()
cout<<"\n Constructor:";
roll=10;
age =18;
strcpy(name,"Rahul");
student(student &s)
roll=s.roll;
age =s.age;
strcpy(name,s.name);
voidinput_void()
cin>>roll;
cin>>age;
cout<<"\n Enter name:";
cin>>name;
voidshow_data()
cout<<roll;
cout<<"\n Age:";
cout<<age;
cout<<"\n Name:";
cout<<name;
}};
void main()
clrscr();
student s;
s.show_data();
cout<<"\n";
student A(s);
A.show_data();
getch();
Output
10.Multiple Inheritance
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
class person
char name[21];
int age;
public:
voidindata()
gets(name);
cin>>age;
voidoutdata();
};
void person::outdata()
{
cout<<"\n\n";
cout<<"-";
class game {
chargame_name[20];
public:
void input()
cin.get();cin.getline(game_name,20);
void output()
};
{ floatTmarks;
introllno;
public:
charcalgrade()
{if(Tmarks>90)
return 'A';
else if(Tmarks>80&&Tmarks<=90)
return 'B';
else if(Tmarks>70&&Tmarks<=80)
return 'C';
else if(Tmarks>60&&Tmarks<=70)
return 'D';
else
return 'E';
void enter()
indata();
input();
cin>>Tmarks;
void display()
outdata();
output();
cout<<"\n\nGrade = "<<calgrade();
}
};
void main()
{ clrscr();
student A;
A.enter();
A.display();
getch();
Output:
#include<fstream.h>
#include<iomanip.h>
#include<conio.h>
// file of records
struct item
int code;
floatqty,price;
char name[20];
}it;
floatgtot=0;
voidcre()
int n;
ofstreamfout("item.dat", ios::binary|ios::app);
cin>>n;
for(int i=1;i<=n;i++)
cin>>it.code>>it.qty>>it.price>>it.name;
fout.write((char*)&it, sizeof(it));
fout.close();
void aces()
{
float tot;
ifstream fin("item.dat",ios::binary);
cout<<setw(6)<<"code"<<setw(20)<<"name"<<setw(7)<<"qty";
cout<<setw(7)<<"price"<<setw(7)<<"total"<<endl;
while(fin)
fin.read((char*)&it, sizeof(it));
if(fin)
tot = it.qty*it.price;
gtot+=tot;
cout<<setw(6)<<it.code<<setw(20)<<it.name<<setw(7)<<it.qty;
cout<<setw(7)<<it.price<<setw(7)<<tot<<endl;
void main()
clrscr();
cre();
aces();
getch();
}
OUTPUT:
12. Enter any line or character in a file and press * to exit the program .
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
void main()
charch;
clrscr();
ofstream f1("emp.txt");
while(1)
ch=getche();
if(ch=='*')
break;
if(ch==13)
{
cout<<"\n";
f1<<'\n';
f1<<ch;
f1.close();
getch();
Output
#include<fstream.h>
#include<conio.h>
void main()
clrscr();
int a[10]; float b[10];
ofstream student;
student.open("stud.txt");
student.close();
i=0;
charstr[80][80];
ifstreamstude;
stude.open("stud.txt",ios::in);
stude.seekg(0);
while(!stude.eof())
stude.getline(str[i],80);
cout<<str[i]<<"\n\n";
i++;
}
getch();
}
14. Selection Sort
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
void main()
clrscr();
int x[10],i,j,temp,low,pos;
for(i=0;i<10;i++)
cin>>x[i];
for(i=0;i<9;i++)
low=x[i];
pos=i;
for(j=i+1;j<10;j++)
if(low>x[j])
low=x[j];
pos=j;
temp=x[i];
x[i]=x[pos];
x[pos]=temp;
} // end of i for loop
// output phase
for(i=0;i<10;i++)
cout<<setw(4)<<x[i];
getch();
return ;
Output
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
cin>>size;
cin>>arr[i];
cin>>del;
if(arr[i]==del)
arr[j]=arr[j+1];
count++;
break;
if(count==0)
else
{
cout<<arr[i]<<" ";
getch();
Output
#include<iostream.h>
#include<conio.h>
intsmall,pos,temp;
for(inti=0;i<n;i++)
small=a[i];
pos=i;
for(int j=i;j<n;j++)
if(a[j]<small)
{
small=a[j];
pos=j;
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
for(i=0;i<n;i++)
cout<<a[i];
int ll,u1,mid;
int flag=0;
ll=0;u1=n-1;
while(ll<=u1)
mid= (ll+u1)/2;
if(item==a[mid])
flag++;
if(item<a[mid])
u1=mid-1;
else
ll=mid+1;
if(flag==0)
void main()
int a[20];
int n, item;
charch;
clrscr();
do
cout<<"\t\t**********************";
cin>>n;
for(inti=0;i<n;i++)
cin>>a[i];
sort(a,n);
cin>>item;
search(a,n,item);
cin>>ch;
}while(ch=='Y'||ch=='y');
getch();
}
inti,a[50],no,pos,size;
cout<<"Enter array size( Max:50 ) :: ";
cin>>size;
cout<<"\nEnter array elements :: \n";
for(i=0;i<size;i++)
{
cout<<" "<<a[i]<<" ";
}
if(pos>size)
{
cout<<"\nThis is out of range.\n";
}
else
{
cout<<"\nEnter number to be inserted :: ";
cin>>no;
--pos;
for(i=size;i>=pos;i--)
{
a[i+1]=a[i];
}
a[pos]=no;
for(i=0;i<size+1;i++)
{
cout<<" "<<a[i]<<" ";
}
}
cout<<"\n";
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
clrscr();
int a[50],n,i,j,temp;
cin>>n;
cin>>a[i];
for(i=1;i<n;++i)
for(j=0;j<(n-i);++j)
if(a[j]>a[j+1])
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
for(i=0;i<n;++i)
cout<<" "<<a[i];
getch();
OUTPUT:
19. MERGING OF AN ARRAY
#include<iostream.h>
#include<conio.h>
void Merge(int A[], int B[], int C[], int N, int M, int&K);
int main()
clrscr();
cin>>n;
cin>>A[i];
cin>>m;
for(i=0;i<m;i++)
cin>>B[i];
Merge(A,B,C,n,m,k);
for(i=0;i<k;i++)
cout<<C[i]<<" ";
getch();
return 0;
void Merge(int A[], int B[], int C[], int N, int M, int&K)
{
int I=0, J=M-1;
K=0;
if (A[I]<B[J])
C[K++]=A[I++];
else if (A[I]>B[J])
C[K++]=B[J--];
else
C[K++]=A[I++];
J--;
C[K++]=A[T];
for ( T=J;T>=0;T--)
C[K++]=B[T];
OUTPUT:
20. Stack using Push & Pop
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
struct node
{
char name[20];
int age;
node *link;
}*ptr=NULL,*save=NULL;
class stack
{
node *top;
public:
stack()
{top=NULL;
}
voidstackpush();
voidstackpop();
void display();
}st;
void stack::stackpush()
{ptr=new node;
if(ptr==NULL)
{cout<<"Overflow ";
}
else
{cout<<"Enter the name ";
gets(ptr->name);
cout<<"Enter the age ";
cin>>ptr->age;
ptr->link=NULL;
if(top==NULL)
{top=ptr;
}
else
{ptr->link=top;
top=ptr;
}
}
}
void stack::stackpop()
{if(top==NULL)
{cout<<"Underflow ";
}
else
{save=top;
top=top->link;
cout<<"Name ";
puts(save->name);
cout<<"Age "<<save->age;
delete save;
}
}
void stack::display()
{if(top==NULL)
{cout<<"No elements.."<<endl;
}
else
{ptr=top;
while(ptr!=NULL)
{cout<<"\nName ";
puts(ptr->name);
cout<<"Age "<<ptr->age;
ptr=ptr->link;
}
}
}
void main()
{clrscr();
intch;
X:
cout<<"\nEnter your choice\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT\n";
cin>>ch;
switch(ch)
{case 1:st.stackpush();
goto X;
case 2:st.stackpop();
goto X;
case 3:st.display();
goto X;
default:cout<<"Wrong choice ";
goto X;
case 4:exit(0);
}
getch();
}
Output
21. Queue using Insert and Delete
#include <iostream>
#include<conio.h>
#include<stdlib.h>
#define MAX_SIZE 100
int main() {
int item, choice, i;
intarr_queue[MAX_SIZE];
int rear = 0;
int front = 0;
int exit = 1;
return 0;
}
Output
22. Circular Queue
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
class Cir_Q
int info[100];
int front;rear;
public:
Cir_Q()
front=rear=0;
void insertion(int);
int deletion();
void disp();
};
if((rear+1)%100==front)
else
rear=(rear+1)%100;
info[rear]=no;
int Cir_Q::deletion()
int no=-999;
if(front==rear)
else
{
front=(front+1)%100;
no=info[front];
return(no);
void Cir_Q::disp()
int i;
if(front==rear)
else
i=front;
do
i=(i+1)%100;
cout<<info[i]<<"\n";
}while(i!=rear);
void main()
{
Cir_Q q;
int n,ch;
do
clrscr();
cout<<endl<<"1.Insertion\n";
cout<<"2.Deletion\n";
cout<<"3.Display\n";
cout<<"4.Quit\n";
cin>>ch;
switch(ch)
case 1:
cin>>n;
q.insertion(n);
break;
case 2:n=q.deletion();
if(n!=-999)
break;
case 3:q.disp();
break;
case 4:exit(0);
}getch();
}while(ch!=4);
Output
SQL QUERIES
SQL: 1
1. Write a SQL queries for the following on the basis of given table student.
FORM DESIGN:
3. To display all the records which has sno between 50000 to 70000.
SQL: 2
2. Write SQL queries for the following on the basis of given table employees.
FORM DESIGN:
1. Display empno & ename of all employees from the table employees.
5. List the detail of those employees whose salary is between 2000 to 5000.
SQL: 3
3. Write SQL queries for the following on the basis of given table sports.
FORM DESIGN:
1. Display the names of the students who are getting grade ‘c’ in sports.
SQL: 4
4. Write SQL queries for the following on the basis of given table teacher.
FORM DESIGN:
4. Display all the names of those teachers who is earning salary of more than
20000.
5. Display all the names of those teachers who is not less than 40 years.
SQL: 5
5. Write SQL queries for the following on the basis of given table pet.
FORM DESIGN:
1. Display all the records of Tommy.
4. Display all the records of those pets who is having sex null.
To display the details of Item whose Price is in the range of 3500 to 55000 (Both
values included).
SELECT * FROM ITEM WHERE PRICE BETWEEN 35000 AND 55000;
Delhi
Mumbai
Banglore
New Delhi
Mumbai
SELECT A.SenderName, B.RecName FROM Sender A, Recipient B WHERE
A.SenderID=B.SenderID AND B.RecCity=’Mumbai’;
SenderName RecName
R Jain H Singh
S Jha P K Swamy
ND08 S Mahajan
ND48 S Tirupati