Documente Academic
Documente Profesional
Documente Cultură
SIGNATURE
S.NO DATE PROGRAM NAME OF THE
TEACHER
STUDENT RESULT PREPARATION SYSTEM USING
1 CLASS
MULTIPLE INHERITANCE
5
MULTILEVEL INHERITANCE
6
7 CONSTRUCTOR OVERLOADING
13 LINEAR SEARCH
14 BINARY SEARCH
15 MATRIX TRANSPOSE
18 BUBBLE SORT
class descriptions:
data members:
student rollno: integer
student name:character array
student marks:float array
student average:float
student grade: character
member functions:
public:
void read();
void display();
void calgrade();
Grade Formula
percentage of Grade
marks
80 to 100 A
60 to 80 B
45 to 60 C
less than 45 D
CODING:
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
//using namespace std;
class student
{
int rollno;
char name [20];
float marks[];
float average;
char grade;
public:
void read();
void display();
protected:
void calgrade();
}s[10];
int n;
void student::read()
{
cout<<”enter roll no:”;
cin >>rollno;
cout<<”enter name:”;
cin>>name;
cout<<”enter marks:”;
for(int i=0;i<n;i++)
cin>>marks[i];
calcgrade();
}
void student:: display()
{
cout<<”name:”<<name<<endl;
cout<<”rollno:”<<rollno<<endl;
cout<<”average:”<<(int)average<<endl;
cout<<”grade:”<<grade<<endl;
}
void student::calcgrade()
{
float total=0;
for(int i=0;i<n;i++)
total=total+marks[i];
average=total/n;
if(average<45)
grade=’d’;
else if(average<60)
grade=’c’;
else if(average<80)
grade=’b’;
else
grade=’a’;
}
void main()
{
int num;
cout<<”enter the no of students:”;
cin>>num;
cout<<”enter the no of subjects”;
cin>>n;
for(i=0;i<num;i++)
{
s[i].read();
s[i].calcgrade();
}
cout<<”student report\n”;
for(i=0;i<num;i++)
{
s[i].display();
}
getch();
}
INPUT AND OUTPUT
Result:
Thus the program has been written in C++ for generating student report using class in C++
Data members:
Name of the depositor :string
Account number :long
Type of account (saving or current) :character
Balance amount :decimal
Member function:
Initialize () : it reads the customer name, account number, account type, current balance
and initialize the object.
Deposit(): increases the balance amount
Withdraw() :checks for minimum balance in current account and decreases the balance
accordingly
Display() :display the customer details
Coding:
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<stdio.h>
//using namespace std;
class account
{
char cname[30];
long accno;
char acctype;
double balance;
public:
void initialize()
{
cout<<" enter name";
gets(cname);
cout<<"enter account number";
cin>>accno;
int done=1;
do
{
cout<<" enter account type current-c and saving-s";
cin>>acctype;
acctype=tolower(acctype);
if(acctype=='s')
balance=1000.0;
else if(acctype=='s')
balance=0.0;
else
{
cout<<"invalid account type";
done=0;
}
}while(done!=1);
}
void display()
{
cout<<"account holder name";
puts(cname);
cout<<"\naccount number"<<accno;
cout<<"\naccount type:"<<acctype<<"\t"<<"balance:"<<balance<<endl;
}
void deposit(double amt);
void withdraw(double amt);
};
void account::deposit(double amt)
{
balance=balance+amt;
cout<<"amount deposited"<<endl;
display();
}
void account::withdraw(double amt)
{
if(acctype=='c')
{
if(balance>=1000)
{
balance=balance-amt;
cout<<"amount widthdrawn";
display();
}
else
cout<<"min balance 1000 is needed for this account";
}
else
{
if(balance>=amt)
{
balance=balance-amt;
cout<<"amount width drawn";
display();
}
else
cout<<"amount exceed the balance";
}
}
void main()
{
account a[10];
int i=0,choice,cont;
char ch;
double d;
do
{
a[i].initialize();
do
{
cout<<"main menu 1-deposit 2 -withdraw 3-display\n";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter the amount to be deposited";
cin>>d;
a[i].deposit(d);
break;
case 2:
cout<<"enter the amount to be withdrawn";
cin>>d;
a[i].withdraw(d);
break;
case 3:
a[i].display();
break;
default:
cout<<"thank you";
}
cout<<"do you want to continue? enter 1";
cin>>cont;
}while (cont==1);
Result:
Thus the program has been written in C++ to simulate banking software which allows multiple
customers and give them options to deposit/withdraw money
Codings:
#include<iostream.h>
#include<conio.h>
using name space std;
float sum=0.0;
class stock
{
int icode;
char itemname[20];
float price;
int qty;
float discount;
private:
void calculatediscount()
{
if (qty<50)
discount=0;
else if(qty<100)
discount=10;
else
discount=20;
}
public:
void get()
{
cout<<”enter the item code”;
cin>>icode;
cout<<”enter item name”;
gets(itemname);
cout<<”enter price”;
cin>>price;
cout<<”enter quantity”;
cin>>qty;
calculatediscount();
}
void show()
{
float totprice=qty*price;
float final price=totprice-totprice*discount/100;
sum=sum+finalprice;
cout<<”itemcode:”<<icode<<endl;
cout<<”itemname:”<<itemname<<endl;
cout<<”qty:”<<qty<<endl;
cout<<”price:”<<price<<endl;
}
};
void main()
{
stock s[100];
int i=0;
char ch;
do
{
s[i].get();
s[i].show();
cout<<”are there any more items?”;
cin>>ch;
}while (ch==’y’);
cout<<”total bill amount=”<<sum;
getch();
}
Result: Thus we have written a program in C++ using classes for inventory simulation and compiled
and executed it successfully.
4. FUNCTION OVERLOADING
Aim: To write a program to find area of triangle, rectangle and circle to demonstrate Function
Overloading concept.
Coding:
#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(float l,float 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;
exit(1);
}
getch();
}
Result: thus we have written a program to find area of triangle, rectangle and circle to demonstrate
Function Overloading and it is compiled and executed successfully.
5. MULTIPLE INHERITANCE
Aim:To write a C++ program to demonstrate multiple inheritance. Consider 3 classes with the
following description.
Coding:
#include <iostream.h>
#include<conio.h>
class student
{
protected:
int rno,m1,m2;
public:
void get()
{
cout<<” enter the rollno:”;
cin>>rno;
cout<<”enter the two marks:”;
cin>>m1>>m2;
}
};
class sports
{
protected:
int msm;
public:
void getsm()
{
cout<<”\n enter the sports marks:”;
cin>>sm;
}
};
Result: Thus we have written a C++ program to demonstrate multiple inheritance and it is compiled
and executed successfully.
6. MULTILEVEL INHERITANCE
Aim: To write a program in C++ to demonstrate multilevel inheritance as per the given
constraints below:
In base class person:
read() : to get the name and age
display() : to display the name and age
In derived class student:public person
readstudent() : to get the rollno and average mark
disprollno() : to display the rollno and average mark
float getaverage(): to return average mark
In derived class gradstudent:public student
void readgrade() :call readstudent(),get subject and get employed or not
char workstatus() : return working status
void displaysubject() :print the subject
Coding:
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
using namespace std;
class person
{
char name[20];
int age;
public:
void read()
{
cout<<”enter name”;
gets(name);
cout<<”enter age”;
cin>>age;
}
void disp()
{
cout<<”name”<<name<<endl;
cout<<”age”<<age<<endl;
}
};
class student:public person
{
int rollno;
float average;
public:
void readstudent()
{
read();
cout<<”enter roll no”;
cin>>rollno;
cout<<”enter average marks”;
cin>>average;
}
void disprollno()
{
cout<<”roll no”:”<<rollno<<endl;
}
float getaverage()
{
return average;
}
};
class gradstudent:public student
{
char subject[5];
char working;
public:
void readgrade()
{
readstudent();
cout<<”enter subject”;
cin>>subject;
cout<<”working?y/n”;
cin>>working;
}
char workstatus()
{
return working;
}
void displaysubject()
{
cout<<”subject:”;
cout.write(subject,5);
}
};
void main()
{
int i;
const int size=2;
gradstudent g[size];
int year,total=0,n=0,w=0,pos;
float topscore=0,score;
cout<<”enter year:”;
cin>>year;
for(i=0;i<size;i++)
{
cout<<”enter the details of graduate””<<i+1<<endl;
g[i].readgrade();
total++;
if(g[i].workstatus()==’y’)
n++;
else
w++;
score=g[i].getaverage();
if(score>topscore)
topscore=score;
pos=i;
}
Formula:
Simple Interest=p*n*r/100;
Constructor signature:
si();
si(long p,int n,float r);
si(long p,int n);
si(long p,float r);
Coding:
#include<iostream.h>
#include<conio.h>
using namespace std;
class si
{
int p;
int years;
float rate;
float interest;
float amt;
public:
si();
si(int p,int n,float r);
si(int p,int n);
si(int p,float r);
void calculate();
void display();
};
si::si()
{
p=years=rate=0;
}
si:: si(int p,int n,float r)
{
cout<<” constructor with three arguments”<<endl;
p=p;
years=n;
rate=r;
}
si s2(2000,2.0,0.08f);
s2.calculate();
s2.display();
si s3(2000,0.10f);
s3.calculate();
s3.display();
getch();
}
Result: Thus we have written a program in c++ and it is complied and executed successfully.
8. WRITING AND READING A FILE CONTENT
Aim: To write a program in C++ for storing the country names and capital names in 2 text files and
printing both of them simultaneously
Coding:
#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
f1.close();
f2.close();
f1.open("country",ios::in);
f2.open("capital",ios::in);
char str[80];
cout<<" the content of the files are…\n";
cout<<"country\t\tcapital\n";
while(f1&&f2)
{
f1.getline(str,80);
cout<<str<<"\t\t";
f2.getline(str,80);
cout<<str<<"\n";
}
getch();
}
Result: Thus we have written a program in C++ based on above constraints and it is complied and
executed successfully.
9. COUNTING LINES IN A TEXT FILE
Aim: To write a file program to count number of lines in an already existing file.
Coding:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
//using namespace std;
void main()
{
ifstream fin;
clrscr();
fin.open("pro1.cpp");
if(!fin)
{
cout<<"error";
exit(0);
}
char str[80];
int count=0;
while(!fin.eof())
{
fin.getline(str,80);
count++;
}
cout<<"number of lines in file is"<<count;
fin.close();
getch();
}
OUTPUT:
number of lines in file is 75
Result: thus we have written a file program to count number of lines in an already existing file and it
is compiled and executed successfully.
10. BINARY FILE MANIPULATION(INSERT,SEARCH AND DISPLAY)
Aim: To write a program in C++ to insert,search and display the details of all students from a
binary file “student.dat”.assuming the record structure is:
struct student
{
int rollno;
char name[20];
char grade;
};
Coding:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
//using namespace std;
struct stu
{
int rollno;
char name[20];
char grade;
}s;
void display()
{
fstream f;
cout<<" the matched data is \n";
f.open("student.dat",ios::in);
cout<<s.rollno<<"\t"<<s.name<<"\t"<<s.grade<<endl;
f.close();
}
void main()
{
clrscr();
fstream fout("student.dat",ios::out);
ofstream ftemp;
char ch;
int n,i;
int flag=1,rno;
int choice;
cout<<"enter the number of students";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"enter rollno,name and grade of the students";
cin>>s.rollno>>s.name>>s.grade;
fout.write((char*)&s,sizeof(s));
}
fout.close();
flag=1;
fout.open("student.dat",ios::in);
cout<<"enter the roll to be searched";
cin>>rno;
while(fout.read((char*)&s,sizeof(s)))
{
if(s.rollno==rno)
{
display();
flag=0;
}
}
if (flag==1)
cout<<"roll number not found";
else
cout<<"roll number is found";
fout.close();
getch();
}
Result: Thus we have written a program in C++ to insert,search and display the file contents
as required and it is compiled and executed successfully.
11. BINARY FILE MANIPULATION ( DELETE AND DISPLAY)
Aim: To write a program in C++ to delete and display the details of all students from a binary
file “student.dat”, assuming the record structure is
struct student
{
int rollno;
char name[20];
char grade;
};
Coding:
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
//using namespace std;
struct student
{
int rollno;
char name[20];
char grade;
}s;
void display()
{
fstream f;
cout<<" the content of the student.dat are\n";
f.open("student.dat",ios::in);
f.clear();
f.seekg(0);
while(f.read((char*)&s,sizeof(s)))
{
cout<<s.rollno<<"\t"<<s.name<<"\t"<<s.grade<<endl;
}
f.close();
}
void main()
{
clrscr();
fstream fout("student.dat",ios::out);
ofstream ftemp("temp.dat",ios::out);
char ch;
int n,i;
int flag,rno;
int choice;
cout<<"enter the number of students";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"enter rollno,name and grade of the students";
cin>>s.rollno>>s.name>>s.grade;
fout.write((char*)&s,sizeof(s));
}
fout.close();
flag=1;
fout.open("student.dat",ios::in);
cout<<" enter the roll to be deleted";
cin>>rno;
fout.clear();
fout.seekg(0);
while(fout.read((char*)&s,sizeof(s)))
{
if(s.rollno!=rno)
{
ftemp.write((char*)&s,sizeof(s));
}
else
{
flag=0;
}
}
ftemp.close();
fout.close();
if(remove("student.dat")!=0)
{
cout<<"error in deletion";
}
rename("temp.dat","student.dat");
cout<<"\nafter deletion..\n";
if(flag==0)
{
cout<<"item found and it is deleted";
display();
}
else
{
cout<<"item is not found";
display();
}
getch();
}
Result: Thus we have written a program in C++ to delete and display the contents of the file
and it is complied and executed successfully.
12. BINARY FILE MANIPULATION(UPDATE AND DISPLAY)
Aim: To write a program in C++ to update and display the details of all students from a
binary file “student.dat”, assuming the record structure is
struct student
{
int rollno;
char name[20];
char grade;
};
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
//using namespace std;
struct student
{
int rollno;
char name[20];
char grade;
}s;
void display()
{
fstream f;
cout<<"the content of the student.dat are\n";
f.open("student.dat",ios::in);
while(f.read((char*)&s,sizeof(s)))
{
cout<<s.rollno<<"\t"<<s.name<<"\t"<<s.grade<<endl;
}
f.close();
}
void main()
{
clrscr();
fstream fout("student.dat",ios::out);
ofstream ftemp("temp.dat",ios::out);
char ch;
int i,n;
int flag=1,rno;
int choice;
cout<<"enter the number of students\n";
cin>>n;
for(i=1;i<=n;i++)
{
cout<<"enter rollno,name and grade of the students";
cin>>s.rollno>>s.name>>s.grade;
fout.write((char*)&s,sizeof(s));
}
fout.close();
flag=1;
fout.open("student.dat",ios::in);
cout<<"enter the roll to be updated";
cin>>rno;
while(fout.read((char*)&s,sizeof(s)))
{
if(s.rollno!=rno)
ftemp.write((char*)&s,sizeof(s));
else
{
flag=0;
cout<<"enter name and grade for updation\n";
gets(s.name);
cin>>s.grade;
ftemp.write((char *)&s,sizeof(s));
}
}
ftemp.close();
fout.close();
if(remove("student.dat")!=0)
{
cout<<"error in updation";
exit(1);
}
rename("temp.dat","student.dat");
if(flag==0)
{
cout<<"record found and updated";
display();
}
else
{
cout<<"record not found and not updated";
display();
}
getch();
}
Result: Thus we have written a program in C++ to update and display the contents of the file and it is
complied and executed successfully.
13. LINEAR SEARCH
Aim: To write a C++ program to search a item in an array using linear search Method
Method:
1.Get the data from the user in an array.
2.Ask the user to enter an element to search in the array.
3.Compare the given key element to each and every element in array
4.If element is present in the given array, then display the position of the element.
Coding:
#include<iostream.h>
#include<conio.h>
class lsearch
{
public:
int data[10],n,key;
void getdata();
void display();
};
Result: Thus we have written program in C++ to search a item in an array using linear search
method. it is compiled and executed successfully.
Coding:
#include<iostream.h>
#include<conio.h>
class bsearch
{
public:
int data[10],n,key,first,last,middle;
void getdata();
void display();
};
void bsearch :: getdata()
{
cout<<"\nEnter the length of the array:";
cin>>n;
cout<<"\n enter the "<<n<<" elements ...\n";
for(int i=0;i<n;i++)
{
cin>>data[i];
}
cout<<"\nEnter the key to find the element in the array:";
cin>>key;
}
Result: Thus we have written program in C++ to search a item in an array using binary search
method. it is compiled and executed successfully.
15. MATRIX TRANSPOSE
void transpose::input()
{
cout<<"Enter order of the matrix: ";
cin>>m>>n;
cout<<"Enter "<<m*n<<"elements in the matrix:\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
}
void transpose::output()
{
cout<<"Before transpose the matrix is: \n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"After transpose the given matrix is:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<a[j][i]<<" ";
}
cout<<endl;
}
}
void main()
{
transpose t1;
clrscr();
t1.input();
t1.output();
getch();
}
Result: Thus we have written program in C++ to find the transpose of a given matrix and it is
compiled and executed successfully.
Coding:
#include<iostream.h>
#include<conio.h>
#include<process.h>
int sum1(int a[50][50],int r)
{
int s=0;
for(int i=0;i<r;i++)
{
s=s+a[i][i];
}
return(s);
}
for(int i=0;i<r;i++)
{
s=0;
for(int j=0;j<r;j++)
{
s=s+a[i][j];
}
void main()
{
clrscr();
int i,s,j,r,c,ch,a[50][50];
x:
cout<<"Entr Array Limit--(Enter only Row as R=C)"<<endl;
cin>>r;
cout<<"Enter Array"<<endl;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
cin>>a[i][j];
}
}
y:
cout<<endl<<endl<<" Enter Choice :"<<endl;
cout<<"Sum of---- 1:main 2:Secondary 3.Rows 4.Columns 5.Re-enter 6.Exit "<<endl;
cin>>ch;
switch(ch)
{
case 1:
s=sum1(a,r);
cout<<"Sum = "<<s<<endl;
goto y;
case 2 :
s=sum2(a,r);
cout<<"Sum = "<<s<<endl;
goto y;
case 3:
row(a,r);
goto y;
case 4:
col(a,r);
goto y;
case 5:
goto x;
case 6:
exit(0);
default :
cout<<"Wrong Choice"<<endl;
break;
}
getch();
}
Result:Thus we have written a program in C++ to determine the row sum, column sum and diagonal
sums of a given square Matrix and it is compiled and executed successfully.
17. INSERTION SORT
Aim: to write a C++ program to sort the given array of numbers using Insertion sort technique as
per the given constraints:
Write a menu driven C++ program with following option
a. Accept elements of an array
b. Display elements of an array
c. Sort the array using insertion sort method
Write C++ functions for all options. The functions should have two parameters name of the
array and number of elements in the array.
Coding:
#include<iostream.h>
#include<conio.h>
#include<process.h>
void accept(int Arr[], int s);
void display(int Arr[], int s);
void isort(int Arr[], int s);
void main()
{
int Arr[100],n,choice;
int ch='y';
cout<<"Enter Size of Array ";
cin>>n;
do
{
cout<<"\nMENU";
cout<<"\n1. Accept elements of array";
cout<<"\n2. Sort the array using insertion sort method";
cout<<"\n3. Display elements of array";
cout<<"\n4. Exit";
cout<<"\n\nEnter your choice 1-4 :";
cin>>choice;
switch(choice)
{
case 1: accept(Arr,n);
break;
case 2: isort(Arr,n);
break;
case 3: display(Arr,n);
break;
case 4: exit(0);
break;
default:
cout<<"\nInvalid choice";
}
cout<<"do you want to continue?";
cin>>ch;
}while(ch=='y'|| ch=='Y');
getch();
}
void accept(int Arr[], int s)
{
for(int I=0;I<s;I++)
{
cout<<"Enter element "<<I+1<<":";
cin>>Arr[I];
}
}
Aim: to write a C++ program to sort the given array of numbers using Insertion sort technique as
per the given constraints:
Write a menu driven C++ program with following option
a. Accept elements of an array
b. Display elements of an array
c. Sort the array using bubble sort method
Write C++ functions for all options. The functions should have two parameters name of the
array and number of elements in the array.
Coding:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
void accept(int Arr[], int s);
void display(int Arr[], int s);
void bsort(int Arr[],int s);
int main()
{
int Arr[100],n,choice;
clrscr();
cout<<"Enter Size of Array ";
cin>>n;
do
{
cout<<"\nMENU";
cout<<"\n1. Accept elements of array";
cout<<"\n2. Display elements of array";
cout<<"\n3. Sort the array using bubble sort method";
cout<<"\n4. Exit";
cout<<"\n\nEnter your choice 1-4 :";
cin>>choice;
switch(choice)
{
case 1: accept(Arr,n);
break;
case 2: display(Arr,n);
break;
case 3: bsort(Arr,n);
break;
case 4: cout<<"\nthank you....\n";
getch();
exit(0);
default:
cout<<"\nInvalid choice";
break;
}
} while(1);
}
void accept(int Arr[], int s)
{
for(int I=0;I<s;I++)
{
cout<<"Enter element "<<I+1<<":";
cin>>Arr[I];
}
}
void display(int Arr[], int s)
{
cout<<"The elements of the array are:\n";
for(int I=0;I<s;I++)
cout<<Arr[I]<<" ";
}
class node
{
public:
int data;
node* next;
};
Coding:
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
//using namespace std;
class node
{
public:
int data;
node* next;
};
class StackList
{
private:
node *top;
int count; //head
int maxnum;
int stackData;
public:
StackList(int max)
{
top = NULL;
maxnum = max;
count=0;
}
void pop()
{
if(top == NULL)
cout<< "nothing to pop";
else
{
node *old = top;
top = top->next;
count--;
delete(old);
}
}
void print()
{
node *temp;
temp = top;
while(temp!=NULL)
{
cout<<temp->data<<",";
temp=temp->next;
}
}
};
void main()
{
//StackList *sl = new StackList(5);
StackList s1(5);
clrscr();
int d;
int ch;
do
{
switch(ch)
{
case 1:
cout<<"\nenter element to push\n";
cin>>d;
s1.push(d);
break;
case 2:
s1.pop();
break;
case 3:
s1.print();
break;
case 4:
exit(1);
default:
cout<<"enter the correct choice?";
}
}while(1);
}
Result: Thus we have written a program in C++ to implement the stack using linked list and it is
compiled and executed successfully.
20. A PROGRAM TO IMPLEMENT QUEUE USING LINKED LIST.
Coding:
#include<iostream.h>
#include<stdlib.h>
//using namespace std;
struct node
{
int info;
struct node *next;
};
class Queue
{
private:
node *rear; node *front;
public:
Queue();
void enqueue();
void dequeue();
void display();
};
Queue::Queue()
{
rear = NULL; front = NULL;
}
void Queue::enqueue()
{
int data;
node *temp = new node;
cout<<"Enter the data to enqueue: ";
cin>>data;
temp->info = data;
temp->next = NULL;
if(front == NULL)
{
front = temp;
}
else
{
rear->next = temp;
}
rear = temp;
}
void Queue::dequeue()
{
node *temp = new node;
if(front == NULL)
{
cout<<"\nQueue is Emtpty\n";
}
else
{
temp = front;
front = front->next;
cout<<"The data Dequeued is "<<temp->info;
delete temp;
}
}
void Queue::display()
{
node *p = new node;
p = front;
if(front == NULL)
{
cout<<"\nNothing to Display\n";
}
else
{
while(p!=NULL)
{
cout<<endl<<p->info;
p = p->next;
}
}
}
void main()
{
Queue queue;
int choice;
while(1)
{
cout<<"\n1.Enqueue\n2. Dequeue\n3. Display\n 4.Quit";
cout<<"\nEnter your choice: ";
cin>>choice;
switch(choice)
{
case 1:
queue.enqueue();
break;
case 2:
queue.dequeue();
break;
case 3:
queue.display();
break;
case 4:
exit(0);
default:
cout<<"\nInvalid Input. Try again! \n";
break;
}
}
}
Result: Thus we have written a program in C++ to implement the stack using linked list and it is
compiled and executed successfully.
SQL- Structured Query Language
1. Data control language (DCL) - used to control user access (e.g., GRANT, REVOKE)
2. Transactional language - used to control logical units of work (e.g., COMMIT)
EXPERIMENT -1 (DDL COMMANDS)
Aim: To understand and perform the DDL commands
Data definition language (DDL) - used to define or change database structure(s) (e.g., CREATE,
ALTER, DROP,etc)
Creating a Database:
Syntax: create database databasename;
eg: create database vbc;
Example :
CREATE TABLE student
(
rno int,
name char(25),
fees int,
dob date,
class char(3)
);
Result: Thus we have learnt various DDL commands and executed successfully
EXPERIMENT -2 (DML COMMANDS)
Data manipulation language (DML) - used to select or change data (e.g., INSERT, UPDATE,
DELETE, SELECT)
SELECT * FROM student WHERE fess > 7000 AND fees < 8000;
rno name fees Dob Class
10 Alex 7800 1998-10-03 K12
12 Alisha 7800 1999-07-03 K11
Syntax:
SELECT column_name,column_name FROM table_name
ORDER BY column_name,column_name ASC|DESC;
Example
SELECT * FROM student ORDER BY name;
COUNT(*)
4
COUNT(rno)
4
SUM(fees)
29300 SELECT SUM(fees) FROM student;
Table - order_items
order_id product_id total_units customer
5100 104 30 Infosys
5101 102 5 Satyam
5102 103 25 Wipro
5103 101 10 TCS
Result: Thus we have learnt various DML commands and executed successfully
EXPERIMENT-3
Aim: To consider the following tables EMPLOYEES and EMPSALARY. Write SQL commands for
the statements(i) to (vi) and give outputs for SQL queries (vii) to (x)
Books:
Bookid BookName AuthorName Publisher Price Type Qty
C0001 Fast Cook Lata Kapoor EPB 355 Cookery 5
F0001 The Tears William First Publ 650 Fiction 20
Hopkins
T0001 My First Brain & EPB 350 Text 10
C++ Brooke
T0002 C++ A.W. TDH 350 Text 15
Brainworks Rossaine
F0002 Thunderbolts Anna First publ. 750 Fiction 50
Roberts
Issued
Bookid QtyIssued
T0001 4
C0001 5
F0001 2
(i) To display Book name, author name and price of First publishers books.
ANS: SELECT BookNmae, AuthorName,Price from Books where Publisher="First Publ";
(ii) To display the names and price of books in ascending order of their price.
ANS:SELECT BookName, Price FROM Books ORDER BY Price;
(v) To select the books whose quantities are more than or equal to the average quantity.
SELECT BookName from Books where qty>=(select average(qty) from Books);
(vi) To display the BookName and quantity issued for the Bookid that have issued
ANS: Select BookName, QtyIssued from Issued I,Books B where I.Bookid=B.Bookid;
Result: Thus the above queries are executed and their ouput is traced successfully.
EXPERIMENT -4
Aim: To consider the following tables Client and Bill. Write the SQL commands for the statements
and Write SQL commands for the statements(i) to (iv) and give outputs for SQL queries (v) to (viii)
Client:
Cust_id Cust_name Address Phone_no City
C007 MANI VILLAPURAM 7343234523 MADURAI
C008 KANI NARI MEDU 8343234523 CHENNAI
C010 VANI NILAIYOOR 9343234523 KOLKATTA
C012 SENTHIL AATHUR 6343234523 DELHI
C013 BANUMATHI CHINNALAPATTI 6643234523 DINDUGUL
Bill:
Ord_id Cust_id Item Ord_date Qty Price
7002 C007 Pizza 20-11-07 1 250
7003 C013 Garlic Bread 24-10-05 3 75.75
7004 C012 Pasta 03-03-07 4 173
7005 C010 Ice Cream 01-01-08 30 195.75
7006 C035 Pizza 02-03-06 4 250
7009 C035 Garlic Bread 02-03-08 2 75.75
i) To Display a report containing Cust_id, Cust_name, Item, Qty, Price and BillAmount.
bill amount is calculated using qty*price;
ii) display how many customers have ordered pizza and ord_date in the month March.
Ans: SELECT count(*) from bill where item=’Pizza’ and order_date like ‘ %03%’
iii) Count the number of customers who have order items worth than 1700;
total amt=sum of qty* price;
Ans: SELECT count(*),cust_id, sum(qty*price) as total_amt from bill group by cust_id
having sum(qty,price)>300;
iv) Display the names of customers along with their city in alphabetical order of city
Ans: SELECT cust_name,city from client order by city
Ans:
Cust_name Phone_no
MANI 9999993335
KANI 8343234523
VANI 9343234523
SENTHIL 6343234523
BANUMATHI 6643234523