SlideShare a Scribd company logo
……………… PUBLIC SENIOR SECONDARY
SCHOOL,……………….
PROGRAMMINING
in
SUBMITTED TO SUBMITTED BY
……………………. ………………………
(Computer Science) XII B
ACKNOWLEDGEMENT
I would like to convey my heartful thanks to
…………………. (Computer Science) who always
gave valuable suggestions & guidance for
completion of my project.
he helped me to understand & remember
important details of the project. My project has
been a success only because of his guidance.
I am especially indented & I am also beholden to
my friends. And finally I thank to the members of
my family for their support & encouragement.
CERTIFICATE
This is to certify that …………………. of
class ………. of ………PUBLIC SENIOR
SECONDARY SCHOOL , ………….has
completed his project under my supervision.
He has taken proper care & shown sincerity in
completion of this project.
I certify that this project is up to my
expectation & as per the guideline issued by
CBSE.
. …………………………
(Computer Science faculty )
INDEX
SNO PROGRAMMING DESCRIPTION SIGNATURE
1 Program to find area of triangle using function overloading
2 Program to keep record of books & Audio Cassettes
3 Write a function to count and print the number of complete words as
“to” and “are” stored in a text file “ESSAY.TXT”.
4 Write a function in C++ to display object from the binary file
“PRODUCT.DAT” whose product price is more than Rs 30.
Assuming that binary file is containing the objects of the following
class:
5 Program to enter the choice by the user using switch-case and display
the result
6 Program to enter a string and find its length and print the string in
reverse order
7 Program to enter an integer and output the cube of that integer
8 Program to enter an integer and print out its successor
9 Program to enter the information in a text file and display it on the
screen by the choice of the user
10 Write a program to convert octal number to binary number and
display it
11 Write a program to calculate number of upper and lower case vowels
and consonants and display it
12 Write a program to search the position of a substring and display it
13 Write a program to remove given integer from array, shift elements to
right and fill space by 0 and display it
14 Write a program to print upper and lower half of matrix
15 Write a program to implement link list for the ticket entry
system
16 Write a program to implement linked queue with list of names.
17 Program to display the list of students, the records of the students will
be sorted in descending order of the marks obtained by the students
18 program to enter the lines in a file and convert them into upper case
19 Program to display volume that uses three elements (length, width
and height) of type distance. This type, in turn has two elements (feet
and inches).Calculate volume of a room using structure
20 Program to enter student details using a pointer to an object
21 Program to enter and display employee details using multi_level
inheritance.
22 Program to enter the information of employee and then search the
record and deleting a node of a linked list
23 SQL QUERIES
//Program to find area of triangle using function overloading
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<math.h>
//function 1
void area(float r)
{float area_c;
area_c=(3.14*r*r); cout<<"Area of the circle="<<area_c<<endl;
}
//function 2
void area(int l,int h)
{float area_r; area_r=l*h;
cout<<"Area of the rectangle = "<<area_r<<endl;
}
//function 3
void area(float a,float b,float c)
{float s,area_t ; s=(a+b+c)/2;
area_t=pow((s*(s-a)*(s-b)*(s-c)),0.5);
cout<<"Area of the triangle = "<<area_t<<endl;
}
void main()
{
clrscr();
int ch; float r,a,b,c,l,h;
cout<<"1.Area of circle"<<endl<<"2.Area of rectangle"<<endl;cout<<"3.Area of triangle"<<endl<<"4.Exit"<<endl;
X: cout<<"Enter the choice"<<endl; cin>>ch;
switch(ch)
{ case 1:cout<<"Enter the radius of the circle"<<endl; cin>>r;
void area (float);
area(r);
goto X;
case 2:cout<<"Enter the sides of rectangle"<<endl; cin>>l>>h;
void area (float,float);
area (l,h); goto X;
case 3:cout<<"Enter the sides of triangle"<<endl;
cin>>a>>b>>c;
void area (float,float,float);
area (a,b,c);
goto X;
case 4:exit(0);
default:cout<<"Wrong Choice"<<endl;
goto X;}
getch();}
OUTPUT
1. Area Of Circle
2. Area Of Rectangle
3. Area Of Triangle
4. Exit
Enter The Choice:
Enter the radius of the circle: 5
Area Of Circle: 78.5
//Program to keep record of books & Audio Cassettes
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<stdio.h>
class publication
{ char title[20];
float price;
public:
void getdata()
{
cout<<"Enter Title"<<endl;
gets(title);
cout<<"Enter Price"<<endl;
cin>>price;
}
void putdata()
{
cout<<"Title"<<endl;
puts(title);
cout<<"Price"<<endl;
cout<<price;
}};
class book : protected publication
{
int pagecount;
public:
void putdata()
{
publication :: putdata();
cout<<endl<<"Pg Count"<<endl;
cout<<pagecount;
}
void getdata()
{
publication::getdata();
cout<<"Pg Count"<<endl;
cin>>pagecount;
} };
class tape : protected publication
{
float time;
public:
void getdata()
{
publication :: getdata();
cout<<"Enter Time"<<endl;
cin>>time;
}
void putdata()
{ publication :: putdata();
cout<<endl<<"Time "<<endl;
cout<<time;
} };
void main()
{
clrscr();
book b;
tape t;
int ch;
x: {
cout<<endl<<"1. BOOK 2:Tape 3:Exit "<<endl;
cin>>ch;
switch(ch)
{ case 1:b.getdata();
b.putdata();
goto x;
case 2:t.getdata();
t.putdata();
goto x;
case 3:exit(0);
} }
getch();
}
OUTPUT
/*Write a function to count and print the number of complete words as
“to” and “are” stored in a text file “ESSAY.TXT”. */
void CWORDS( )
{
ifstream fin(“ESSAY.TXT”);
char st[80];
int count=0;
while(!fin.eof())
{
fin>>st;
if(!fin)
break;
if(strcmpi(st,”to”) = =0 || strcmpi(st,”are”)= =0)
count++;
}
cout<<”nTotal ‘to’ & ‘are’ words = “<<count;
fin.close( );
}
void main()
{
CWORDS();
}
OUTPUT
Total to and are words are :7
/*Write a function in C++ to display object from the binary file “PRODUCT.DAT” whose product
price is more than Rs 30. Assuming that binary file is containing the objects of the following class: */
class PRODUCT
{
int PRODUCT_no;
char PRODUCT_name[20];
float PRODUCT_price;
public:
void enter( )
{
cin>> PRODUCT_no ; gets(PRODUCT_name) ;
cin >> PRODUCT_price;
}
void display()
{
cout<< PRODUCT_no<<” “<<PRODUCT_name<<” “<< PRODUCT_price;
}
int ret_Price( )
{
return PRODUCT_price;
}
};
void Rec_display()
{
Product P;
ifstream ifile(“PRODUCT.Dat”, ios::binary);
if(!ifile)
{
cout<<”n File doesn’t exist”; exit(0);
}
else
{
cout<<”nPRODUCT_no PRODUCT_name PRODUCT_pricen”;
while(ifile.read((char *)&P, sizeof(P)))
{
if (P.ret_Price()>30)
P.display();
}
}
}
OUTPUT
PRODUCT_no PRODUCT_name PRODUCT_price
101 colgate 45
105 Nescafe 85
108 Panteen 105
//Program to enter the choice by the user using switch-case and display the result
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
int choice;
cout << "1. Talk" << endl;
cout << "2. Eat" << endl;
cout << "3. Play" << endl;
cout << "4. Sleep" << endl;
cout << "Enter your choice : " << endl;
cin>>choice;
switch(choice)
{
case 1 : cout << "You chose to talk...talking too much is a bad habit." << endl;
break;
case 2 : cout << "You chose to eat...eating healthy foodstuff is good." << endl;
break;
case 3 : cout << "You chose to play...playing too much everyday is bad." << endl;
break;
case 4 : cout << "You chose to sleep...sleeping enough is a good habit." << endl;
break;
default : cout << "You did not choose anything...so exit this program." << endl;
}
getch();
}
OUTPUT
This program takes in the user's choice as a screen input.
Depending on the user's choice, it switches between the different cases.
The appropriate message is then outputted using the 'cout' command.
//Program to enter a string and find its length and print the string in reverse order.
#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
int slength;
char str[81]; //Allowing the user to input a maximum of 80 characters.
cout << "Enter the string : " << endl;
cin>>str;
slength=strlen(str);
cout << "The length of the string " << str << " is " << slength << "." << endl;
cout<<”Reverse string is:”;
for(int x=slength-1;x>=0;x--)
cout<<str[x];
getch();
}
OUTPUT
Enter the string : COMPUTER
The length of the string COMPUTER is 8
Reverse string is: RETUPMOC
//Program to enter an integer and output the cube of that integer
#include <iostream.h>
#include <conio.h>
int cube(int x); //The prototype.
void main()
{
clrscr();
int a;
cout << "Enter an integer : ";
cin>>a;
cout << "The cube of " << a << " is : " << cube(a) << endl; //Call the function cube(a).
getch();
}
//Defining the function.
int cube(int x)
{
int y;
y=x*x*x;
return(y);
}
OUTPUT
Enter the integer:8
The cube of 8 is : 512
//Program to enter an integer and print out its successor
#include <iostream.h>
#include <conio.h>
void value(int);
void main()
{
clrscr();
int x;
cout << "Enter an integer : ";
cin>>x;
cout << "The successor of " << x << " is ";
value(x);
getch();
}
void value(int x)
{
x++;
cout << x << "." << endl;
}
OUTPUT:
Enter the integer:49
The successor of 49 is 50.
/*Program to enter the information in a text file and display it on the screen by the choice of the user*/
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<ctype.h>
class what
{
char str[40];
public:
void create();
void display();
void c_lower();
void dis_lower();
};
void what::dis_lower()
{
char ch4;
ifstream obj5("story1.dat");
cout<<"nDisplay the datan";
while(!obj5.eof())
{
obj5.get(ch4);
cout<<ch4;
//obj5.getline(str,80);
//cout<<str<<"n";
}
obj5.close();
}
void what::c_lower()
{char ch,ch3;
ofstream obj3("story1.dat");
ifstream obj4("story.txt");
while(obj4)
{obj4.get(ch);
if(ch!='n')
{ if(islower(ch))
{cout<<"nch="<<ch;
obj3<<ch;
}else {
ch3=tolower(ch);
obj3<<ch3;
cout<<"nch="<<ch<<" ch3="<<ch3;
}
}else{
obj3<<'n';
}}
obj3.close();
obj4.close();
}
void what::display()
{ifstream obj1("story.txt");
cout<<"nDisplay the datan";
while(obj1)
{obj1.getline(str,40,'n');
cout<<str<<"n";
}
obj1.close();
}
void what::create()
{ofstream obj("story.txt");
char c2;
do
{cout<<"nEnter the line of text";
gets(str);
obj<<str<<"n";
cout<<"nDo you want to add more text(y/n)";
cin>>c2;
}while(c2=='y');
obj.close();
}
void main()
{what whatobj;
int c1=0;
do { cout<<"n1-create the file";
cout<<"n2-Display the file";
cout<<"n3-Create the file lower case";
cout<<"n4-Display the file lower case";
cin>>c1;
switch(c1)
{ case 1: whatobj.create();
break;
case 2: whatobj.display();
break;
case 3: whatobj.c_lower();
break;
case 4: whatobj.dis_lower();
break;
}
}while(c1!=5);
}
OUTPUT
1-create the file
2-Display the file
3-Create the file lower case
4-Display the file lower case
Enter the choice:1
TYPE THE CONTENT UNTIL YOU PRESS ENTER KEY
Do you want to add more text(y/n)n
1-create the file
2-Display the file
3-Create the file lower case
4-Display the file lower case
Enter the choice:3
convert all the upper case character to lower case character
//Write a program to convert octal number to binary number and display it?
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int calc (int oct, int bin[])
{
int k=0,rem;
while (oct>0)
{
rem=oct%2;
bin[k]=rem;
oct=oct/2;
k++;
}
return k-1;
}
void main ()
{
clrscr();
int oct,bin[20],c,k;
cout<<"n Enter two digit octal number =";
cin>>oct;
k=calc(oct,bin);
cout<<"n The binary equivalent =";
for (c=k;c>=0;c--)
cout<<setw (2)<<bin[c];
getch ();
}
OUTPUT
/* Write a program to calculate number of upper and lower case vowels and consonants and
display it?*/
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
void output (char str[100])
{
int c=0,uv=0,uc=0,lc=0,lv=0;
while (str[c] != '0')
{
if (isupper(str[c]))
if (str[c]=='A'|| str[c]=='E'|| str[c]=='I'||
str[c]=='O'|| str[c]=='U')
uv+=1;
else
uc+=1;
else
if (islower(str[c]))
if (str[c]=='a'|| str[c]=='e'|| str[c]=='i'||
str[c]=='o'|| str[c]=='u')
lv+=1;
else
lc+=1;
c++;
}
cout<<"n upper case of vowels="<<uv<<endl;
cout<<"n upper case of consonants="<<uc<<endl;
cout<<"n lower case of vowels="<<lv<<endl;
cout<<"n lower case of consonants="<<lc<<endl;
}
void main ()
{
char str[100];
cout<<"n Enter the string ";
gets (str);fflush (stdin);
output (str);
getch ();
}
OUTPUT
//Write a program to search the position of a substring and display it?
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include <string.h>
int search (char str[50],char str1[20])
{
int c=0,d,x=0,y;
char str2[25];
while (str[c] != '0')
{
d=0;
while (str[c] !=' ')
{
str2[d]=str[c];
c++ ; d++;
}
str2[d]='0';
c++; x+=1;
if (strcmp (str2,str1)==0)
y=x;
}
return y;
}
void main ()
{
char str[50],str1[20];
int k;
cout <<"n Enter any string ";
gets (str); fflush (stdin);
cout <<"n Enter the substring to be searched ";
gets (str1); fflush (stdin);
k=search (str,str1);
cout<<"n the position of substring ="<<k;
getch ();
}
OUTPUT
/*Write a program to remove given integer from array, shift elements to right and fill space
by 0 and display it?*/
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void shift (int a[],int val,int n)
{ int k,pos,c;
for (c=0;c<n;c++)
if (a[c]==val)
{ pos=c;
for(k=pos;k>0;k--)
a[k]=a[k-1];
a[0]=0;
}}
void main ()
{ clrscr();
int a[20],c,n,val;
cout<<"n Enter number of terms = ";
cin>>n;
for (c=0;c<n;c++)
{ cout<<"n Enter array elements = ";
cin>>a[c];
} cout <<"n Enter the value to be deleted = ";
cin >> val;
cout <<"nnn The input array nn "<<endl;
for (c=0; c<n; c++)
cout<<" "<<a[c];
shift (a,val,n);
cout <<"nnn The output array nn"<<endl;
for (c=0;c<n;c++)
cout<<" "<<a[c];
getch ();
}
OUTPUT
// Write a program to print upper and lower half of matrix?
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
void upperhalf (int mat[10][10],int m,int n)
{
int c,r;
for (r=0;r<n;r++)
{
cout<<setw ((r+1)*4);
for(c=r;c<m;c++)
cout<<mat[r][c]<<setw (4);
cout<<"nnnn";
}
}
void lowerhalf (int mat[10][10],int n)
{
int c,r;
for (r=0;r<n;r++)
{
for(c=0;c<=r;c++)
cout<<setw (4)<<mat[r][c];
cout<<"nnnn";
}
}
void main ()
{
clrscr();
int mat[10][10],m,n,c,r;
char choice;
cout<<"n Enter number of rows and column = ";
cin>>n>>m;
for(r=0;r<n;r++)
for (c=0;c<m;c++)
{
cout<<"n Enter matrix elements = ";
cin>>mat[r][c];
}
clrscr();
do
{
clrscr();
cout<<"n Enter u for printing of upper half of
matrix"<<endl;
cout<<"n Enter l for printing of lower half of
matrix"<<endl;
cout<<"n Enter q for quit"<<endl;
cout<<"n Enter your choice =";
cin>>choice;
switch (choice)
{
case 'u': upperhalf(mat,m,n);
break;
case 'l': lowerhalf(mat,n);
break;
}
getch ();
}
while (choice != 'q');
}
OUTPUT
//Write a program to implement link list for the ticket entry system
#include<iostream.h>
#include<conio.h>
struct train
{
int tno;
char pname[25];
char des_name[25];
int dis;
train *next;
};
class journey
{
train *top;
public:
journey()
{
top=NULL;
}
void push();
void pop();
void display();
};
void journey::push()
{
train *tmp;
tmp=new train;
cout<<"nEnter the Ticket No:";
cin>>tmp->tno;
cout<<"nEnter the Passanger name:";
cin>>tmp->pname;
cout<<"nEnter the destination name:";
cin>>tmp->des_name;
cout<<"nEnter the distance:";
cin>>tmp->dis;
tmp->next=NULL;
if(top==NULL)
{top=tmp;
}else
{tmp->next=top;
//delete top;
top=tmp;
}//delete tmp;
}
void journey::pop()
{ if(top==NULL)
{cout<<"nStack is empty";
}else
{top=top->next;
}
}
void journey::display()
{train *t;
t=top;
while(t!=NULL)
{cout<<"n"<<t->tno<<"tt"<<t->pname<<"tt"<<t->des_name<<"tt"<<t->dis;
t=t->next;
}}
void main()
{int ch=0;
journey jobj;
do {cout<<"n1-pushn2-popn3-Display";
cin>>ch;
switch(ch)
{case 1: jobj.push();
break;
case 2: jobj.pop();
break;
case 3: jobj.display();
break;
}
}while(ch!=4);
}
OUTPUT
//Write a program to implement linked queue with list of names.
#include<iostream.h>
#include<conio.h>
struct members
{
char name[25];
members *link;
};
class queue
{
members *rear,*front;
public:
queue()
{
rear=NULL;
front=NULL;
}
void input();
void del();
void dis();
};
void queue::input()
{
members *tmp;
tmp=new members;
cout<<"nEnter the name:";
cin>>tmp->name;
tmp->link=NULL;
if(rear==NULL)
{
cout<<"nFirst";
rear=tmp;
front=tmp;
}
else
{
rear->link=tmp;
rear=tmp;
}
}
void queue::del()
{
if(front==NULL)
{
cout<<"nQueues of names are empty";
}
else
{
front=front->link;
}
}
void queue::dis()
{
members *t;
t=front;
while(t!=NULL)
{
cout<<"n Name:"<<t->name;
t=t->link;
}
}
void main()
{
int ch=0;
queue obj;
do
{
clrscr();
cout<<"n1-PUSHn2-POPnDISPLAYnEnter the choice:";
cin>>ch;
switch(ch)
{
case 1: obj.input();
break;
case 2: obj.del();
break;
case 3: obj.dis();
break;
}
getch();
}while(ch!=4);
}
OUTPUT
/* Program to display the list of students, the records of the students will be sorted in descending
order of the marks obtained by the students.*/
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <iomanip.h>
class student
{
char name[15];
int rollno;
int marks;
public:void read_data();
int get_marks();
void display_data();
};
void student::read_data()
{
cout<<"n Enter name";
gets(name);
fflush(stdin);
cout<<"n Enter roll and marks";
cin>>rollno>>marks;
}
int student::get_marks()
{
return marks;
}
void student:: display_data()
{
cout<<endl<<setw(9)<<name;
cout<<setw(7) <<rollno<<setw(5)<<marks;
}
void sort_list(student s[],int n);
void main()
{
int n;
student stud_list[50];
cout<<"n Enter the Number of students";
cin>>n;
for(int i=0;i<n;i++)
stud_list[i].read_data();
sort_list(stud_list,n); //sort the list
clrscr();
cout<<"n List of students n";
cout<<"n Name Rollno Marks";
for(i=0;i<n;i++)
stud_list[i].display_data();
}
void sort_list(student s[],int n)
{
int i,j;
student temp;
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(s[i].get_marks()<s[j].get_marks())
{
temp=s[i];
s[i]=s[j];
s[j]=temp;
} } } }
OUTPUT
//program to enter the lines in a file and convert them into upper case
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
void main()
{char fname[15];
char row[80];
int count,;cout<<"n enter the name of the file to be created";
gets(fname);
ofstream myfile(fname);
char ch;
while(1)
{cout<<"n enter a line of text";
gets(row);
mylife<<row<<"n";
cout<<"n want to continue ? y/n";
cin>>ch;
if((ch=='N')||(ch=='n'))
break;
}myfile.close();
ofstream tempfile("temp");
ifstream newfile(fname);
while(newfile)
{
newfile.get(ch);
if(ch!='n')
ch=toupper(ch);
tempfile.put(ch);
}
newfile.close();
tempfile.close();
clrscr();
cout<<"n the output of file is ...n";
ifstream yourfile("temp");
count=0;
while(!yourfile.eof() )
{
yourfile.getline(row,80);
cout<<row<<'n';
count++;
if((count%22)==0)
{
cout<<"n enter any key to continue";
cin>>ch;
}
}
yourfile.close();
}
OUTPUT
Enter the name of the file:ABC.txt
The name of the text book is computer science
THE NAME OF THE TEXT BOOK IS COMPUTER SCIENCE
/*Program to display volume that uses three elements (length, width and height) of type distance. This
type, in turn has two elements (feet and inches).Calculate volume of a room using structure.*/
#include<iostream.h>
#include<conio.h>
struct distance
{
float feet;
float inches;
};
struct volume
{
distance length;
distance width;
distance height;
}vol;
void main()
{
float tot_length,tot_width,tot_height;
float v;
clrscr();
cout<<"Enter length in feet:"; cin>>vol.length.feet;
cout<<"Enter length in inches:"; cin>>vol.length.inches;
cout<<"Enter width in feet:"; cin>>vol.width.feet;
cout<<"Enter width in inches:"; cin>>vol.width.inches;
cout<<"Enter height in feet:"; cin>>vol.height.feet;
cout<<"Enter height in inches:"; cin>>vol.height.inches;
tot_length=vol.length.feet+vol.length.inches/12;
tot_width=vol.width.feet+vol.width.inches/12;
tot_height=vol.height.feet+vol.height.inches/12;
cout<<tot_length<<"n";
cout<<tot_width<<"n";
cout<<tot_height<<"n";
v=tot_length*tot_width*tot_height;
cout<<"The volume is :";
cout<<v;
}
OUTPUT
// Program to enter student details using a pointer to an object.
#include<iostream.h>
#include<conio.h>
class student
{
char name[15];
int roll;
public:
void get_data()
{
cout<<"n enter the data";
cout<<"n name";
cin>>name;
cout<<"roll:";
cin>>roll;
}
void show_data()
{
cout<<"n the data is..";
cout<<"n name:";
cout<<name;
cout<<"n roll:";
cout<<roll;
}
};
main()
{
student *objptr;
objptr=new student;
objptr->get_data();
objptr->show_data();
return 0;
}
OUTPUT
//Program to enter and display employee details using multi_level inheritance.
#include <iostream.h>
#include <conio.h>
class employee //base class
{ protected: int emp_code;
public: void get_code(int);
void put_code(void);
};
void employee::get_code(int a)
{emp_code=a;}
void employee::put_code()
{ cout<<"Employee Code:"<<emp_code<<"n"; }
class salary:public employee //first_level derivation
{ protected: float basic;
float da;
float hra;
public: void get_sal(float,float,float);
void put_sal(void);
};
void salary::get_sal(float x, float y, float z)
{ basic=x;
da=y;
hra=z;
}
void salary::put_sal()
{ cout<<"Basic:"<<basic<<"n";
cout<<"DA:" <<da<<"n";
cout<<"HRA:"<<hra<<"n";
}
class payroll:public salary //second_level derivation
{ float gross;
public: void display(void); };
void payroll::display(void)
{ gross=basic+da+hra;
put_code();
put_sal();
cout<<"Gross:"<<gross<<"n"; }
void main()
{ payroll emp1;
emp1.get_code(101);
emp1.get_sal(5000.0,2400.0,1800.0);
emp1.display();
}
OUTPUT
//Program to enter the information of employee and then search the record and deleting a node of a
linked list
#include<iostream.h>
#include<conio.h>
void main()
{
struct emp
{
char name[20];
int code;
emp *next; //self-referential structure
};
emp *point,*item,*first,*back;
int i,n,found;
int ecode;
cout<<"nEnter the size of the list to be created";
cin>>n;
if(n<=0)
{
cout<<"nError!";
}
first=new emp;
cout<<"nEnter the data:";
cin>>first->name>>first->code;
first->next=NULL;
point=first;
//linked list creation
for(i=1;i<n;i++)
{
item=new emp;
cout<<"nEnter the data:";
cin>>item->name>>item->code;
item->next=NULL;
point->next=item;
//connect the nodes
point=item; //shift the pointer to the point node
}
cout<<"Enter the code of the node";
cout<<"to be deleted:";
cin>>ecode;
if(first->code==ecode)
{
point=first;
first=first->next;
delete point;
}
else
{
point=first->next;
back=first;
while(point!=NULL)
{
if(point->code==ecode)
{
back->next=point->next;
delete point;
break;
}
back=point;
point=point->next;
}
}
cout<<"nThe list after deletion is:n";
point=first; //reset point to first node
while(point!=NULL)
{
cout<<point->name<<" "<<point->code<<"n";
point=point->next;
}
}
OUTPUT
Consider the following tables EMPLOYEES and EMPSALARY. Write SQL commands for the statements(i) to (iv) and
give outputs for SQL queries (v) to (viii).
EMPLOYEES
EMPID FIRSTNAME LASTNAME ADDRESS CITY
10 George Smith 83 First Street Howard
105 Mary Jones 842 Vine Ave Loasantiville
152 Sam Tones 33 Elm St Paris
215 Sarah Acherman 440 US 110 Upton
244 Manila Sengupta 24 Friends Street New Delhi
300 Robert Samuel 9 Fifth Cross Washington
335 Henry Williams 12 Moore Street Boston
400 Rachel Lee 121Harrison St New York
441 Peter Thompson 11Red Road Paris
EMPSALARY
EMPID SALARY BENEFITS DESIGNATION
10 75000 15000 Manager
105 65000 15000 Manager
152 80000 25000 Director
215 75000 12500 Manager
244 50000 12000 Clerk
300 45000 10000 Clerk
335 40000 10000 Clerk
400 32000 7500 Salesman
441 28000 7500 Salesman
(a) To display Firstname, Lastname, address and city of all employees leaving in Paris from the table
EMPLOYEES.
SELECT FIRSTNAME,LASTNAME,ADDRESS,CITY FROM EMPLOYEES WHERE CITY='Paris';
(b) To display the content of EMPLOYEES table in descending order of Firstname.
SELECT * FROM EMPLOYEES ORDER BY FIRSTNAME;
(c) To display the Firstname , Lastname, and total salary of all Managers from the
tablesEMPLOYEES and EMPSALARY, where total salary is calculated as SALARY + BENEFITS
SELECT FIRSTNAME,LASTNAME,ES.SALARY+ES.BENEFITS “TOTAL SALARY” FROM
EMPLOYEES,EMPSALARY ES;
(d) To display the maximum salary among Managers and Clerks from the table EMPSALARY.
SELECT DESIGNATIN,MAX(SALARY) FROM EMPSALARY GROUP BY DESIGNATION;
e) Write a query to display employee names whose salary is more than 10000
SELECT * FROM EMPLOYEES E,EMPSALARY ES WHERE E.EMPID=ES.EMPID AND
ES.SALARY>10000
f) To diplay the salary+ benefits of those whose designation is clerk
SELECT (SALARY+BENEFITS) AS TOTAL FROM EMPSALARY WHERE DESIGNATION=”CLERK”
g) To display the designation wise total salary of those employees whose total salary is more than 25000
SELECT SALARY AS “TOTAL SALARY”,DESIGNATION FROM EMPSALARY GROUP BY DESIGNATION
h) To count and display number of employees in each designation
SELECT COUNT(*),DESIGNATION FROM EMPSALARY GROUP BY DESIGNATION
i) To update the benefits by 1500 of each employee
UPDATE EMPSALARY SET BENEFITS=BENEFITS+1500
j) To delete all those employees whose salary is less than 15000
DELETE FROM EMPSALARY WHERE SALARY<15000
k) To add new field in a table empsalary as comm. Integer type
ALTER TABLE EMPSALARY ADD(COMM INT));
(l) SELECT FIRTNAME,SALARY FROM EMPLOYEES, EMPSALARY WHERE
DESIGNATION ='Salesman' AND EMPLOYEES.EMPID =EMPSALARY.EMPID;
Rachel 32000
Peter 28000
(m) SELECT COUNT(DISTINCT DESIGNATION) FROM EMPSALARY;
4
(n) SELECT DESIGNATION,SUM(SALARY) FROM EMPSALARY GROUP BY
DESIGNATION HAVING COUNT(*)>2;
Manager 42500
Clerk 32000

