SlideShare a Scribd company logo
1 of 52
COMPUTER SCIENCE
Practical File
On
C++ PROGRAMS
&
MY SQL
ROLL NO . :-
Class –
Submitted By :-
C++ PROGRAMS
INDEX
Q1.Enter name , age and salary and display it by using outside
the class member .
Q2. Program which gives the squares of all the odd numbers
stored in an array .
Q3.Program to store numbers in an array and allow user to
enter any number which he/she wants to find in array .(Binary
Search)
Q4.Program for copy constructor .
Q5.Enter numbers in an array in any order and it will give the
output of numbers in ascending order .
Q6. Enter any number from 2 digit to 5 digit and the output
will be the sum of all the distinguish digits of the numbers .
Q7.Enter rows and columns and the output will be the sum of
the diagonals .
Q8. Enter item no. , price and quantity in a class .
Q9.Enter any line or character in a file and press * to exit the
program .
Q10. Program will read the words which starts from vowels
stored in a file .
Q11. Enter employee no , name , age , salary and store it in a
file.
Q12. Deleting the information of employee by entering the
employee number .
Q13. Enter any number and its power and the output will the
power of the number .
Q14. Enter 3 strings and the output will show the longest
string and the shortest string .
Q.15 Enter any number and the output will be all the prime
numbers up to that number .
Q16. Selection sort
Q17. Using loop concept the program will give the output of
numbers making a right triangle .
Q18. Program for Stacks and Queue .
Q.19Enter two arrays and the output will be the merge of two
arrays .
Q20. Sequence sort .
Q.SQL QUERIES AND OUTPUT .
Q1.Enter name , age and salary and display it by using outside
the class member .
#include<iostream.h>
#include<conio.h>
class abc
{
//private:
char n[20];
int a;
float sal;
public:
void getdata(void)
{
cout<<"nEnter name ";
cin>>n;
cout<<"nEnter age ";
cin>>a;
cout<<"nEnter salary ";
cin>>sal;
}
void putdata(void)
{
cout<<"nnNAME IS "<<n;
cout<<"nAGE IS "<<a;
cout<<"nSALARY IS "<<sal;
}
};
main()
{
abc p;
clrscr();
p.getdata();
p.putdata();
getch();
}
OUTPUT
Q2. Program which gives the squares of all the odd numbers
stored in an array .
#include<iostream.h>
#include<conio.h>
main()
{
int a[20],i,x;
clrscr();
cout<<"nEnter no of elements ";
cin>>x;
for(i=0;i<x;i++)
{
cout<<"nEnter no ";
cin>>a[i];
}
cout<<"nnArr1: ";
for(i=0;i<x;i++)
cout<<" "<<a[i];
cout<<"nnArr1: ";
for(i=0;i<x;i++)
{
if(a[i]%2==1)
a[i]=a[i]*a[i];
cout<<" "<<a[i];
}
getch();
}
OUTPUT
Q3.Program to store numbers in an array and allow user to
enter any number which he/she wants to find in array .(Binary
Search)
#include<iostream.h>
#include<conio.h>
main()
{
int a[20],n,i,no,low=0,high,mid,f=0;
clrscr();
cout<<"nEnter no of elements ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"nEnter no ";
cin>>a[i];
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
cout<<"nEnter no to be search ";
cin>>no;
high=n-1;
while(low<=high && f==0)
{
mid=(low+high)/2;
if(a[mid]==no)
{
cout<<"nn"<<no<<" store at "<<mid+1;
f=1;
break;
}
else if(no>a[mid])
low=mid+1;
else
high=mid-1;
}
if(f==0)
cout<<"nn"<<no<<" does not exist";
getch();
}
OUTPUT
Q4.Program for copy constructor .
#include<iostream.h>
#include<conio.h>
#include<string.h>
class data
{
char n[20];
int age;
float sal;
public:
data(){}
data(char x[],int a,float k)
{
strcpy(n,x);
age=a;
sal=k;
}
data(data &p)
{
strcpy(n,p.n);
age=p.age;//+20;
sal=p.sal;//+1000;
}
display()
{
cout<<"nnNAME : "<<n;
cout<<"nnAGE : "<<age;
cout<<"nnSalary: "<<sal;
}
};
main()
{
clrscr();
data d("ajay",44,5000); //implicit caling
data d1(d);
data d2=d;
data d3;
d3=d2;
d.display();
d1.display();
d2.display();
d3.display();
getch();
}
OUTPUT
Q5.Enter numbers in an array in any order and it will give the
output of numbers in ascending order .(Bubble Sort)
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,t;
clrscr();
cout<<"nEnter no of elements in A ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"nEnter no ";
cin>>a[i];
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
for(i=0;i<n;i++)
for(j=0;j<n-i-1;j++)
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
getch();
}
OUTPUT
Q6. Enter any number from 2 digit to 5 digit and the output
will be the sum of all the distinguish digits of the numbers .
#include<iostream.h>
#include<conio.h>
main()
{
int a=0,b=0,c;
clrscr();
cout<<"nEnter value for A ";
cin>>a;
while(a>0) // for(;a>0;) or for(i=a;i>0;i=i/10)
{
c=a%10;
b=b+c;
a=a/10;
}
cout<<"nSum of digits "<<b;
getch();
}
OUTPUT
Q7.Enter rows and columns and the output will be the sum of
the diagonals .
#include<iostream.h>
#include<conio.h>
main()
{
int a[10][10],i,j,r,c;
clrscr();
cout<<"nEnter no of rows ";
cin>>r;
cout<<"nEnter no of Col ";
cin>>c;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
{
cout<<"nEnter no ";
cin>>a[i][j];
}
int sum=0,sum1=0;
for(i=0;i<r;i++)
{
cout<<"n";
for(j=0;j<c;j++)
{
cout<<" "<<a[i][j];
/// if(i==j) //&& a[i][j]>0)
// cout<<a[i][j];
// else
// cout<<" ";
//sum=sum+a[i][j];
/* if(i+j==r-1)// && a[i][j]>0)
cout<<a[i][j];
else
cout<<" "; */
if(i==j)
sum1=sum1+a[i][j];
}
}
for(i=0;i<r;i++)
{
cout<<"n";
for(j=0;j<c;j++)
{
// cout<<" "<<a[i][j];
/* if(i==j) //&& a[i][j]>0)
cout<<a[i][j];
else
cout<<" ";*/
//sum=sum+a[i][j];
if(i+j==r-1)// && a[i][j]>0)
// cout<<a[i][j];
// else
// cout<<" ";
sum=sum+a[i][j];
}
}
cout<<"nnFirst diagonal sum "<<sum1;
cout<<"nnSecond diagonal sum "<<sum;
getch();
}
OUTPUT
Q8. Enter item no. , price and quantity in a class .
#include<iostream.h>
#include<conio.h>
class dd
{
char item[20];
int pr,qty;
public:
void getdata();
void putdata();
};
void dd::getdata()
{
cout<<"nEnter item name ";
cin>>item;
cout<<"nEnter price ";
cin>>pr;
cout<<"nEnter quantity ";
cin>>qty;
}
void dd::putdata()
{
cout<<"nnItem name:"<<item;
cout<<"nnPrice: "<<pr;
cout<<"nnQty:"<<qty;
}
main()
{
dd a1,o1,k1;
clrscr();
a1.getdata();
o1.getdata();
k1.getdata();
a1.putdata();
o1.putdata();
k1.putdata();
getch();
}
OUTPUT
Q9.Enter any line or character in a file and press * to exit the
program .
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
main()
{
char ch;
clrscr();
ofstream f1("emp"); //implicit
//ofstream f1;
//f1.open("emp",ios::out); //explicit
cout<<"nEnter char ";
while(1) //infinity
{
ch=getche(); // to input a single charactor by keybord.
if(ch=='*')
break;
if(ch==13)
{
cout<<"n";
f1<<'n';
}
f1<<ch;
}
f1.close();
//getch();
}
OUTPUT
Q10. Program will read the words which starts from vowels
stored in a file .
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
main()
{
char ch[80];
int cnt=0;
clrscr();
ifstream f1("emp");
ofstream f2("temp");
while(!f1.eof())
{
f1>>ch;
cout<<ch<<"n";
if(ch[0]=='a' || ch[0]=='e' || ch[0]=='o' || ch[0]=='i' || ch[0]=='u')
f2<<"n"<<ch;
}
f1.close();
f2.close();
cout<<"nnName start with vowels nn";
f1.open("temp",ios::in);
while(f1) //while(!f1.eof())
{
f1>>ch;
cout<<"n"<<ch;
if(f1.eof())
break;
}
f1.close();
getch();
}
OUTPUT
Q11. Enter employee no , name , age , salary and store it in a
file.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
int row=5,col=2;
class abc
{
private:
int empno;
char n[20];
int age;
float sal;
public:
void getdata()
{
char ch;
cin.get(ch); // To empty buffer
cout<<"nEnter employee no ";
cin>>empno;
cout<<"nEnter name ";
cin>>n;
cout<<"nEnter age ";
cin>>age;
cout<<"nEnter salary ";
cin>>sal;
}
void putdata()
{
// gotoxy(col,row);
cout<<"n"<<empno;
// gotoxy(col+10,row);
cout<<"t"<<n;
// gotoxy(col+25,row);
cout<<"t"<<age;
// gotoxy(col+35,row);
cout<<"t"<<sal;
// row++;
}
};
main()
{
clrscr();
abc p,p1;
fstream f1("emp5.txt",ios::in|ios::out|ios::binary);
int i;
for(i=0;i<3;i++)
{
p.getdata();
f1.write((char *)&p,sizeof(p));
}
cout<<"nnEMPNOtNAMEtAGEtSALARYn";
f1.seekg(0);
//f1.clear();
//clrscr();
for(i=0;i<3;i++)
{
f1.read((char*)&p1,sizeof(p1));
p1.putdata();
}
f1.close();
getch();
}
OUTPUT
Q12. Deleting the information of employee by entering the
employee number .
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
class abc
{
private:
int empno;
char n[20];
int age;
float sal;
public:
void getdata()
{
cout<<"nEnter employee no ";
cin>>empno;
cout<<"nEnter name ";
cin>>n;
cout<<"nEnter age ";
cin>>age;
cout<<"nEnter salary ";
cin>>sal;
}
void putdata()
{
cout<<"nn"<<empno<<"t"<<n<<"t"<<age<<"t"<<sal;
}
int get_empno()
{
return empno;
}
};
main()
{
abc p,p1;
clrscr();
ifstream f1("emp5.txt",ios::in|ios::binary);
ofstream f2("temp",ios::out|ios::binary);
int i,emp;
cout<<"nnNAMEtAGEtSALARY";
f1.clear();
f1.seekg(0);
//for(i=0;i<4;i++)
while(!f1.eof())
{
f1.read((char*)&p1,sizeof(p1));
if(f1.eof())
break;
p1.putdata();
}
cout<<"nEnter employee no ";
cin>>emp;
f1.clear();
f1.seekg(0);
//while(f1)
while(!f1.eof())
{
f1.read((char*)&p1,sizeof(p1));
if(f1.eof())
break;
if(emp!=p1.get_empno())
f2.write((char*)&p1,sizeof(p1));
}
f1.close();
f2.close();
remove("emp5.txt");
rename("temp","emp5.txt");
f1.open("emp5.txt",ios::in|ios::binary);
cout<<"nnNAMEtAGEtSALARY";
f1.seekg(0);
//for(i=0;i<3;i++)
while(!f1.eof())
{
f1.read((char*)&p1,sizeof(p1));
if(f1.eof())
break;
p1.putdata();
}
f1.close();
getch();
}
OUTPUT
Q13. Enter any number and its power and the output will the
power of the number .
#include<iostream.h>
#include<conio.h>
#include<math.h>
#define CUBE(a,b) pow(a,b)
//a>b?a:b
main()
{
int x,y,z;
clrscr();
cout<<"nEnter base value ";
cin>>x;
cout<<"nEnter power ";
cin>>y;
z=CUBE(x,y);
cout<<"n"<<z;
getch();
}
OUTPUT
Q14. Enter 3 strings and the output will show the longest
string and the shortest string .
#include<iostream.h>
#include<conio.h>
#include<string.h>
main()
{
char n[20],n1[20],n2[20];
int l1,l2,l3;
clrscr();
cout<<"nEnter String1 ";
cin>>n;
cout<<"nEnter String2 ";
cin>>n1;
cout<<"nEnter String3 ";
cin>>n2;
l1=strlen(n);
l2=strlen(n1);
l3=strlen(n2);
(l1>l2 && l1>l3) ?cout<<"nLong: "<<n:(l2>l1 && l2>l3) ? cout<<"nLong: "<<n1
:cout<<"nLong: "<<n2;
(l1<l2 && l1<l3)?cout<<"nshort:"<<n:(l2<l1 && l2<l3)?
cout<<"nshort:"<<n1:cout<<"nshort:"<<n2;
getch();
}
OUTPUT
Q.15 Enter any number and the output will be all the prime
numbers up to that number .
#include<iostream.h>
#include<conio.h>
main()
{
int n,i,j,p;
clrscr();
cout<<"nEnter no of N ";
cin>>n;
for(i=1;i<=n;i++)
{
p=0;
for(j=2;j<=i/2;j++)
if(i%j==0)
p=1;
if(p==0)
cout<<" "<<i;
}
getch();
}
OUTPUT
Q16. Selection sort
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,t,min,p;
clrscr();
cout<<"nEnter no of elements in A ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"nEnter no ";
cin>>a[i];
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
for(i=0;i<n;i++)
{
min=a[i];
p=i;
for(j=i;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
p=j;
}
}
t=a[i];
a[i]=a[p];
a[p]=t;
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
getch();
}
OUTPUT
Q17. Using loop concept the program will give the output of
numbers making a right triangle .
#include<iostream.h>
#include<conio.h>
main()
{
int i,j;
clrscr();
for(i=1;i<=4;i++)
{
cout<<"nn";
for(j=1;j<=i;j++)
cout<<" "<<i;
}
getch();
}
OUTPUT
Q18. Program for Stacks and Queue .
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
struct queue
{
int x;
queue *next;
}*front=NULL,*rear;
void insert(int);
void delnode();
void display();
void main()
{
int a,ch;
clrscr();
do
{
cout<<"nEnter 1 for Insert";
cout<<"nEnter 2 for Delete";
cout<<"nEnter 3 for display";
cout<<"nEnter 4 for exit";
cout<<"nnEnter your choice ";
cin>>ch;
switch(ch)
{
case 1: cout<<"nEnter no for insert ";
cin>>a;
insert(a);
break;
case 2: delnode();
break;
case 3: display();
break;
case 4: exit(0);
}
}
while(1);
getch();
}
void insert(int no) // char str[]
{
queue *ptr;
ptr=new queue; // strcpy(ptr->n,str)
// ptr=(struct queue*)malloc(sizeof(struct queue));
ptr->x=no;
ptr->next=NULL;
if(front==NULL)
{
front=ptr;
rear=ptr;
}
else
{
rear->next=ptr;
rear=ptr;
}
}
void delnode()
{
int p;
queue *ptr;
if(front==NULL)
{
cout<<"nnQueue is Empty";
return;
}
p=front->x; //strcpy(p,front->n)
ptr=front;
front=front->next;
delete ptr;
cout<<"nndeleted element "<<p<<"n";
}
void display()
{
queue *ptr;
cout<<"nQueue now:- n";
for(ptr=front;ptr!=NULL;ptr=ptr->next)
cout<<" "<<ptr->x;
}
OUTPUT
Q.19Enter two arrays and the output will be the merge of two
arrays .
# include <iostream.h>
# include <conio.h>
main()
{
int arr1[100],arr2[100],arr3[100],c,i=0,j=0,k=0,size1,size2;
clrscr();
cout<<"n enter no of element of arr1 ";
cin>>size1;
for (i=0;i<size1;i++)
{
cout<<"n enter no. ";
cin>>arr1[i];
}
cout<<"n enter no of element of arr2 ";
cin>>size2;
for (i=0;i<size2;i++)
{
cout<<"n enter no. ";
cin>>arr2[i];
}
cout<<"n arr1 ";
for (i=0;i<size1;i++)
cout<<" "<<arr1[i];
cout<<"n arr2 ";
for (i=0;i<size2;i++)
cout<<" "<<arr2[i];
i=0;j=0;k=0;
while (i<size1 && j<size2)
{
if (arr1[i]<arr2[j])
arr3[k++]=arr1[i++];
else if (arr2[j]<arr1[i])
arr3[k++]=arr2[j++];
else
i++;
}
while (i<size1)
arr3[k++]=arr1[i++];
while (j<size2)
arr3[k++]=arr2[j++];
cout<<"n arr3 ";
for (i=0;i<k;i++)
cout<<" "<<arr3[i];
getch();
}
OUTPUT
Q20.Sequence Sort (Insertion Sort)
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20],n,i,j,t;
clrscr();
cout<<"nEnter no of elements in A ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"nEnter no ";
cin>>a[i];
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
cout<<"nn";
for(i=0;i<n;i++)
cout<<" "<<a[i];
getch();
}
OUTPUT
My SQL
School homework
QUERIES
Ques 1. mysql> select ename ,sal,dept_no from empl
where commission is null ;
Ques 2. mysql> select ename ,sal,dept_no from empl where
commission is not null;
Ques 3. mysql> select * from empl where sal between
1000 and 2500;
Ques 4. mysql> select ename from empl where ename like
‘a%’ ;
Ques 5 . mysql> select concat (ename,dept_no)as “name
dept” from empl;
Ques 6 . mysql> select lower(ename) “empl name” from
empl;
Ques 7 . mysql> select upper(ename) “empl name” from
empl;
Ques 8 . mysql> select substr(job,1,5) from empl where
empno=8888 or empno=8900;
Ques 9 . mysql> select job,instr (job,’le’)as “le in ename”
from empl;
Ques 10 . mysql> select ename, length (ename)as “name
length” from empl where empno <=8888 ;
OUTPUT QUESTIONS
Ques 1 . mysql> select left(‘Informatices practices’,5) ;
Ques 2 . mysql> select right (‘Informatices practices’,5);
Ques 3 . mysql> select mid(‘Informatices practices’,6,9);
Ques 4 . mysql> select ltrim(‘ akshit’);
Ques 5 . mysql> select rtrim(‘akshit ‘);
CS & SQL Practical File C++ Programs

