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)

More Related Content

What's hot (20)

DOCX
12th CBSE Practical File
Ashwin Francis
 
DOCX
12th CBSE Computer Science Project
Ashwin Francis
 
PDF
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
अयशकांत मिश्र
 
PDF
computer science project class 12th
Nitesh Kushwaha
 
PDF
Computer project final for class 12 Students
Shahban Ali
 
DOCX
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
PDF
Computer science class 12 project on Super Market Billing
Harsh Kumar
 
DOCX
Computer Science investigatory project class 12
Raunak Yadav
 
PPTX
Computer Science Investigatory Project
Prakhar Seth
 
DOCX
Practical File of C Language
RAJWANT KAUR
 
PDF
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
DOCX
Chapter 8 c solution
Azhar Javed
 
ODT
Library Management Project (computer science) class 12
RithuJ
 
DOCX
Computer science project work
rahulchamp2345
 
PDF
MOVIE TICKET BOOKING-COMPUTER SCIENCE C++ PROJECT
Sindhu Ashok
 
PDF
Isc computer project final upload last
Arunav Ray
 
PDF
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
ArkaSarkar23
 
DOC
C lab-programs
Tony Kurishingal
 
DOCX
12th CBSE Computer Science Project
Ashwin Francis
 
DOCX
computer science project for class 12 on telephone billing
anshi acharya
 
12th CBSE Practical File
Ashwin Francis
 
12th CBSE Computer Science Project
Ashwin Francis
 
Computer Investgatort Project (HOTEL MANAGEMENT SYSTEM)
अयशकांत मिश्र
 
computer science project class 12th
Nitesh Kushwaha
 
Computer project final for class 12 Students
Shahban Ali
 
Computer Science Practical Science C++ with SQL commands
Vishvjeet Yadav
 
Computer science class 12 project on Super Market Billing
Harsh Kumar
 
Computer Science investigatory project class 12
Raunak Yadav
 
Computer Science Investigatory Project
Prakhar Seth
 
Practical File of C Language
RAJWANT KAUR
 
Let us c(by yashwant kanetkar) chapter 2 solution
rohit kumar
 
Chapter 8 c solution
Azhar Javed
 
Library Management Project (computer science) class 12
RithuJ
 
Computer science project work
rahulchamp2345
 
MOVIE TICKET BOOKING-COMPUTER SCIENCE C++ PROJECT
Sindhu Ashok
 
Isc computer project final upload last
Arunav Ray
 
Computer Science Investigatory Project Class XII CBSE(Latest Syllabus)(Python...
ArkaSarkar23
 
C lab-programs
Tony Kurishingal
 
12th CBSE Computer Science Project
Ashwin Francis
 
computer science project for class 12 on telephone billing
anshi acharya
 

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

DOCX
Computer Practical XII
Ûťţåm Ğűpţä
 
PDF
c++ practical Digvajiya collage Rajnandgaon
yash production
 
PDF
2014 computer science_question_paper
vandna123
 
DOC
programming in C++ report
vikram mahendra
 
PDF
C- Programming Assignment 3
Animesh Chaturvedi
 
DOCX
C++ file
simarsimmygrewal
 
PDF
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
DOCX
Arrays
poonamchopra7975
 
DOCX
Cs pritical file
Mitul Patel
 
DOC
project report in C++ programming and SQL
vikram mahendra
 
DOC
Pads lab manual final
AhalyaR
 
PDF
a) In the code, board is initialized by reading an input file. But y.pdf
anuradhasilks
 
DOCX
Wap to implement bitwise operators
Harleen Sodhi
 
PPTX
Presentat ions_PPT_Unit-2_OOP.pptx
ZeelGoyani
 
PDF
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
PPSX
Concepts of C [Module 2]
Abhishek Sinha
 
PPT
Whats new in_csharp4
Abed Bukhari
 
PDF
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
PDF
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
PDF
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
Computer Practical XII
Ûťţåm Ğűpţä
 
c++ practical Digvajiya collage Rajnandgaon
yash production
 
2014 computer science_question_paper
vandna123
 
programming in C++ report
vikram mahendra
 
C- Programming Assignment 3
Animesh Chaturvedi
 
Object Oriented Programming (OOP) using C++ - Lecture 3
Faculty of Computers and Informatics, Suez Canal University, Ismailia, Egypt
 
Cs pritical file
Mitul Patel
 
project report in C++ programming and SQL
vikram mahendra
 
Pads lab manual final
AhalyaR
 
a) In the code, board is initialized by reading an input file. But y.pdf
anuradhasilks
 
Wap to implement bitwise operators
Harleen Sodhi
 
Presentat ions_PPT_Unit-2_OOP.pptx
ZeelGoyani
 
sodapdf-converted into ppt presentation(1).pdf
MuhammadMaazShaik
 
Concepts of C [Module 2]
Abhishek Sinha
 
Whats new in_csharp4
Abed Bukhari
 
C++ normal assignments by maharshi_jd.pdf
maharshi1731
 
54602399 c-examples-51-to-108-programe-ee01083101
premrings
 
Simple Java Program for beginner with easy method.pdf
ashwinibhosale27
 
Ad

Recently uploaded (20)

PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PPT
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
PPTX
ENG8_Q1_WEEK2_LESSON1. Presentation pptx
marawehsvinetshe
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPTX
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
Introduction presentation of the patentbutler tool
MIPLM
 
Controller Request and Response in Odoo18
Celine George
 
Workbook de Inglés Completo - English Path.pdf
shityouenglishpath
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Indian Contract Act 1872, Business Law #MBA #BBA #BCOM
priyasinghy107
 
ENG8_Q1_WEEK2_LESSON1. Presentation pptx
marawehsvinetshe
 
Horarios de distribución de agua en julio
pegazohn1978
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
epi editorial commitee meeting presentation
MIPLM
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPT-Q1-WK-3-ENGLISH Revised Matatag Grade 3.pptx
reijhongidayawan02
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
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 ‘);