More Related Content

What's hot (20)

PPSX
Stack
Seema Sharma
 
PPTX
Structure in c language
sangrampatil81
 
PDF
OOPs & Inheritance Notes
Shalabh Chaudhary
 
DOC
Jumping statements
Suneel Dogra
 
PPTX
Dynamic memory allocation in c
lavanya marichamy
 
PDF
Java Serialization
imypraz
 
PPTX
Loops in C Programming Language
Mahantesh Devoor
 
PPT
Android - Android Intent Types
Vibrant Technologies & Computers
 
PPTX
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
PPTX
Operator overloading
Ramish Suleman
 
PDF
Constructors and destructors
Nilesh Dalvi
 
PPTX
Unit 2. Elements of C
Ashim Lamichhane
 
PPT
Structure in c
Prabhu Govind
 
PPTX
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
PPTX
C++ decision making
Zohaib Ahmed
 
PDF
Constructor and Destructor
Kamal Acharya
 
PPT
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
PPTX
Python dictionary
Mohammed Sikander
 
PPTX
Applets in java
Wani Zahoor
 
PPT
pointers
teach4uin
 
Structure in c language
sangrampatil81
 
OOPs & Inheritance Notes
Shalabh Chaudhary
 
Jumping statements
Suneel Dogra
 
Dynamic memory allocation in c
lavanya marichamy
 