More Related Content

What's hot

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File Harjinder Singh
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Rushil Aggarwal
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C LanguageRAJWANT KAUR
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and PointersPrabu U
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and UnionsDhrumil Patel
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++Sujan Mia
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarSivakumar R D .
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methodsnarmadhakin
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Sanjit Shaw
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and DestructorKamal Acharya
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in cBUBT
 

What's hot (20)

Data Structures Practical File
Data Structures Practical File Data Structures Practical File
Data Structures Practical File
 
Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++Computer science Investigatory Project Class 12 C++
Computer science Investigatory Project Class 12 C++
 
Practical File of C Language
Practical File of C LanguagePractical File of C Language
Practical File of C Language
 
Structures and Pointers
Structures and PointersStructures and Pointers
Structures and Pointers
 
Function in C program
Function in C programFunction in C program
Function in C program
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Getters_And_Setters.pptx
Getters_And_Setters.pptxGetters_And_Setters.pptx
Getters_And_Setters.pptx
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Constructors and Destructor in C++
Constructors and Destructor in C++Constructors and Destructor in C++
Constructors and Destructor in C++
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Structure of C++ - R.D.Sivakumar
Structure of C++ - R.D.SivakumarStructure of C++ - R.D.Sivakumar
Structure of C++ - R.D.Sivakumar
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Polymorphism in c++(ppt)
Polymorphism in c++(ppt)Polymorphism in c++(ppt)
Polymorphism in c++(ppt)
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Constructor and Destructor
Constructor and DestructorConstructor and Destructor
Constructor and Destructor
 
Chapter 5 exercises Balagurusamy Programming ANSI in c
Chapter 5 exercises Balagurusamy Programming ANSI  in cChapter 5 exercises Balagurusamy Programming ANSI  in c
Chapter 5 exercises Balagurusamy Programming ANSI in c
 
Strings
StringsStrings
Strings
 

Similar to CS & SQL Practical File C++ Programs

c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaonyash production
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ reportvikram mahendra
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQLvikram mahendra
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual finalAhalyaR
 
a) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfa) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfanuradhasilks
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operatorsHarleen Sodhi
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfMuhammadMaazShaik
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4Abed Bukhari
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101premrings
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab FileKandarp Tiwari
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 

Similar to CS & SQL Practical File C++ Programs (20)

Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
 
C++ file
C++ fileC++ file
C++ file
 
Arrays
ArraysArrays
Arrays
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
project report in C++ programming and SQL
project report in C++ programming and SQLproject report in C++ programming and SQL
project report in C++ programming and SQL
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
a) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfa) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdf
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
 
sodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdfsodapdf-converted into ppt presentation(1).pdf
sodapdf-converted into ppt presentation(1).pdf
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Whats new in_csharp4
Whats new in_csharp4Whats new in_csharp4
Whats new in_csharp4
 
54602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee0108310154602399 c-examples-51-to-108-programe-ee01083101
54602399 c-examples-51-to-108-programe-ee01083101
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
java-programming.pdf
java-programming.pdfjava-programming.pdf
java-programming.pdf
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 

Recently uploaded

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

CS & SQL Practical File C++ Programs

  • 1. COMPUTER SCIENCE Practical File On C++ PROGRAMS & MY SQL ROLL NO . :- Class – Submitted By :- C++ PROGRAMS
  • 2. INDEX Q1.Enter name , age and salary and display it by using outside the class member . Q2. Program which gives the squares of all the odd numbers stored in an array . Q3.Program to store numbers in an array and allow user to enter any number which he/she wants to find in array .(Binary Search) Q4.Program for copy constructor . Q5.Enter numbers in an array in any order and it will give the output of numbers in ascending order . Q6. Enter any number from 2 digit to 5 digit and the output will be the sum of all the distinguish digits of the numbers . Q7.Enter rows and columns and the output will be the sum of the diagonals . Q8. Enter item no. , price and quantity in a class . Q9.Enter any line or character in a file and press * to exit the program . Q10. Program will read the words which starts from vowels stored in a file . Q11. Enter employee no , name , age , salary and store it in a file.
  • 3. Q12. Deleting the information of employee by entering the employee number . Q13. Enter any number and its power and the output will the power of the number . Q14. Enter 3 strings and the output will show the longest string and the shortest string . Q.15 Enter any number and the output will be all the prime numbers up to that number . Q16. Selection sort Q17. Using loop concept the program will give the output of numbers making a right triangle . Q18. Program for Stacks and Queue . Q.19Enter two arrays and the output will be the merge of two arrays . Q20. Sequence sort . Q.SQL QUERIES AND OUTPUT . Q1.Enter name , age and salary and display it by using outside the class member . #include<iostream.h> #include<conio.h> class abc
  • 4. { //private: char n[20]; int a; float sal; public: void getdata(void) { cout<<"nEnter name "; cin>>n; cout<<"nEnter age "; cin>>a; cout<<"nEnter salary "; cin>>sal; } void putdata(void) { cout<<"nnNAME IS "<<n; cout<<"nAGE IS "<<a; cout<<"nSALARY IS "<<sal; } }; main() { abc p; clrscr(); p.getdata(); p.putdata(); getch(); }
  • 6. Q2. Program which gives the squares of all the odd numbers stored in an array . #include<iostream.h> #include<conio.h> main() { int a[20],i,x; clrscr(); cout<<"nEnter no of elements "; cin>>x; for(i=0;i<x;i++) { cout<<"nEnter no "; cin>>a[i]; } cout<<"nnArr1: "; for(i=0;i<x;i++) cout<<" "<<a[i]; cout<<"nnArr1: "; for(i=0;i<x;i++) { if(a[i]%2==1) a[i]=a[i]*a[i]; cout<<" "<<a[i]; } getch(); }
  • 8. Q3.Program to store numbers in an array and allow user to enter any number which he/she wants to find in array .(Binary Search) #include<iostream.h> #include<conio.h> main() { int a[20],n,i,no,low=0,high,mid,f=0; clrscr(); cout<<"nEnter no of elements "; cin>>n; for(i=0;i<n;i++) { cout<<"nEnter no "; cin>>a[i]; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; cout<<"nEnter no to be search "; cin>>no; high=n-1; while(low<=high && f==0) { mid=(low+high)/2; if(a[mid]==no) { cout<<"nn"<<no<<" store at "<<mid+1; f=1; break; } else if(no>a[mid]) low=mid+1; else high=mid-1; } if(f==0) cout<<"nn"<<no<<" does not exist"; getch(); }
  • 10. Q4.Program for copy constructor . #include<iostream.h> #include<conio.h> #include<string.h> class data { char n[20]; int age; float sal; public: data(){} data(char x[],int a,float k) { strcpy(n,x); age=a; sal=k; } data(data &p) { strcpy(n,p.n); age=p.age;//+20; sal=p.sal;//+1000; } display() { cout<<"nnNAME : "<<n; cout<<"nnAGE : "<<age; cout<<"nnSalary: "<<sal; } }; main() { clrscr(); data d("ajay",44,5000); //implicit caling data d1(d); data d2=d; data d3; d3=d2; d.display(); d1.display(); d2.display();
  • 11. d3.display(); getch(); } OUTPUT Q5.Enter numbers in an array in any order and it will give the output of numbers in ascending order .(Bubble Sort)
  • 12. #include<iostream.h> #include<conio.h> void main() { int a[20],n,i,j,t; clrscr(); cout<<"nEnter no of elements in A "; cin>>n; for(i=0;i<n;i++) { cout<<"nEnter no "; cin>>a[i]; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; for(i=0;i<n;i++) for(j=0;j<n-i-1;j++) if(a[j]>a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; getch(); } OUTPUT
  • 13. Q6. Enter any number from 2 digit to 5 digit and the output will be the sum of all the distinguish digits of the numbers . #include<iostream.h> #include<conio.h>
  • 14. main() { int a=0,b=0,c; clrscr(); cout<<"nEnter value for A "; cin>>a; while(a>0) // for(;a>0;) or for(i=a;i>0;i=i/10) { c=a%10; b=b+c; a=a/10; } cout<<"nSum of digits "<<b; getch(); } OUTPUT Q7.Enter rows and columns and the output will be the sum of the diagonals . #include<iostream.h> #include<conio.h> main() {
  • 15. int a[10][10],i,j,r,c; clrscr(); cout<<"nEnter no of rows "; cin>>r; cout<<"nEnter no of Col "; cin>>c; for(i=0;i<r;i++) for(j=0;j<c;j++) { cout<<"nEnter no "; cin>>a[i][j]; } int sum=0,sum1=0; for(i=0;i<r;i++) { cout<<"n"; for(j=0;j<c;j++) { cout<<" "<<a[i][j]; /// if(i==j) //&& a[i][j]>0) // cout<<a[i][j]; // else // cout<<" "; //sum=sum+a[i][j]; /* if(i+j==r-1)// && a[i][j]>0) cout<<a[i][j]; else cout<<" "; */ if(i==j) sum1=sum1+a[i][j]; } } for(i=0;i<r;i++) { cout<<"n"; for(j=0;j<c;j++) { // cout<<" "<<a[i][j]; /* if(i==j) //&& a[i][j]>0) cout<<a[i][j]; else cout<<" ";*/ //sum=sum+a[i][j]; if(i+j==r-1)// && a[i][j]>0)
  • 16. // cout<<a[i][j]; // else // cout<<" "; sum=sum+a[i][j]; } } cout<<"nnFirst diagonal sum "<<sum1; cout<<"nnSecond diagonal sum "<<sum; getch(); } OUTPUT Q8. Enter item no. , price and quantity in a class . #include<iostream.h> #include<conio.h> class dd {
  • 17. char item[20]; int pr,qty; public: void getdata(); void putdata(); }; void dd::getdata() { cout<<"nEnter item name "; cin>>item; cout<<"nEnter price "; cin>>pr; cout<<"nEnter quantity "; cin>>qty; } void dd::putdata() { cout<<"nnItem name:"<<item; cout<<"nnPrice: "<<pr; cout<<"nnQty:"<<qty; } main() { dd a1,o1,k1; clrscr(); a1.getdata(); o1.getdata(); k1.getdata(); a1.putdata(); o1.putdata(); k1.putdata(); getch(); } OUTPUT
  • 18. Q9.Enter any line or character in a file and press * to exit the program .
  • 19. #include<iostream.h> #include<fstream.h> #include<conio.h> main() { char ch; clrscr(); ofstream f1("emp"); //implicit //ofstream f1; //f1.open("emp",ios::out); //explicit cout<<"nEnter char "; while(1) //infinity { ch=getche(); // to input a single charactor by keybord. if(ch=='*') break; if(ch==13) { cout<<"n"; f1<<'n'; } f1<<ch; } f1.close(); //getch(); } OUTPUT
  • 20. Q10. Program will read the words which starts from vowels stored in a file .
  • 21. #include<iostream.h> #include<fstream.h> #include<conio.h> main() { char ch[80]; int cnt=0; clrscr(); ifstream f1("emp"); ofstream f2("temp"); while(!f1.eof()) { f1>>ch; cout<<ch<<"n"; if(ch[0]=='a' || ch[0]=='e' || ch[0]=='o' || ch[0]=='i' || ch[0]=='u') f2<<"n"<<ch; } f1.close(); f2.close(); cout<<"nnName start with vowels nn"; f1.open("temp",ios::in); while(f1) //while(!f1.eof()) { f1>>ch; cout<<"n"<<ch; if(f1.eof()) break; } f1.close(); getch(); } OUTPUT
  • 22. Q11. Enter employee no , name , age , salary and store it in a file. #include<iostream.h>
  • 23. #include<conio.h> #include<fstream.h> int row=5,col=2; class abc { private: int empno; char n[20]; int age; float sal; public: void getdata() { char ch; cin.get(ch); // To empty buffer cout<<"nEnter employee no "; cin>>empno; cout<<"nEnter name "; cin>>n; cout<<"nEnter age "; cin>>age; cout<<"nEnter salary "; cin>>sal; } void putdata() { // gotoxy(col,row); cout<<"n"<<empno; // gotoxy(col+10,row); cout<<"t"<<n; // gotoxy(col+25,row); cout<<"t"<<age; // gotoxy(col+35,row); cout<<"t"<<sal; // row++; } }; main() { clrscr(); abc p,p1; fstream f1("emp5.txt",ios::in|ios::out|ios::binary); int i; for(i=0;i<3;i++) {
  • 25.
  • 26. Q12. Deleting the information of employee by entering the employee number . #include<iostream.h> #include<conio.h> #include<fstream.h> #include<stdio.h> class abc { private: int empno; char n[20]; int age; float sal; public: void getdata() { cout<<"nEnter employee no "; cin>>empno; cout<<"nEnter name "; cin>>n; cout<<"nEnter age "; cin>>age; cout<<"nEnter salary "; cin>>sal; } void putdata() { cout<<"nn"<<empno<<"t"<<n<<"t"<<age<<"t"<<sal; } int get_empno() { return empno; } }; main() { abc p,p1; clrscr(); ifstream f1("emp5.txt",ios::in|ios::binary); ofstream f2("temp",ios::out|ios::binary); int i,emp; cout<<"nnNAMEtAGEtSALARY";
  • 27. f1.clear(); f1.seekg(0); //for(i=0;i<4;i++) while(!f1.eof()) { f1.read((char*)&p1,sizeof(p1)); if(f1.eof()) break; p1.putdata(); } cout<<"nEnter employee no "; cin>>emp; f1.clear(); f1.seekg(0); //while(f1) while(!f1.eof()) { f1.read((char*)&p1,sizeof(p1)); if(f1.eof()) break; if(emp!=p1.get_empno()) f2.write((char*)&p1,sizeof(p1)); } f1.close(); f2.close(); remove("emp5.txt"); rename("temp","emp5.txt"); f1.open("emp5.txt",ios::in|ios::binary); cout<<"nnNAMEtAGEtSALARY"; f1.seekg(0); //for(i=0;i<3;i++) while(!f1.eof()) { f1.read((char*)&p1,sizeof(p1)); if(f1.eof()) break; p1.putdata(); } f1.close(); getch(); }
  • 28. OUTPUT Q13. Enter any number and its power and the output will the power of the number . #include<iostream.h>
  • 29. #include<conio.h> #include<math.h> #define CUBE(a,b) pow(a,b) //a>b?a:b main() { int x,y,z; clrscr(); cout<<"nEnter base value "; cin>>x; cout<<"nEnter power "; cin>>y; z=CUBE(x,y); cout<<"n"<<z; getch(); } OUTPUT Q14. Enter 3 strings and the output will show the longest string and the shortest string . #include<iostream.h> #include<conio.h> #include<string.h>
  • 30. main() { char n[20],n1[20],n2[20]; int l1,l2,l3; clrscr(); cout<<"nEnter String1 "; cin>>n; cout<<"nEnter String2 "; cin>>n1; cout<<"nEnter String3 "; cin>>n2; l1=strlen(n); l2=strlen(n1); l3=strlen(n2); (l1>l2 && l1>l3) ?cout<<"nLong: "<<n:(l2>l1 && l2>l3) ? cout<<"nLong: "<<n1 :cout<<"nLong: "<<n2; (l1<l2 && l1<l3)?cout<<"nshort:"<<n:(l2<l1 && l2<l3)? cout<<"nshort:"<<n1:cout<<"nshort:"<<n2; getch(); } OUTPUT
  • 31. Q.15 Enter any number and the output will be all the prime numbers up to that number . #include<iostream.h> #include<conio.h>
  • 32. main() { int n,i,j,p; clrscr(); cout<<"nEnter no of N "; cin>>n; for(i=1;i<=n;i++) { p=0; for(j=2;j<=i/2;j++) if(i%j==0) p=1; if(p==0) cout<<" "<<i; } getch(); } OUTPUT Q16. Selection sort #include<iostream.h> #include<conio.h> void main() {
  • 33. int a[20],n,i,j,t,min,p; clrscr(); cout<<"nEnter no of elements in A "; cin>>n; for(i=0;i<n;i++) { cout<<"nEnter no "; cin>>a[i]; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; for(i=0;i<n;i++) { min=a[i]; p=i; for(j=i;j<n;j++) { if(a[j]<min) { min=a[j]; p=j; } } t=a[i]; a[i]=a[p]; a[p]=t; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; getch(); } OUTPUT
  • 34. Q17. Using loop concept the program will give the output of numbers making a right triangle . #include<iostream.h> #include<conio.h>
  • 35. main() { int i,j; clrscr(); for(i=1;i<=4;i++) { cout<<"nn"; for(j=1;j<=i;j++) cout<<" "<<i; } getch(); } OUTPUT Q18. Program for Stacks and Queue . #include<iostream.h> #include<conio.h> #include<stdlib.h> struct queue
  • 36. { int x; queue *next; }*front=NULL,*rear; void insert(int); void delnode(); void display(); void main() { int a,ch; clrscr(); do { cout<<"nEnter 1 for Insert"; cout<<"nEnter 2 for Delete"; cout<<"nEnter 3 for display"; cout<<"nEnter 4 for exit"; cout<<"nnEnter your choice "; cin>>ch; switch(ch) { case 1: cout<<"nEnter no for insert "; cin>>a; insert(a); break; case 2: delnode(); break; case 3: display(); break; case 4: exit(0); } } while(1); getch(); } void insert(int no) // char str[] { queue *ptr; ptr=new queue; // strcpy(ptr->n,str) // ptr=(struct queue*)malloc(sizeof(struct queue)); ptr->x=no; ptr->next=NULL; if(front==NULL) {
  • 37. front=ptr; rear=ptr; } else { rear->next=ptr; rear=ptr; } } void delnode() { int p; queue *ptr; if(front==NULL) { cout<<"nnQueue is Empty"; return; } p=front->x; //strcpy(p,front->n) ptr=front; front=front->next; delete ptr; cout<<"nndeleted element "<<p<<"n"; } void display() { queue *ptr; cout<<"nQueue now:- n"; for(ptr=front;ptr!=NULL;ptr=ptr->next) cout<<" "<<ptr->x; } OUTPUT
  • 38.
  • 39. Q.19Enter two arrays and the output will be the merge of two arrays .
  • 40. # include <iostream.h> # include <conio.h> main() { int arr1[100],arr2[100],arr3[100],c,i=0,j=0,k=0,size1,size2; clrscr(); cout<<"n enter no of element of arr1 "; cin>>size1; for (i=0;i<size1;i++) { cout<<"n enter no. "; cin>>arr1[i]; } cout<<"n enter no of element of arr2 "; cin>>size2; for (i=0;i<size2;i++) { cout<<"n enter no. "; cin>>arr2[i]; } cout<<"n arr1 "; for (i=0;i<size1;i++) cout<<" "<<arr1[i]; cout<<"n arr2 "; for (i=0;i<size2;i++) cout<<" "<<arr2[i]; i=0;j=0;k=0; while (i<size1 && j<size2) { if (arr1[i]<arr2[j]) arr3[k++]=arr1[i++]; else if (arr2[j]<arr1[i]) arr3[k++]=arr2[j++]; else i++; } while (i<size1) arr3[k++]=arr1[i++]; while (j<size2) arr3[k++]=arr2[j++];
  • 41. cout<<"n arr3 "; for (i=0;i<k;i++) cout<<" "<<arr3[i]; getch(); } OUTPUT Q20.Sequence Sort (Insertion Sort) #include<iostream.h> #include<conio.h> void main()
  • 42. { int a[20],n,i,j,t; clrscr(); cout<<"nEnter no of elements in A "; cin>>n; for(i=0;i<n;i++) { cout<<"nEnter no "; cin>>a[i]; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; for(i=0;i<n;i++) for(j=i+1;j<n;j++) if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } cout<<"nn"; for(i=0;i<n;i++) cout<<" "<<a[i]; getch(); } OUTPUT
  • 44. School homework QUERIES Ques 1. mysql> select ename ,sal,dept_no from empl where commission is null ;
  • 45. Ques 2. mysql> select ename ,sal,dept_no from empl where commission is not null; Ques 3. mysql> select * from empl where sal between 1000 and 2500;
  • 46. Ques 4. mysql> select ename from empl where ename like ‘a%’ ; Ques 5 . mysql> select concat (ename,dept_no)as “name dept” from empl;
  • 47. Ques 6 . mysql> select lower(ename) “empl name” from empl; Ques 7 . mysql> select upper(ename) “empl name” from empl;
  • 48. Ques 8 . mysql> select substr(job,1,5) from empl where empno=8888 or empno=8900; Ques 9 . mysql> select job,instr (job,’le’)as “le in ename” from empl;
  • 49. Ques 10 . mysql> select ename, length (ename)as “name length” from empl where empno <=8888 ;
  • 50. OUTPUT QUESTIONS Ques 1 . mysql> select left(‘Informatices practices’,5) ; Ques 2 . mysql> select right (‘Informatices practices’,5); Ques 3 . mysql> select mid(‘Informatices practices’,6,9);
  • 51. Ques 4 . mysql> select ltrim(‘ akshit’); Ques 5 . mysql> select rtrim(‘akshit ‘);