II Puc Practical Final

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

II PUC PRACTICALS

C++ PROGRAMS:
1.WAP to find the frequency of presence of an element in an array.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[20], n, i, f=0, s;
cout<<"Enter the number of elements";
cin>>n;
cout<<"Enter the elements";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to find the frequency";
cin>>s;
for(i=0; i<n; i++)
if(s==a[i])
f++;
cout<<"Frequency="<<f;
}

2.WAP to insert an element into an array at a given position.


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[20], n, i, e, p;
cout<<"Enter the number of elements";
cin>>n;
cout<<"Enter the elements";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element to insert";
cin>>e;
cout<<"Enter the element position";
cin>>p;
if(p>n-1)
cout<<"Insertion not possible";
else
{
for(i=n-1; i>=p; i--)
a[i+1]=a[i];
a[p]=e;
n=n+1;
cout<<"Array after insertion \n";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
}
3.WAP to delete an element from an array from a given position.
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int a[20], n, i, e, p;
cout<<"Enter the number of elements";
cin>>n;
cout<<"Enter the elements";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the element position to delete";
cin>>p;
if(p>n-1)
cout<<"Deletion not possible";
else
{
e=a[p];
for(i=p; i<n-1; i++)
a[i]=a[i+1];
n=n-1;
cout<<"Array after deletion \n";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}
}

4.WAP to sort the elements in an ascending order using insertion sort.


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int n, a[100], i, j, temp;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements ";
for(i=0; i<n; i++)
cin>>a[i];
for(i=1; i<n; i++)
{
for( j=i; j>=1; j--)
{
if(a[ j ]<a[ j-1])
{
temp=a[ j ];
a[ j ]=a[ j-1 ];
a[ j-1 ]=temp;
}
}
}
cout<<"Array after sorting \n";
for(i=0; i<n; i++)
cout<<a[i]<<"\t";
}

5.WAP to search for an element using binary search.


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int n, a[100], i, beg, end, mid, s, loc=-1;
cout<<"Enter the number of elements";
cin>>n;
cout<<"Enter the elements";
for(i=0; i<n; i++)
cin>>a[i];
cout<<"Enter the search element";
cin>>s;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;
if(s==a[mid])
{
loc=mid;
break;
}
else
if(s<a[mid])
end=mid-1;
else
beg=mid+1;
}
if(loc>=0)
cout<<"Search element is found in location "<<loc;
else
cout<<"Search element is not found";
}

6.WAP to create a class with data members principle, time and rate of interest. Create
member functions to accept data values, to compute simple interest and display the
result.
#include<iostream.h>
#include<conio.h>
class simple
{
private: float p, t, r, si;
public:
void input()
{
cout<<"Enter the principal, time and rate of interest";
cin>>p>>t>>r;
}
void process()
{
si=(p*t*r)/100;
}
void output()
{
cout<<"Simple Interest="<<si;
}
};

main()
{
clrscr();
simple obj;
obj.input();
obj.process();
obj.output();
getch();
}

7.WAP to create a class with data members a,b,c and member functions to input data,
compute the discriminant based on following conditions and print roots.
i) If discriminant=0, print roots are equal and their roots value.
ii) If discriminant>0, print the real roots and their values.
iii) If discriminant<0, print the roots are imaginary and exit the program.
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
class quadratic
{
private: double a, b, c, d, r1, r2;
public: void input();
void process();
void output();
};

void quadratic :: input()


{
cout<<"Enter the co-efficients";
cin>>a>>b>>c;
}

void quadratic :: process()


{
d=b*b - 4*a*c;
if(d==0)
{
cout<<"Roots are equal \n";
r1=(-b-sqrt(d))/(2*a);
r2=r1;
}
else if(d>0)
{
cout<<"Roots are positive and different \n";
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
}
else
{
cout<<"Roots are imaginary";
exit(0);
}
}
void quadratic :: output()
{
cout<<"First root="<<r1;
cout<<"\n Second root="<<r2;
}
main()
{
clrscr();
quadratic obj;
obj.input();
obj.process();
obj.output();
}

8.WAP to find area of a square, rectangle and triangle using function overloading.
#include<iostream.h>
#include<conio.h>
#include<math.h>
class shape
{
public:
float area(float a)
{
return a*a;
}

float area(float a, float b)


{
return a*b;
}
float area(float a, float b, float c)
{
float s;
s=(a+b+c)/2;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
};
main()
{
clrscr();
shape s;
float a,b,c;
cout<<"Enter the side of a square";
cin>>a;
cout<<"Area of square="<<s.area(a);
cout<<"Enter two sides of a rectangle";
cin>>a>>b;
cout<<"\n Area of rectangle="<<s.area(a,b);
cout<<"Enter three sides of a triangle";
cin>>a>>b>>c;
cout<<"\n Area of triangle="<<s.area(a,b,c);
}

9. WAP to find cube of a number using inline function.


#include<iostream.h>
#include<conio.h>
class in
{
public: int cube(int );
};

inline int cube(int a)


{
return a*a*a;
}

main()
{
clrscr();
in i;
int a;
cout<<"Enter a number";
cin>>a;
cout<<"Cube of a number="<<i.cube(a);
}

10. WAP to find sum of series 1+x+x2+x3+….+xn using constructors.


#include<iostream.h>
#include<conio.h>
#include<math.h>
class series
{
private: int x, n, i, sum;
public: series()
{
sum=0;
}
void input();
void process();
void output();
};

void series :: input()


{
cout<<"Enter the value of x and n";
cin>>x>>n;
}
void series :: process()
{
for(i=0; i<=n; i++)
sum=sum+pow(x,i);
}
void series :: output()
{
cout<<"Sum of series="<<sum;
}
main()
{
series s;
s.input();
s.process();
s.output();
getch();
}

11. Create a base class containing data members rollno and name. Also create a member
unction to read and display the data using the concept of single level inheritance. Create a
derived class that contains marks of two subjects and total marks as data members.
#include<iostream.h>
#include<conio.h>
class student
{
private: int regno;
char name[30];
public: void input()
{
cout<<"Enter the register no";
cin>>regno;
cout<<"Enter the name";
cin>>name;
}
void output()
{
cout<<"Register Number="<<regno;
cout<<"\n Name="<<name;
}
};
class marks : public student
{
private: int m1,m2,total;
public:
void input1()
{
cout<<"Enter the marks in 2 subjects";
cin>>m1>>m2;
}
void process()
{
total=m1+m2;
}
void output1()
{
cout<<"\n Subject1 marks="<<m1;
cout<<"\n Subject2 marks="<<m2;
cout<<"\n Total="<<total;
}
};
main()
{
marks m;
m.input();
m.input1();
m.process();
m.output();
m.output1();
getch();
}

12.Create a class containing following data members Register no, name and fees. Also
create a member functions to read and display the data using concepts of pointer to
objects.
#include<iostream.h>
#include<conio.h>
class student
{
private: int regno,fees;
char name[30];
public: void input()
{
cout<<"Enter the register no";
cin>>regno;
cout<<"Enter the name";
cin>>name;
cout<<"Enter the fees";
cin>>fees;
}
void output()
{
cout<<"Register Number="<<regno;
cout<<"\n Name="<<name;
cout<<"\n Fees="<<fees;
}
};
main()
{
student obj,*pobj;
pobj=&obj;
pobj->input();
pobj->output();
getch();
}

SQL QUERIES:
1. Create a table for house hold Electricity bill with the following fields.
Fieldname Type
RR_number varchar2(10)
Consumer_name varchar2(25)
Date_billing date
Units number (4)

Ans: create table ebill26


(
rr_number varchar2(10),
consumer_name varchar2(25),
date_billing date,
units number(4)
);

a) Insert 4 records into the table.


Ans: insert into ebill26 values ('a101', 'kumar', '02-mar-18', 98);
insert into ebill26 values ('a102', 'naveen', '02-feb-18', 88);
insert into ebill26 values ('a103', 'suma', '20-sep-20', 108);
insert into ebill26 values ('a104', 'sheetal', '15-aug-21', 158);