Java Serialization
imypraz
 
Loops in C Programming Language
Mahantesh Devoor
 
Android - Android Intent Types
Vibrant Technologies & Computers
 
[OOP - Lec 19] Static Member Functions
Muhammad Hammad Waseem
 
Operator overloading
Ramish Suleman
 
Constructors and destructors
Nilesh Dalvi
 
Unit 2. Elements of C
Ashim Lamichhane
 
Structure in c
Prabhu Govind
 
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
C++ decision making
Zohaib Ahmed
 
Constructor and Destructor
Kamal Acharya
 
Structure of C++ - R.D.Sivakumar
Sivakumar R D .
 
Python dictionary
Mohammed Sikander
 
Applets in java
Wani Zahoor
 
pointers
teach4uin
 

Similar to project report in C++ programming and SQL (20)

PDF
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
DOC
programming in C++ report
vikram mahendra
 
PPT
Apclass (2)
geishaannealagos
 
PPT
Apclass
geishaannealagos
 
PDF
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
DOCX
Practical File of c++.docx lab manual program question
vidhimangal05
 
PDF
Lecture 1
Jehangir Khan
 
DOCX
Oops practical file
Ankit Dixit
 
DOCX
Computer Practical XII
Ûťţåm Ğűpţä
 
PPTX
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
PPT
Apclass (2)
geishaannealagos
 
PDF
c++ practical Digvajiya collage Rajnandgaon
yash production
 
PDF
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
DOCX
Cs pritical file
Mitul Patel
 
PDF
Functions
Swarup Kumar Boro
 
DOCX
12th CBSE Practical File
Ashwin Francis
 
PDF
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
PPTX
Example Programs of CPP programs ch 1.pptx
DrVikasMahor
 
PDF
Mid term sem 2 1415 sol
IIUM
 
CBSE Question Paper Computer Science with C++ 2011
Deepak Singh
 
programming in C++ report
vikram mahendra
 
Apclass (2)
geishaannealagos
 
Object Oriented Programming Using C++ Practical File
Harjinder Singh
 
Practical File of c++.docx lab manual program question
vidhimangal05
 
Lecture 1
Jehangir Khan
 
Oops practical file
Ankit Dixit
 
Computer Practical XII
Ûťţåm Ğűpţä
 
KMK1093 CHAPTER 2.kkkpptx KMK1093 CHAPTER 2.kkkpptx
JessylyneSophia
 
Apclass (2)
geishaannealagos
 
c++ practical Digvajiya collage Rajnandgaon
yash production
 
I PUC CS Lab_programs
Prof. Dr. K. Adisesha
 
Cs pritical file
Mitul Patel
 
12th CBSE Practical File
Ashwin Francis
 
Acm aleppo cpc training second session
Ahmad Bashar Eter
 
Example Programs of CPP programs ch 1.pptx
DrVikasMahor
 
Mid term sem 2 1415 sol
IIUM
 
Ad

More from vikram mahendra (20)

PPTX
Communication skill
vikram mahendra
 
PDF
Python Project On Cosmetic Shop system
vikram mahendra
 
PDF
Python Project on Computer Shop
vikram mahendra
 
PDF
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
PDF
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
PPTX
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
PPTX
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
PPTX
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART1
vikram mahendra
 
PPTX
OPERATOR IN PYTHON-PART2
vikram mahendra
 
PPTX
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
PPTX
DATA TYPE IN PYTHON
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
PPTX
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
PPTX
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
PPTX
Python Introduction
vikram mahendra
 
PPTX
GREEN SKILL[PART-2]
vikram mahendra
 
PPTX
GREEN SKILLS[PART-1]
vikram mahendra
 
PPTX
Dictionary in python
vikram mahendra
 
Communication skill
vikram mahendra
 
Python Project On Cosmetic Shop system
vikram mahendra
 
Python Project on Computer Shop
vikram mahendra
 
PYTHON PROJECT ON CARSHOP SYSTEM
vikram mahendra
 
BOOK SHOP SYSTEM Project in Python
vikram mahendra
 
FLOW OF CONTROL-NESTED IFS IN PYTHON
vikram mahendra
 
FLOWOFCONTROL-IF..ELSE PYTHON
vikram mahendra
 
FLOW OF CONTROL-INTRO PYTHON
vikram mahendra
 
OPERATOR IN PYTHON-PART1
vikram mahendra
 
OPERATOR IN PYTHON-PART2
vikram mahendra
 
USE OF PRINT IN PYTHON PART 2
vikram mahendra
 
DATA TYPE IN PYTHON
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
vikram mahendra
 
USER DEFINE FUNCTIONS IN PYTHON
vikram mahendra
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
vikram mahendra
 
INTRODUCTION TO FUNCTIONS IN PYTHON
vikram mahendra
 
Python Introduction
vikram mahendra
 
GREEN SKILL[PART-2]
vikram mahendra
 
GREEN SKILLS[PART-1]
vikram mahendra
 
Dictionary in python
vikram mahendra
 
Ad

Recently uploaded (20)

PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
PPTX
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
DOCX
DLL english grade five goof for one week
FlordelynGonzales1
 
DOCX
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
PDF
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
PPTX
How to use _name_search() method in Odoo 18
Celine George
 
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
PPTX
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
 
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
DLL english grade five goof for one week
FlordelynGonzales1
 
MUSIC AND ARTS 5 DLL MATATAG LESSON EXEMPLAR QUARTER 1_Q1_W1.docx
DianaValiente5
 
THE PSYCHOANALYTIC OF THE BLACK CAT BY EDGAR ALLAN POE (1).pdf
nabilahk908
 
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
 
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
 
How to use _name_search() method in Odoo 18
Celine George
 
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
COM and NET Component Services 1st Edition Juval Löwy
kboqcyuw976
 
Project 4 PART 1 AI Assistant Vocational Education
barmanjit380
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Urban Hierarchy and Service Provisions.pptx
Islamic University of Bangladesh
 

project report in C++ programming and SQL

  • 1. ……………… PUBLIC SENIOR SECONDARY SCHOOL,………………. PROGRAMMINING in SUBMITTED TO SUBMITTED BY ……………………. ……………………… (Computer Science) XII B
  • 2. ACKNOWLEDGEMENT I would like to convey my heartful thanks to …………………. (Computer Science) who always gave valuable suggestions & guidance for completion of my project. he helped me to understand & remember important details of the project. My project has been a success only because of his guidance. I am especially indented & I am also beholden to my friends. And finally I thank to the members of my family for their support & encouragement.
  • 3. CERTIFICATE This is to certify that …………………. of class ………. of ………PUBLIC SENIOR SECONDARY SCHOOL , ………….has completed his project under my supervision. He has taken proper care & shown sincerity in completion of this project. I certify that this project is up to my expectation & as per the guideline issued by CBSE. . ………………………… (Computer Science faculty )
  • 4. INDEX SNO PROGRAMMING DESCRIPTION SIGNATURE 1 Program to find area of triangle using function overloading 2 Program to keep record of books & Audio Cassettes 3 Write a function to count and print the number of complete words as “to” and “are” stored in a text file “ESSAY.TXT”. 4 Write a function in C++ to display object from the binary file “PRODUCT.DAT” whose product price is more than Rs 30. Assuming that binary file is containing the objects of the following class: 5 Program to enter the choice by the user using switch-case and display the result 6 Program to enter a string and find its length and print the string in reverse order 7 Program to enter an integer and output the cube of that integer 8 Program to enter an integer and print out its successor 9 Program to enter the information in a text file and display it on the screen by the choice of the user 10 Write a program to convert octal number to binary number and display it 11 Write a program to calculate number of upper and lower case vowels and consonants and display it 12 Write a program to search the position of a substring and display it 13 Write a program to remove given integer from array, shift elements to right and fill space by 0 and display it 14 Write a program to print upper and lower half of matrix 15 Write a program to implement link list for the ticket entry system 16 Write a program to implement linked queue with list of names. 17 Program to display the list of students, the records of the students will be sorted in descending order of the marks obtained by the students 18 program to enter the lines in a file and convert them into upper case 19 Program to display volume that uses three elements (length, width and height) of type distance. This type, in turn has two elements (feet and inches).Calculate volume of a room using structure 20 Program to enter student details using a pointer to an object 21 Program to enter and display employee details using multi_level inheritance. 22 Program to enter the information of employee and then search the record and deleting a node of a linked list
  • 6. //Program to find area of triangle using function overloading #include<iostream.h> #include<conio.h> #include<process.h> #include<math.h> //function 1 void area(float r) {float area_c; area_c=(3.14*r*r); cout<<"Area of the circle="<<area_c<<endl; } //function 2 void area(int l,int h) {float area_r; area_r=l*h; cout<<"Area of the rectangle = "<<area_r<<endl; } //function 3 void area(float a,float b,float c) {float s,area_t ; s=(a+b+c)/2; area_t=pow((s*(s-a)*(s-b)*(s-c)),0.5); cout<<"Area of the triangle = "<<area_t<<endl; } void main() { clrscr(); int ch; float r,a,b,c,l,h; cout<<"1.Area of circle"<<endl<<"2.Area of rectangle"<<endl;cout<<"3.Area of triangle"<<endl<<"4.Exit"<<endl; X: cout<<"Enter the choice"<<endl; cin>>ch; switch(ch) { case 1:cout<<"Enter the radius of the circle"<<endl; cin>>r; void area (float); area(r); goto X; case 2:cout<<"Enter the sides of rectangle"<<endl; cin>>l>>h; void area (float,float); area (l,h); goto X; case 3:cout<<"Enter the sides of triangle"<<endl; cin>>a>>b>>c; void area (float,float,float); area (a,b,c); goto X; case 4:exit(0); default:cout<<"Wrong Choice"<<endl; goto X;} getch();} OUTPUT 1. Area Of Circle 2. Area Of Rectangle 3. Area Of Triangle 4. Exit Enter The Choice: Enter the radius of the circle: 5 Area Of Circle: 78.5
  • 7. //Program to keep record of books & Audio Cassettes #include<iostream.h> #include<conio.h> #include<process.h> #include<stdio.h> class publication { char title[20]; float price; public: void getdata() { cout<<"Enter Title"<<endl; gets(title); cout<<"Enter Price"<<endl; cin>>price; } void putdata() { cout<<"Title"<<endl; puts(title); cout<<"Price"<<endl; cout<<price; }}; class book : protected publication { int pagecount; public: void putdata() { publication :: putdata(); cout<<endl<<"Pg Count"<<endl; cout<<pagecount; } void getdata() { publication::getdata(); cout<<"Pg Count"<<endl; cin>>pagecount; } }; class tape : protected publication { float time; public: void getdata() { publication :: getdata(); cout<<"Enter Time"<<endl; cin>>time; } void putdata() { publication :: putdata(); cout<<endl<<"Time "<<endl; cout<<time; } }; void main() { clrscr(); book b; tape t; int ch; x: { cout<<endl<<"1. BOOK 2:Tape 3:Exit "<<endl; cin>>ch; switch(ch) { case 1:b.getdata(); b.putdata(); goto x; case 2:t.getdata(); t.putdata(); goto x; case 3:exit(0); } } getch(); } OUTPUT
  • 8. /*Write a function to count and print the number of complete words as “to” and “are” stored in a text file “ESSAY.TXT”. */ void CWORDS( ) { ifstream fin(“ESSAY.TXT”); char st[80]; int count=0; while(!fin.eof()) { fin>>st; if(!fin) break; if(strcmpi(st,”to”) = =0 || strcmpi(st,”are”)= =0) count++; } cout<<”nTotal ‘to’ & ‘are’ words = “<<count; fin.close( ); } void main() { CWORDS(); } OUTPUT Total to and are words are :7
  • 9. /*Write a function in C++ to display object from the binary file “PRODUCT.DAT” whose product price is more than Rs 30. Assuming that binary file is containing the objects of the following class: */ class PRODUCT { int PRODUCT_no; char PRODUCT_name[20]; float PRODUCT_price; public: void enter( ) { cin>> PRODUCT_no ; gets(PRODUCT_name) ; cin >> PRODUCT_price; } void display() { cout<< PRODUCT_no<<” “<<PRODUCT_name<<” “<< PRODUCT_price; } int ret_Price( ) { return PRODUCT_price; } }; void Rec_display() { Product P; ifstream ifile(“PRODUCT.Dat”, ios::binary); if(!ifile) { cout<<”n File doesn’t exist”; exit(0); } else { cout<<”nPRODUCT_no PRODUCT_name PRODUCT_pricen”; while(ifile.read((char *)&P, sizeof(P))) { if (P.ret_Price()>30) P.display(); } } } OUTPUT PRODUCT_no PRODUCT_name PRODUCT_price 101 colgate 45 105 Nescafe 85 108 Panteen 105
  • 10. //Program to enter the choice by the user using switch-case and display the result #include <iostream.h> #include <conio.h> int main() { clrscr(); int choice; cout << "1. Talk" << endl; cout << "2. Eat" << endl; cout << "3. Play" << endl; cout << "4. Sleep" << endl; cout << "Enter your choice : " << endl; cin>>choice; switch(choice) { case 1 : cout << "You chose to talk...talking too much is a bad habit." << endl; break; case 2 : cout << "You chose to eat...eating healthy foodstuff is good." << endl; break; case 3 : cout << "You chose to play...playing too much everyday is bad." << endl; break; case 4 : cout << "You chose to sleep...sleeping enough is a good habit." << endl; break; default : cout << "You did not choose anything...so exit this program." << endl; } getch(); } OUTPUT This program takes in the user's choice as a screen input. Depending on the user's choice, it switches between the different cases. The appropriate message is then outputted using the 'cout' command.
  • 11. //Program to enter a string and find its length and print the string in reverse order. #include <iostream.h> #include <conio.h> #include <string.h> void main() { clrscr(); int slength; char str[81]; //Allowing the user to input a maximum of 80 characters. cout << "Enter the string : " << endl; cin>>str; slength=strlen(str); cout << "The length of the string " << str << " is " << slength << "." << endl; cout<<”Reverse string is:”; for(int x=slength-1;x>=0;x--) cout<<str[x]; getch(); } OUTPUT Enter the string : COMPUTER The length of the string COMPUTER is 8 Reverse string is: RETUPMOC
  • 12. //Program to enter an integer and output the cube of that integer #include <iostream.h> #include <conio.h> int cube(int x); //The prototype. void main() { clrscr(); int a; cout << "Enter an integer : "; cin>>a; cout << "The cube of " << a << " is : " << cube(a) << endl; //Call the function cube(a). getch(); } //Defining the function. int cube(int x) { int y; y=x*x*x; return(y); } OUTPUT Enter the integer:8 The cube of 8 is : 512
  • 13. //Program to enter an integer and print out its successor #include <iostream.h> #include <conio.h> void value(int); void main() { clrscr(); int x; cout << "Enter an integer : "; cin>>x; cout << "The successor of " << x << " is "; value(x); getch(); } void value(int x) { x++; cout << x << "." << endl; } OUTPUT: Enter the integer:49 The successor of 49 is 50.
  • 14. /*Program to enter the information in a text file and display it on the screen by the choice of the user*/ #include<iostream.h> #include<fstream.h> #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<ctype.h> class what { char str[40]; public: void create(); void display(); void c_lower(); void dis_lower(); }; void what::dis_lower() { char ch4; ifstream obj5("story1.dat"); cout<<"nDisplay the datan"; while(!obj5.eof()) { obj5.get(ch4); cout<<ch4; //obj5.getline(str,80); //cout<<str<<"n"; } obj5.close(); } void what::c_lower() {char ch,ch3; ofstream obj3("story1.dat"); ifstream obj4("story.txt"); while(obj4) {obj4.get(ch); if(ch!='n') { if(islower(ch)) {cout<<"nch="<<ch; obj3<<ch; }else { ch3=tolower(ch); obj3<<ch3; cout<<"nch="<<ch<<" ch3="<<ch3; } }else{ obj3<<'n'; }} obj3.close(); obj4.close(); } void what::display() {ifstream obj1("story.txt"); cout<<"nDisplay the datan"; while(obj1) {obj1.getline(str,40,'n'); cout<<str<<"n"; } obj1.close(); } void what::create() {ofstream obj("story.txt");
  • 15. char c2; do {cout<<"nEnter the line of text"; gets(str); obj<<str<<"n"; cout<<"nDo you want to add more text(y/n)"; cin>>c2; }while(c2=='y'); obj.close(); } void main() {what whatobj; int c1=0; do { cout<<"n1-create the file"; cout<<"n2-Display the file"; cout<<"n3-Create the file lower case"; cout<<"n4-Display the file lower case"; cin>>c1; switch(c1) { case 1: whatobj.create(); break; case 2: whatobj.display(); break; case 3: whatobj.c_lower(); break; case 4: whatobj.dis_lower(); break; } }while(c1!=5); } OUTPUT 1-create the file 2-Display the file 3-Create the file lower case 4-Display the file lower case Enter the choice:1 TYPE THE CONTENT UNTIL YOU PRESS ENTER KEY Do you want to add more text(y/n)n 1-create the file 2-Display the file 3-Create the file lower case 4-Display the file lower case Enter the choice:3 convert all the upper case character to lower case character
  • 16. //Write a program to convert octal number to binary number and display it? #include<iostream.h> #include<conio.h> #include<iomanip.h> int calc (int oct, int bin[]) { int k=0,rem; while (oct>0) { rem=oct%2; bin[k]=rem; oct=oct/2; k++; } return k-1; } void main () { clrscr(); int oct,bin[20],c,k; cout<<"n Enter two digit octal number ="; cin>>oct; k=calc(oct,bin); cout<<"n The binary equivalent ="; for (c=k;c>=0;c--) cout<<setw (2)<<bin[c]; getch (); } OUTPUT
  • 17. /* Write a program to calculate number of upper and lower case vowels and consonants and display it?*/ #include<iostream.h> #include<conio.h> #include<ctype.h> #include<stdio.h> void output (char str[100]) { int c=0,uv=0,uc=0,lc=0,lv=0; while (str[c] != '0') { if (isupper(str[c])) if (str[c]=='A'|| str[c]=='E'|| str[c]=='I'|| str[c]=='O'|| str[c]=='U') uv+=1; else uc+=1; else if (islower(str[c])) if (str[c]=='a'|| str[c]=='e'|| str[c]=='i'|| str[c]=='o'|| str[c]=='u') lv+=1; else lc+=1; c++; } cout<<"n upper case of vowels="<<uv<<endl; cout<<"n upper case of consonants="<<uc<<endl; cout<<"n lower case of vowels="<<lv<<endl; cout<<"n lower case of consonants="<<lc<<endl; } void main () { char str[100]; cout<<"n Enter the string "; gets (str);fflush (stdin); output (str); getch (); } OUTPUT
  • 18. //Write a program to search the position of a substring and display it? #include<iostream.h> #include<conio.h> #include<stdio.h> #include <string.h> int search (char str[50],char str1[20]) { int c=0,d,x=0,y; char str2[25]; while (str[c] != '0') { d=0; while (str[c] !=' ') { str2[d]=str[c]; c++ ; d++; } str2[d]='0'; c++; x+=1; if (strcmp (str2,str1)==0) y=x; } return y; } void main () { char str[50],str1[20]; int k; cout <<"n Enter any string "; gets (str); fflush (stdin); cout <<"n Enter the substring to be searched "; gets (str1); fflush (stdin); k=search (str,str1); cout<<"n the position of substring ="<<k; getch (); } OUTPUT
  • 19. /*Write a program to remove given integer from array, shift elements to right and fill space by 0 and display it?*/ #include<iostream.h> #include<conio.h> #include<iomanip.h> void shift (int a[],int val,int n) { int k,pos,c; for (c=0;c<n;c++) if (a[c]==val) { pos=c; for(k=pos;k>0;k--) a[k]=a[k-1]; a[0]=0; }} void main () { clrscr(); int a[20],c,n,val; cout<<"n Enter number of terms = "; cin>>n; for (c=0;c<n;c++) { cout<<"n Enter array elements = "; cin>>a[c]; } cout <<"n Enter the value to be deleted = "; cin >> val; cout <<"nnn The input array nn "<<endl; for (c=0; c<n; c++) cout<<" "<<a[c]; shift (a,val,n); cout <<"nnn The output array nn"<<endl; for (c=0;c<n;c++) cout<<" "<<a[c]; getch (); } OUTPUT
  • 20. // Write a program to print upper and lower half of matrix? #include<iostream.h> #include<conio.h> #include<iomanip.h> void upperhalf (int mat[10][10],int m,int n) { int c,r; for (r=0;r<n;r++) { cout<<setw ((r+1)*4); for(c=r;c<m;c++) cout<<mat[r][c]<<setw (4); cout<<"nnnn"; } } void lowerhalf (int mat[10][10],int n) { int c,r; for (r=0;r<n;r++) { for(c=0;c<=r;c++) cout<<setw (4)<<mat[r][c]; cout<<"nnnn"; } } void main () { clrscr(); int mat[10][10],m,n,c,r; char choice; cout<<"n Enter number of rows and column = "; cin>>n>>m; for(r=0;r<n;r++) for (c=0;c<m;c++) { cout<<"n Enter matrix elements = "; cin>>mat[r][c]; } clrscr(); do { clrscr(); cout<<"n Enter u for printing of upper half of matrix"<<endl; cout<<"n Enter l for printing of lower half of matrix"<<endl; cout<<"n Enter q for quit"<<endl; cout<<"n Enter your choice ="; cin>>choice; switch (choice) { case 'u': upperhalf(mat,m,n); break; case 'l': lowerhalf(mat,n); break; } getch (); } while (choice != 'q'); } OUTPUT
  • 21. //Write a program to implement link list for the ticket entry system #include<iostream.h> #include<conio.h> struct train { int tno; char pname[25]; char des_name[25]; int dis; train *next; }; class journey { train *top; public: journey() { top=NULL; } void push(); void pop(); void display(); }; void journey::push() { train *tmp; tmp=new train; cout<<"nEnter the Ticket No:"; cin>>tmp->tno; cout<<"nEnter the Passanger name:"; cin>>tmp->pname; cout<<"nEnter the destination name:"; cin>>tmp->des_name; cout<<"nEnter the distance:"; cin>>tmp->dis; tmp->next=NULL; if(top==NULL) {top=tmp; }else {tmp->next=top; //delete top; top=tmp; }//delete tmp; } void journey::pop() { if(top==NULL) {cout<<"nStack is empty"; }else {top=top->next; } } void journey::display() {train *t; t=top; while(t!=NULL) {cout<<"n"<<t->tno<<"tt"<<t->pname<<"tt"<<t->des_name<<"tt"<<t->dis; t=t->next; }} void main() {int ch=0; journey jobj; do {cout<<"n1-pushn2-popn3-Display"; cin>>ch;
  • 22. switch(ch) {case 1: jobj.push(); break; case 2: jobj.pop(); break; case 3: jobj.display(); break; } }while(ch!=4); } OUTPUT
  • 23. //Write a program to implement linked queue with list of names. #include<iostream.h> #include<conio.h> struct members { char name[25]; members *link; }; class queue { members *rear,*front; public: queue() { rear=NULL; front=NULL; } void input(); void del(); void dis(); }; void queue::input() { members *tmp; tmp=new members; cout<<"nEnter the name:"; cin>>tmp->name; tmp->link=NULL; if(rear==NULL) { cout<<"nFirst"; rear=tmp; front=tmp; } else { rear->link=tmp; rear=tmp; } } void queue::del() { if(front==NULL) { cout<<"nQueues of names are empty"; } else { front=front->link; } } void queue::dis() { members *t; t=front; while(t!=NULL) { cout<<"n Name:"<<t->name; t=t->link; } } void main() {
  • 24. int ch=0; queue obj; do { clrscr(); cout<<"n1-PUSHn2-POPnDISPLAYnEnter the choice:"; cin>>ch; switch(ch) { case 1: obj.input(); break; case 2: obj.del(); break; case 3: obj.dis(); break; } getch(); }while(ch!=4); } OUTPUT
  • 25. /* Program to display the list of students, the records of the students will be sorted in descending order of the marks obtained by the students.*/ #include <iostream.h> #include <conio.h> #include <stdio.h> #include <iomanip.h> class student { char name[15]; int rollno; int marks; public:void read_data(); int get_marks(); void display_data(); }; void student::read_data() { cout<<"n Enter name"; gets(name); fflush(stdin); cout<<"n Enter roll and marks"; cin>>rollno>>marks; } int student::get_marks() { return marks; } void student:: display_data() { cout<<endl<<setw(9)<<name; cout<<setw(7) <<rollno<<setw(5)<<marks; } void sort_list(student s[],int n); void main() { int n; student stud_list[50]; cout<<"n Enter the Number of students"; cin>>n; for(int i=0;i<n;i++) stud_list[i].read_data(); sort_list(stud_list,n); //sort the list clrscr(); cout<<"n List of students n"; cout<<"n Name Rollno Marks"; for(i=0;i<n;i++) stud_list[i].display_data(); } void sort_list(student s[],int n) { int i,j; student temp; for(i=0;i<n-1;i++) { for(j=i+1;j<n;j++) { if(s[i].get_marks()<s[j].get_marks()) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } } } OUTPUT
  • 26. //program to enter the lines in a file and convert them into upper case #include<fstream.h> #include<stdio.h> #include<conio.h> #include<ctype.h> void main() {char fname[15]; char row[80]; int count,;cout<<"n enter the name of the file to be created"; gets(fname); ofstream myfile(fname); char ch; while(1) {cout<<"n enter a line of text"; gets(row); mylife<<row<<"n"; cout<<"n want to continue ? y/n"; cin>>ch; if((ch=='N')||(ch=='n')) break; }myfile.close(); ofstream tempfile("temp"); ifstream newfile(fname); while(newfile) { newfile.get(ch); if(ch!='n') ch=toupper(ch); tempfile.put(ch); } newfile.close(); tempfile.close(); clrscr(); cout<<"n the output of file is ...n"; ifstream yourfile("temp"); count=0; while(!yourfile.eof() ) { yourfile.getline(row,80); cout<<row<<'n'; count++; if((count%22)==0) { cout<<"n enter any key to continue"; cin>>ch; } } yourfile.close(); } OUTPUT Enter the name of the file:ABC.txt The name of the text book is computer science THE NAME OF THE TEXT BOOK IS COMPUTER SCIENCE
  • 27. /*Program to display volume that uses three elements (length, width and height) of type distance. This type, in turn has two elements (feet and inches).Calculate volume of a room using structure.*/ #include<iostream.h> #include<conio.h> struct distance { float feet; float inches; }; struct volume { distance length; distance width; distance height; }vol; void main() { float tot_length,tot_width,tot_height; float v; clrscr(); cout<<"Enter length in feet:"; cin>>vol.length.feet; cout<<"Enter length in inches:"; cin>>vol.length.inches; cout<<"Enter width in feet:"; cin>>vol.width.feet; cout<<"Enter width in inches:"; cin>>vol.width.inches; cout<<"Enter height in feet:"; cin>>vol.height.feet; cout<<"Enter height in inches:"; cin>>vol.height.inches; tot_length=vol.length.feet+vol.length.inches/12; tot_width=vol.width.feet+vol.width.inches/12; tot_height=vol.height.feet+vol.height.inches/12; cout<<tot_length<<"n"; cout<<tot_width<<"n"; cout<<tot_height<<"n"; v=tot_length*tot_width*tot_height; cout<<"The volume is :"; cout<<v; } OUTPUT
  • 28. // Program to enter student details using a pointer to an object. #include<iostream.h> #include<conio.h> class student { char name[15]; int roll; public: void get_data() { cout<<"n enter the data"; cout<<"n name"; cin>>name; cout<<"roll:"; cin>>roll; } void show_data() { cout<<"n the data is.."; cout<<"n name:"; cout<<name; cout<<"n roll:"; cout<<roll; } }; main() { student *objptr; objptr=new student; objptr->get_data(); objptr->show_data(); return 0; } OUTPUT
  • 29. //Program to enter and display employee details using multi_level inheritance. #include <iostream.h> #include <conio.h> class employee //base class { protected: int emp_code; public: void get_code(int); void put_code(void); }; void employee::get_code(int a) {emp_code=a;} void employee::put_code() { cout<<"Employee Code:"<<emp_code<<"n"; } class salary:public employee //first_level derivation { protected: float basic; float da; float hra; public: void get_sal(float,float,float); void put_sal(void); }; void salary::get_sal(float x, float y, float z) { basic=x; da=y; hra=z; } void salary::put_sal() { cout<<"Basic:"<<basic<<"n"; cout<<"DA:" <<da<<"n"; cout<<"HRA:"<<hra<<"n"; } class payroll:public salary //second_level derivation { float gross; public: void display(void); }; void payroll::display(void) { gross=basic+da+hra; put_code(); put_sal(); cout<<"Gross:"<<gross<<"n"; } void main() { payroll emp1; emp1.get_code(101); emp1.get_sal(5000.0,2400.0,1800.0); emp1.display(); } OUTPUT
  • 30. //Program to enter the information of employee and then search the record and deleting a node of a linked list #include<iostream.h> #include<conio.h> void main() { struct emp { char name[20]; int code; emp *next; //self-referential structure }; emp *point,*item,*first,*back; int i,n,found; int ecode; cout<<"nEnter the size of the list to be created"; cin>>n; if(n<=0) { cout<<"nError!"; } first=new emp; cout<<"nEnter the data:"; cin>>first->name>>first->code; first->next=NULL; point=first; //linked list creation for(i=1;i<n;i++) { item=new emp; cout<<"nEnter the data:"; cin>>item->name>>item->code; item->next=NULL; point->next=item; //connect the nodes point=item; //shift the pointer to the point node } cout<<"Enter the code of the node"; cout<<"to be deleted:"; cin>>ecode; if(first->code==ecode) { point=first; first=first->next; delete point; } else { point=first->next; back=first; while(point!=NULL) { if(point->code==ecode) { back->next=point->next; delete point; break; } back=point; point=point->next; } } cout<<"nThe list after deletion is:n"; point=first; //reset point to first node while(point!=NULL) { cout<<point->name<<" "<<point->code<<"n"; point=point->next; } } OUTPUT
  • 31. Consider the following tables EMPLOYEES and EMPSALARY. Write SQL commands for the statements(i) to (iv) and give outputs for SQL queries (v) to (viii). EMPLOYEES EMPID FIRSTNAME LASTNAME ADDRESS CITY 10 George Smith 83 First Street Howard 105 Mary Jones 842 Vine Ave Loasantiville 152 Sam Tones 33 Elm St Paris 215 Sarah Acherman 440 US 110 Upton 244 Manila Sengupta 24 Friends Street New Delhi 300 Robert Samuel 9 Fifth Cross Washington 335 Henry Williams 12 Moore Street Boston 400 Rachel Lee 121Harrison St New York 441 Peter Thompson 11Red Road Paris EMPSALARY EMPID SALARY BENEFITS DESIGNATION 10 75000 15000 Manager 105 65000 15000 Manager 152 80000 25000 Director 215 75000 12500 Manager 244 50000 12000 Clerk 300 45000 10000 Clerk 335 40000 10000 Clerk 400 32000 7500 Salesman 441 28000 7500 Salesman (a) To display Firstname, Lastname, address and city of all employees leaving in Paris from the table EMPLOYEES. SELECT FIRSTNAME,LASTNAME,ADDRESS,CITY FROM EMPLOYEES WHERE CITY='Paris'; (b) To display the content of EMPLOYEES table in descending order of Firstname. SELECT * FROM EMPLOYEES ORDER BY FIRSTNAME; (c) To display the Firstname , Lastname, and total salary of all Managers from the tablesEMPLOYEES and EMPSALARY, where total salary is calculated as SALARY + BENEFITS SELECT FIRSTNAME,LASTNAME,ES.SALARY+ES.BENEFITS “TOTAL SALARY” FROM EMPLOYEES,EMPSALARY ES; (d) To display the maximum salary among Managers and Clerks from the table EMPSALARY. SELECT DESIGNATIN,MAX(SALARY) FROM EMPSALARY GROUP BY DESIGNATION; e) Write a query to display employee names whose salary is more than 10000 SELECT * FROM EMPLOYEES E,EMPSALARY ES WHERE E.EMPID=ES.EMPID AND ES.SALARY>10000 f) To diplay the salary+ benefits of those whose designation is clerk SELECT (SALARY+BENEFITS) AS TOTAL FROM EMPSALARY WHERE DESIGNATION=”CLERK” g) To display the designation wise total salary of those employees whose total salary is more than 25000 SELECT SALARY AS “TOTAL SALARY”,DESIGNATION FROM EMPSALARY GROUP BY DESIGNATION h) To count and display number of employees in each designation SELECT COUNT(*),DESIGNATION FROM EMPSALARY GROUP BY DESIGNATION i) To update the benefits by 1500 of each employee UPDATE EMPSALARY SET BENEFITS=BENEFITS+1500 j) To delete all those employees whose salary is less than 15000 DELETE FROM EMPSALARY WHERE SALARY<15000 k) To add new field in a table empsalary as comm. Integer type ALTER TABLE EMPSALARY ADD(COMM INT)); (l) SELECT FIRTNAME,SALARY FROM EMPLOYEES, EMPSALARY WHERE DESIGNATION ='Salesman' AND EMPLOYEES.EMPID =EMPSALARY.EMPID; Rachel 32000 Peter 28000
  • 32. (m) SELECT COUNT(DISTINCT DESIGNATION) FROM EMPSALARY; 4 (n) SELECT DESIGNATION,SUM(SALARY) FROM EMPSALARY GROUP BY DESIGNATION HAVING COUNT(*)>2; Manager 42500 Clerk 32000