Professional Documents
Culture Documents
COMPUTER SCIENCE
2016-2017
NAME:-HIMANSHU
CLASS:-12th
Roll No:Subject Teacher:-Mr. Pankaj
Shukla
Contents
1 Introduction
2 Acknowledgement
3
ARRAY(1-DIMENSIONAL)
i SEARCHING
ii SORTING
iii
MERGING
iv INSERTION
v DELETION OF ELEMENTS
4
ARRAY (1-DIMENSIONAL)
i
CREATION
ii
INSERTION
iii
TRAVERSAL
INTRODUCTION
This file is combo of different C++ Programs. This will enhance the readers
knowledge and will provide a basic view about C++ language.
It also contain SQL programs which is used to retain a database of any type of
information like the information of any school management system, Library system
etc.
Acknowledgment
It is my utmost pleasure to express my sincere thanks to my computer teacher,
Mr Pankaj Shukla, for providing a helping hand in this project. His valuable
guidance, support and supervision helped me to reach up to this level.
I thank our principal for his constant guidance and faith. I express my gratitude to the
school management for providing me this opportunity to work this project out. I would
also like to thank my parents as they encouraged me to put forward my project.
IOSTREAM.H
FSTREAM.H
PROCESS.H
CTYPE.H
CONIO.H
STDIO.H
STIRING.H
C++ PROGRAMS
Array: Array is a collection of variables of the same type that are
referenced by a common name.
I
//declaration of array
ary
int arry[10]={5,6,3,17,4,2,8,9,10,11};
int n=10;
int a
cout<<"\n\tCHOOSE THE OPERATION";
//main menu
cout<<"\n\t1.LINEAR SEARCH";
cout<<"\n\t2.BINARY SERACH";
cout<<"\n\t3.INSERT NEW NUMBER";
cout<<"\n\t4.DELETE A NUMBER";
cout<<"\n\t5.ADD THE ELEMENTS";
cout<<"\n\t6.SELECTION SORTING";
cout<<"\n\t7.BUBBLE SORTING";
cout<<"\n\t8.INSERTION SORT";
cin>>a;
switch(a)
{
case 1: linear(ary,n);
break;
case 2: binary(ary,n);
break;
case 3: insert(ary,n);
break;
case 4: delete_item(ary,n);
break;
case 5: merge(ary,arry);
break;
case 6: selection_sort(arry,n);
break;
case 7: bubble_sort(arry,n);
break;
case 8: insert_sort(arry,n);
break;
default: cout<<"wrong choice";
} }
function close
C++ Output -
//main body
//linear search
over
C++ output-
if(r==0)
cout<<"no such number found";
else
cout<<"the number has been located "<<r;
}
// function binary
search close
C++ output-
//function definition
{clrscr();
int item;
cout<<"enter the number to be inserted";
cin>>item;
int j=n-1;
while(j>=0&&ar[j]>item)
{ar[j+1]=ar[j];
j--; }
ar[j+1]=item;
number
n++;
numbers
//new array
//insert
function close
C++ output-
//function definition
{int item;
cout<<"enter the number to be deleted";
cin>>item;
number
//store the
int j=0;
while(j<n&&ar[j]<item)
j++;
if(ar[j]==item)
value
{ while(j<n)
{ ar[j]=ar[j+1];
value
//replacing the
j++; }
cout<<"\nelement is deleted\n";
n--;
numbers
//decreasing the
//new array
//delete function
C++ output-
{
cout<<"\t\tnew["<<l<<"]= "<<newa[l]<<"\n";
}//for
getche();
}//merging two array
C++ output-
C++ output-
//replacing the
ar[j+1]=ar[j];
ar[j]=sml; }//if
}//for j }//for i
cout<<"\t\tarray after complete sorting:\n";
for(int k=0;k<n;k++)
cout<<"\n\t\t\tarray["<<k<<"]="<<ar[k]; }
function close
//bubble sorting
C++ output-
C++ output-
C++ output-
class student
{ private:
int rno;
//data members
float mrk;
public:
student()
//constructor
{rno=1;
mrk=90; }
void display()
//member function
{cout<<"rno ="<<rno;
cout<<"\nmrk ="<<mrk; }
};
void main()
//main function
{ student S1;
S1.display();
C++ output-
Inheritance in class :
C++ codeint area();
class shape
{ public:
int length ,width;
private:
//function prototype
//class(I) declaration
int setl(int i)
{ length=i;
return(0); }
int setw(int i)
{ width=i;
return(0); } };
class price
//class(II) declaration
{ public:
int setprc(int i)
{ int price=i*100;
return price; } };
class rectangle:public shape,public price //class(III)declaration and
inheritance
{ public:
int area()
{ int i;
i=length*width;
return(i); } };
void main()
{ clrscr();
int a,b,c,d;
cout<<"enter the length ";
cin>>a;
cout<<"enter the width ";
cin>>b;
rectangle rect;
rect.setl(a);
rect.setw(b);
c=rect.area();
C++ output-
IV STACKS :
Stack using array:
C++ code# include<iostream.h>
# include<conio.h>
void PUSH();
void POP();
class stack
{ private:
int ar[5];
int top;
public:
stack()
{ top=-1; }
void push(int item)
{ if(top==-1||top<4)
{ ar[top]=item;
top++;
cout<<"\nar["<<top<<"] ="<<item; }
else
getche(); }
void POP()
{ cout<<"pop:\n";
for(int i=0;i<6;i++)
{ S1.pop(); } }
C++ output-
void pop();
void display();
~stack()
{}//destructor
}st;//class stack
void stack::push()
{node*temp;
temp=new node;
cout<<"enter value";
cin>>temp->data;
temp->next=top;
top=temp;}
void stack::pop()
{ if(top!=NULL)
{ node*temp=top;
top=top->next;
delete temp;
cout<<"\nNEW STACK:";
st.display(); }//if
else cout<<"the stack is empty";}
void stack::display()
{ if(top==NULL)
cout<<"the stack is empty";
node*temp=top;
while(temp!=NULL)
{ cout<<"\nthe values are";
cout<<"\n"<<temp->data;
temp=temp->next;
}
}
void main()
{
char ch;
do{ cout<<"\n\t\tStack option";
cout<<"\n\tP:for push";
cout<<"\n\tO:for pop";
cout<<"\n\tD:for display";
cout<<"\n\tQ:for quit";
cin>>ch;
switch(ch)
{
case'P':st.push();
break;
case'O':st.pop();
break;
case'D':st.display();
break;
case'Q':exit(0);
break;
default:cout<<"\nWrong choice";
}
}
while(ch!='Q');//do while
}
C++ output-
C++ output-
C++ code#include<conio.h>
#include<iostream.h>
#include<process.h>
#include<malloc.h>
struct node
// Creating a NODE Structure
{ int data;
struct node *next; };
class queue
// Creating a class QUEUE
{ struct node *frnt,*rear;
public:
queue() // constructure
{ frnt=rear=NULL; }
void insert(); // to insert an element
void del(); // to delete an element
void show(); // to show the stack };
void queue::insert()
// Insertion
{ int value;
struct node *ptr;
cout<<"\nInsertion\n";
cout<<"Enter a number to insert: ";
cin>>value;
ptr=new node;
ptr->data=value;
ptr->next=NULL;
if(frnt==NULL)
frnt=ptr;
else rear->next=ptr;
rear=ptr;
cout<<"\nNew item is inserted to the Queue!!!";
getch(); }
void queue::del()
// Deletion
{ if(frnt==NULL)
{ cout<<"\nQueue is empty!!";
getch();
return; }
struct node *temp;
temp=frnt;
frnt=frnt->next;
cout<<"\nDeletion Operation........\nDeleted value is "<<temp->data;
delete temp;
getch(); }
void queue::show()
// Show Queue
{ struct node *ptr1=frnt;
if(frnt==NULL)
{ cout<<"The Queue is empty!!";
getch();
return; }
cout<<"\nThe Queue is\n";
while(ptr1!=NULL)
{
cout<<ptr1->data<<" ->";
ptr1=ptr1->next; }
cout<<"END";
getch();}
int main()
{ clrscr();
queue q;
int choice;
while(1)
{cout<<"\n-----------------------------------------------------------";
cout<<"\n\t\tQUEUE USING LINKED LIST\n\n";
cout<<"1:INSERTION\n2:DELETION\n3:DISPLAY QUEUE\n4:EXIT";
cout<<"\nEnter your choice(1-4): ";
cin>>choice;
switch(choice)
{
case 1: q.insert();
break;
case 2: q.del();
break;
case 3:q.show();
break;
case 4: exit(0);
break;
default: cout<<"Please enter correct choice(1-4)!!";
getch();
break; }}return 0;}
C++ output-
inFile.open("studentA.dat", ios::binary);
Student obj;
while(inFile.read((char*)&obj, sizeof(obj)))
{ if(obj.retAdmno() == n)
{
obj.showData();} }
inFile.close(); }
void delete_record(int n)
// function to delete a record
{ Student obj;
ifstream inFile;
inFile.open("studentA.dat", ios::binary);
ofstream outFile;
outFile.open("temp.dat", ios::out | ios::binary);
while(inFile.read((char*)&obj, sizeof(obj)))
{ if(obj.retAdmno() != n)
{
outFile.write((char*)&obj, sizeof(obj)); }}
inFile.close();
outFile.close();
remove("studentA.dat");
rename("temp.dat", "studentA.dat"); }
void modify_record(int n)
{ fstream file;
file.open("studentA.dat",ios::in | ios::out);
Student obj;
while(file.read((char*)&obj, sizeof(obj)))
{ if(obj.retAdmno() == n)
{
}}
write_record();
cout << "\nList of records";
display();
cout << "\nSearch result";
search(100);
delete_record(100);
//Search record
//Delete record
//Modify record
return 0;}
C++ output-
int main()
{ofstream fout;
fout.open("out.txt");
char str[300] = "If your ship doesn't come,swim your way out
to reach it.";
fout << str; //Write string to the file.
fout.close();
getche();
ifstream ifile;
ifile.open("out.txt");
char ch;
while(!ifile.eof())
{ ifile.get(ch);
cout<<ch;}
ifile.close();
getche();
return 0; }
C++ output-
5 To delete a record:
SQL code:
delete from customer where cname like 'anuj';
SQL output:
6 To update a record:
SQL code:
update CAR set color ='white' where color like 'yellow';
select *from CAR ;
SQL output:
SQL code:
select max(average) from CAR;
SQL output:
SQL code:
alter table customer add (to_check varchar(3));
SQL output: