cms practical_075336
cms practical_075336
Q1. WAP to find addition, subtraction, multiplication and division of two numbers given
by user using Switch - case.
#include <iostream>
#include <conio.h>
#include<math.h>
using namespace std;
main()
{
int n ;
cout<<"\n 1. Addition.\t 2. Subtraction. \t 3. Multiplication. \t 4. Division. ";
cout<<"\n Enter your choice.";
cin>>n;
switch(n)
{
case 1:
int a,b,c;
cout<<"\n Enter two numbers . ";
cin>>a>>b;
c = a + b;
cout << "Sum of two numbers is :" << c << endl ;
break;
case 2:
int x,y,sub;
cout<<"\n Enter two numbers . ";
cin>>x>>y;
sub = x - y;
cout << "Subtraction of two numbers is :" << sub << endl ;
break;
case 3:
int p,q,m;
cout<<"\n Enter two numbers . ";
cin>>p>>q;
m = p * q;
cout << " Multiplication of two numbers is :" << m << endl ;
break;
case 4:
double d,e,div;
cout<<"\n Enter two numbers . ";
cin>>d>>e;
div = d / e;
cout << "Division of two numbers is :" << div << endl ;
break;
default:
cout<<"Wrong Choice.";
break;
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],c[3][3],i,j;
cout<<"\n Enter first matrix :";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>a[i][j];
}}
cout<<"\n Enter second matrix :";
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cin>>b[i][j];
}}
cout<<"\n First matrix is :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<a[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n Second matrix is :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<b[i][j]<<" ";
}
cout<<"\n";
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}
cout<<"\n Sum of two matrix is :"<<endl;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<" ";
}
cout<<"\n";
}
getch();
}
Q3. WAP for Selection sort.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ar[20],i,j,size,temp,loc,min;
cout<<"Enter array size : " ;
cin>>size;
cout<<" Enter array elements :";
for(i=0;i<size;i++)
{
cin>>ar[i];
}
for(i=0;i<size-1;i++)
{
min=ar[i]; //element
loc=i; //loc=0 index number
for(j=i+1;j<size;j++)
{
if(ar[j]<min)
{
min=ar[j];
loc=j;
}}
temp=ar[i];
ar[i]=ar[loc];
ar[loc]=temp;
}
cout<<" \n Array after selection sort : ";
for(i=0;i<size;i++)
{
cout<<ar[i]<<" ";
}
getch();
}
do
{
cout<<"\n Enter your choice : ";
cout<<"\n 1. PUSH ";
cout<<"\n 2. POP ";
cout<<"\n 3. Display ";
cout<<"\n 4. Exit "<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"\n Enter element to add in the stack : ";
cin>>num;
push(num); //function push is calling.
break;
case 2:
pop(); //function pop is calling.
break;
case 3:
display(); //display function is calling.
break;
}}
while(choice!=4);
getch();
}
void display()
{
if(top==-1)
{
cout<<"\n Stack is Empty. ";
return ;
}
else
{
cout<<"\n Stack elements are : "<<endl;
int i;
for (i=top;i>=0;i--)
{
cout<<endl;
cout<<stack[i];
} }}
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
int i,j,n,f;
cout<<" Enter your range :-";
cin>>n;
cout<<" Prime Numbers between 1 to "<<n<<endl;
for( i=2;i<=n;i++)
{
f=1;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{
f=0;
break;
}
}
if(f==1)
cout<<i<<", ";
getch();
}
Q8. A program that stores and displays information using structure.
#include <iostream>
#include <conio.h>
struct employee
{
int empID;
char name[50];
int salary;
char department[50];
};
void main()
{
employee emp[3] = { { 1 , "Harry" , 20000 , "Finance" } , { 2 , "Sally" , 50000 , "HR" } , { 3 ,
"John" , 15000 , "Technical" } };
cout<<"The employee information is given as follows:"<<endl;
cout<<endl;
for(int i=0; i<3;i++)
{
cout<<"Employee ID: "<<emp[i].empID<<endl;
cout<<"Name: "<<emp[i].name<<endl;
cout<<"Salary: "<<emp[i].salary<<endl;
cout<<"Department: "<<emp[i].department<<endl;
cout<<endl;
}
getch();
}
Output
The employee information is given as follows:
Employee ID: 1
Name: Harry
Salary: 20000
Department: Finance
Employee ID: 2
Name: Sally
Salary: 50000
Department: HR
Employee ID: 3
Name: John
Salary: 15000
Department: Technical
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
int n, sum=0, i=1;
cout<<"Enter your number ";
cin>>n;
#include <iostream.h>
#include<conio.h>
class box
{
public:
double length;
double breadth;
double height;
};
void main()
{
clrscr();
box b1;
box b2;
double SA ;
cout<<" Enter height of b1 : ";
cin>>b1.height;
cout<<" Enter length of b1 : ";
cin>>b1.length;
cout<<" Enter Breadth of b1 : ";
cin>>b1.breadth;
getch();
}
Q11. WAP using hierarchical inheritance find product and sum of any number.
#include <iostream>
#include<conio.h>
Output
#include<iostream>
#include<conio.h>
class ABC
{
private:
int l,w,x;
public:
ABC (int a,int b) //parameterized constructor to initialize l and w
{
l = a;
w = b;
}
int area( ) //function to find area
{
x = l * w;
return x;
}
void display( ) //function to display the area
{
cout << "Area = " << x << endl;
}
};
int main()
{
ABC c(2,4); //initializing the data members of object 'c' implicitly
c.area();
c.display();
Output
Area = 8
Area = 16
#include<iostream>
#include<conio.h>
class example
{
private:
int x;
public:
example (int a) //parameterized constructor to initialize l and b
{
x = a;
}
example( example &b) //copy constructor with reference object argument
{
x = b.bx;
}
int display( ) //function to display
{
return x;
}
};
int main()
{
example c1(2); //initializing the data members of object 'c' implicitly
example c2(c1); //copy constructor called
example c3 = c1;
example c4 = c2;
cout << "example c1 = " << c1.display() << endl;
cout << "example c2 = " << c2.display() << endl;
cout << "example c3 = " << c3.display() << endl;
cout << "example c4 = " << c4.display() << endl;
return 0;
}
Output
example c1 = 2
example c2 = 2
example c3 = 2
example c4 = 2
#include <iostream>
#include<conio.h>
class ABC
{
public:
ABC () //constructor defined
{
cout << "Hey look I am in constructor" << endl;
}
~ABC() //destructor defined
{
cout << "Hey look I am in destructor" << endl;
}
};
int main()
{
ABC x; //constructor is called
cout << "function main is terminating...." << endl;
/*....object x goes out of scope ,now destructor is being called...*/
return 0;
}
Output
Hey look I am in constructor
function main is terminating....
Hey look I am in destructor
Characteristics Or Advantages
Traditionally, data was organized in file formats. DBMS was a new concept then, and all
the research was done to make it overcome the deficiencies in traditional style of data
management. A modern DBMS has the following characteristics −
1. Real-world entity − A modern DBMS is more realistic and uses real-world entities
to design its architecture. It uses the behavior and attributes too. For example, a
school database may use students as an entity and their age as an attribute.
2. Relation-based tables − DBMS allows entities and relations among them to form
tables. A user can understand the architecture of a database just by looking at the
table names.
3. Less redundancy − DBMS follows the rules of normalization, which splits a relation
when any of its attributes is having redundancy in values. Normalization is a
mathematically rich and scientific process that reduces data redundancy.
If a database design is not perfect, it may contain anomalies (Error), which are
like a bad dream for any database administrator. Managing a database
with anomalies is next to impossible.
Update anomalies − If data items are scattered and are not linked to each other properly,
then it could lead to strange situations. For example, when we try to update one data
item having its copies scattered over several places, a few instances get updated properly
while a few others are left with old values. Such instances leave the database in an
inconsistent state.
Deletion anomalies − We tried to delete a record, but parts of it was left undeleted
because of unawareness, the data is also saved somewhere else.
Insert anomalies − We tried to insert data in a record that does not exist at all.
4. Query Language − DBMS is equipped with query language, which makes it more
efficient to retrieve and manipulate data. A user can apply as many and as different
filtering options as required to retrieve a set of data. Traditionally it was not possible
where file-processing system was used.
6. Multiple views − DBMS offers multiple views for different users. A user who is in
the Sales department will have a different view of database than a person working in
the Production department. This feature enables the users to have a concentrate view
of the database according to their requirements.
7. Security − Features like multiple views offer security to some extent where users are
unable to access data of other users and departments. DBMS offers methods to
impose constraints while entering data into the database and retrieving the same at a
later stage. DBMS offers many different levels of security features, which enables
multiple users to have different views with different features. For example, a user in
the Sales department cannot see the data that belongs to the Purchase department.
Additionally, it can also be managed how much data of the Sales department should
be displayed to the user. Since a DBMS is not saved on the disk as traditional file
systems, it is very hard for miscreants to break the code.
Types of DML
i. Procedural DML – These require a user to specify what data is needed and how
to get it.
ii. Non-procedural DML – These require a user to specify what data is needed
without specifying how to get it.