b) Check the structure of table and note your observation.


Ans: desc ebill26;

c) Add 2 new fields to the table. bill_amt number (6, 2)


duedate date
Ans: alter table ebill26 add(bill_amt number(6, 2), duedate date );

d) Compute the bill amount for each customer as per the following rules.
Minimum amount Rs.50
First 100 units Rs.4.50/unit
>100 units Rs.5.50/unit

Ans: update ebill26 set bill_amt = 50;

update ebill26 set bill_amt = bill_amt + units*4.50 where units<=100;

update ebill26 set bill_amt = bill_amt +100*4.50+(units-100)*5.50 where units>100;

e) Compute due date as billing date +15days.


Ans: update ebill26 set duedate = date_billing+15;

f) List all the bills generated.


Ans: select *from ebill26;

2. Create a student database with the following fields:


FieldName Type
Stud_id number(4)
Stud_name varchar2(25)
Sub1 number(2)
Sub2 number(2)
Sub3 number(2)

Ans: create table student26


(
sid number(4),
sname varchar2(25),
sub1 number(2),
sub2 number(2),
sub3 number(2)
);

a) Add 3 records into the table


Ans: insert into student26 values (1001, 'anuthara', 67, 82, 86);
insert into student26 values (1002, 'arjun', 32, 66, 78);
insert into student26 values (1003, 'karthik', 37, 65, 68);

b) Display the description of the fields in the table.


Ans: desc student26;
c) Alter the table to add total number(3) and per number(3).
Ans: alter table student26 add(total number(3), per number(3));

d) Calculate the total marks & percentage for each student.


Ans: update student26 set total= sub1 + sub2 +sub3;
update student26 set per= total/3;

e) Compute the result as “pass” or fail by checking if the student has scored more than 35
marks in each subject.
Ans: alter table student26 add(result varchar2(10));

update student26 set result=’pass’ where sub1>=35 and sub2>=35 and sub3>=35;

update student26 set result=’fail’ where sub1<35 or sub2<35 or sub3<35;

f) List the content of the table


Ans: select *from student26;

g) Retrieve only student id and student name of all the students


Ans: select sid, sname from student26;
h) List the students who have result as “pass”
Ans: select *from student26 where result=’pass’;

i) List the students who have result as “fail”


Ans: select *from student26 where result=’fail’;

j) Count the number of students who have passed


Ans: select count(*) from student26 where result=’pass’;

k) Count the number of students who have failed


Ans: select count(*) from student26 where result=’fail’;

l) Count the number of students who have percentage more than 60.
Ans: select count(*) from student26 where per>=60;

m) Sort the table according to the order of stud_id.


Ans: select *from student26 order by sid;

HTML:
1. Write an HTML program to prepare a study timetable.
<HTML>
<HEAD>
<TITLE>TIME TABLE</TITLE>
</HEAD>
<BODY TEXT="RED" BGCOLOR="WHITE">
<H1><CENTER>MY STUDY TIME TABLE FOR THE WEEK</CENTER></H1>
<CENTER>
<TABLE BORDER="12" BORDERCOLOR="RED" CELLSPACING="10" CELLPADDING="12">
<TR>
<TH>DAYS</TH>
<TH>SUBJECTS</TH>
<TH>MORNING STUDY TIME</TH>
<TH>EVENING STUDY TIME</TH>
</TR>
<TR>
<TH>MONDAY/TUESDAY</TH>
<TD>ENGLISH/COMP.SCIENCE</TD>
<TD>5:30-6:30AM</TD>
<TD>7:00-8:30PM</TD>
</TR>
<TR>
<TH>WEDNESDAY/THURSDAY</TH>
<TD>KANNADA/PHYSICS</TD>
<TD>5:30-6:30AM</TD>
<TD>7:00-8:30PM</TD>
</TR>
<TR>
<TH>FRIDAY/SATURDAY</TH>
<TD>CHEMISTRY/MATHS</TD>
<TD>5:30-6:30AM</TD>
<TD>7:00-8:30PM</TD>
</TR>
</TABLE>
</CENTER>
</BODY>
</HTML>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy