SlideShare a Scribd company logo
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
Practical Class 12th (c++programs+sql queries and 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
Practical Class 12th (c++programs+sql queries and 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 ‘);
Practical Class 12th (c++programs+sql queries and output)
Ad

More Related Content

What's hot (20)

C++ 25 programs Class XII
C++ 25 programs Class XIIC++ 25 programs Class XII
C++ 25 programs Class XII
Saurav Ranjan
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
C++ references
C++ referencesC++ references
C++ references
corehard_by
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Visual Basic(Vb) practical
Visual Basic(Vb) practicalVisual Basic(Vb) practical
Visual Basic(Vb) practical
Rahul juneja
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
C# Loops
C# LoopsC# Loops
C# Loops
Hock Leng PUAH
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
Saket Pathak
 
Enumeration in c#
Enumeration in c#Enumeration in c#
Enumeration in c#
Dr.Neeraj Kumar Pandey
 
Creating your own exception
Creating your own exceptionCreating your own exception
Creating your own exception
TharuniDiddekunta
 
PDBC
PDBCPDBC
PDBC
Sunil OS
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
riturajj
 
C# Generics
C# GenericsC# Generics
C# Generics
Rohit Vipin Mathews
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
Edureka!
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Deep C
Deep CDeep C
Deep C
Olve Maudal
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 
C++ 25 programs Class XII
C++ 25 programs Class XIIC++ 25 programs Class XII
C++ 25 programs Class XII
Saurav Ranjan
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
Bilal Mirza
 
Java IO Streams V4
Java IO Streams V4Java IO Streams V4
Java IO Streams V4
Sunil OS
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
Neeru Mittal
 
Visual Basic(Vb) practical
Visual Basic(Vb) practicalVisual Basic(Vb) practical
Visual Basic(Vb) practical
Rahul juneja
 
12th CBSE Practical File
12th CBSE Practical File12th CBSE Practical File
12th CBSE Practical File
Ashwin Francis
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
Saket Pathak
 
Cn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshanCn os-lp lab manual k.roshan
Cn os-lp lab manual k.roshan
riturajj
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
Edureka!
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
Jeevesh Pandey
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
Tareq Hasan
 

Similar to Practical Class 12th (c++programs+sql queries and output) (20)

Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
Ûťţåm Ğűpţä
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
yash production
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
vikram mahendra
 
C- Programming Assignment 3
C- Programming Assignment 3C- Programming Assignment 3
C- Programming Assignment 3
Animesh Chaturvedi
 
C++ file
C++ fileC++ file
C++ file
simarsimmygrewal
 
Object Oriented Programming (OOP) using C++ - Lecture 3
Object Oriented Programming (OOP) using C++ - Lecture 3Object Oriented Programming (OOP) using C++ - Lecture 3
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Arrays
ArraysArrays
Arrays
poonamchopra7975
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul 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 SQL
vikram mahendra
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
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
anuradhasilks
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
Presentat ions_PPT_Unit-2_OOP.pptx
Presentat                    ions_PPT_Unit-2_OOP.pptxPresentat                    ions_PPT_Unit-2_OOP.pptx
Presentat ions_PPT_Unit-2_OOP.pptx
ZeelGoyani
 
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
MuhammadMaazShaik
 
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_csharp4
Abed Bukhari
 
C++ normal assignments by maharshi_jd.pdf
C++ normal assignments by maharshi_jd.pdfC++ normal assignments by maharshi_jd.pdf
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
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
premrings
 
Simple Java Program for beginner with easy method.pdf
Simple Java Program for beginner with easy method.pdfSimple Java Program for beginner with easy method.pdf
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
c++ practical Digvajiya collage Rajnandgaon
c++ practical  Digvajiya collage Rajnandgaonc++ practical  Digvajiya collage Rajnandgaon
c++ practical Digvajiya collage Rajnandgaon
yash production
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
vandna123
 
programming in C++ report
programming in C++ reportprogramming in C++ report
programming in C++ report
vikram mahendra
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
Mitul 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 SQL
vikram mahendra
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
AhalyaR
 
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
anuradhasilks
 
Wap to implement bitwise operators
Wap to implement bitwise operatorsWap to implement bitwise operators
Wap to implement bitwise operators
Harleen Sodhi
 
Presentat ions_PPT_Unit-2_OOP.pptx
Presentat                    ions_PPT_Unit-2_OOP.pptxPresentat                    ions_PPT_Unit-2_OOP.pptx
Presentat ions_PPT_Unit-2_OOP.pptx
ZeelGoyani
 
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
MuhammadMaazShaik
 
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_csharp4
Abed Bukhari
 
C++ normal assignments by maharshi_jd.pdf
C++ normal assignments by maharshi_jd.pdfC++ normal assignments by maharshi_jd.pdf
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
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
premrings
 
Simple Java Program for beginner with easy method.pdf
Simple Java Program for beginner with easy method.pdfSimple Java Program for beginner with easy method.pdf
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
Ad

Recently uploaded (20)

Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Metamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative JourneyMetamorphosis: Life's Transformative Journey
Metamorphosis: Life's Transformative Journey
Arshad Shaikh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Phoenix – A Collaborative Renewal of Children’s and Young People’s Services C...
Library Association of Ireland
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACYUNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
UNIT 3 NATIONAL HEALTH PROGRAMMEE. SOCIAL AND PREVENTIVE PHARMACY
DR.PRISCILLA MARY J
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Michelle Rumley & Mairéad Mooney, Boole Library, University College Cork. Tra...
Library Association of Ireland
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
Ad

Practical Class 12th (c++programs+sql queries and output)

  • 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++) {
  • 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
  • 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 ‘);