0% found this document useful (0 votes)
9 views31 pages

Final II Pu - Cs Lab Manual

The document is a lab manual for II PUC containing various programming exercises in C++. It includes programs for finding frequency in an array, inserting and deleting elements, sorting, searching using binary search, calculating simple interest, solving quadratic equations, function overloading for area calculations, and using inheritance for student details. Additionally, it covers SQL commands for creating a database and managing a table for electricity billing.

Uploaded by

aditya guha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views31 pages

Final II Pu - Cs Lab Manual

The document is a lab manual for II PUC containing various programming exercises in C++. It includes programs for finding frequency in an array, inserting and deleting elements, sorting, searching using binary search, calculating simple interest, solving quadratic equations, function overloading for area calculations, and using inheritance for student details. Additionally, it covers SQL commands for creating a database and managing a table for electricity billing.

Uploaded by

aditya guha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

CS LAB MANUAL II PUC

/* 1. Write a program to find the frequency of presence an element in an


array */

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class frequency
{
private:
int n,m[100],ele,freq;
public:
void getdata();
void findfreq();
void display();
};

void frequency :: getdata()


{
cout<<"Enter the size of the array "<<endl;
cin>>n;
cout<<"Enter "<<n<<"elements into the array"<<endl;
for(int i=0;i<n;i++)
cin>>m[i];
cout<<"Enter the search element "<<endl;
cin>>ele;
}

void frequency :: findfreq()


{
freq=0;
for(int i=0;i<n;i++)
if(ele==m[i])
freq++;
}

void frequency :: display()


{
if(freq>0)
cout<<"Frequency of "<<ele<<" is "<<freq;
else
cout<<ele<<" Does not exist"<<endl;
}

1
CS LAB MANUAL II PUC

void main()
{
frequency f;
clrscr();
f.getdata();
f.findfreq();
f.display();
getch();
}

OUTPUT

2
CS LAB MANUAL II PUC

/* 2. Write a program to insert an element into an array at a given


position */

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<process.h>

class insertion
{
private:
int n,m[100],ele,p;
public:
void getdata();
void insert();
void display();
};

void insertion :: getdata()


{
cout<<"How many elements "<<endl;
cin>>n;
cout<<"Enter the elements "<<endl;
for(int i=0;i<n;i++)
cin>>m[i];
cout<<"Enter the element to be inserted "<<endl;
cin>>ele;
cout<<"Enter the position in between 0 to n-1 ";
cin>>p;
}

void insertion :: insert()


{
if(p>n)
{
cout<<p<<" is an invalid position ";
getch();
exit(0);
}

3
CS LAB MANUAL II PUC

for(int i=n-1;i>=p;i--)
m[i+1]=m[i];
m[p]=ele;
n++;
cout<<ele<<" is successfully inserted"<<endl;
}
void insertion :: display()
{
cout<<"The array after the insertion is ";
for(int i=0;i<n;i++)
cout<<setw(4)<<m[i];
}

void main()
{
clrscr();
insertion i;
i.getdata();
i.insert();
i.display();
getch();
}

OUTPUT

4
CS LAB MANUAL II PUC

// 3. Write a program to delete an element from an array from a given


position

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<process.h>

class deletion
{

private:
int m[100],n,ele,p;
public:
void getdata();
void remove();
void display();
};

void deletion :: getdata()


{
cout<<"How many elements ? "<<endl;
cin>>n;
cout<<"Enter the elements "<<endl;
for(int i=0; i<n; i++)
cin>>m[i];
cout<<"Enter the position o to n-1 "<<endl;
cin>>p;
}
void deletion :: remove()
{
if(p>n)
{
cout<<p<<" is an invalid position ";
getch();
exit(0);
}
ele=m[p];
for(int i=p+1;i<n;i++)
m[i-1]=m[i];
n--;
cout<<ele<<" is successfully removed "<<endl;
}

5
CS LAB MANUAL II PUC

void deletion :: display()


{
cout<<" The array after deletion is ";
for(int i=0; i<n; i++)
cout<<setw(4)<<m[i];
}

void main()
{
deletion d;
clrscr();
d.getdata();
d.remove();
d.display();
getch();
}

OUTPUT

6
CS LAB MANUAL II PUC

// 4. Write a program to sort the elements of an array in ascending order


using insertion sort

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class sorting
{
private:
int m[100],n;
public:
void getdata();
void sort();
void display();
};

void sorting :: getdata()


{
cout<<"How many elements ";
cin>>n;
cout<<"Enter the elements ";
for(int i=0; i<n; i++)
cin>>m[i];
}

void sorting :: display()


{
cout<<"The array after sorting is "<<endl;
for(int i=0; i<n; i++)
cout<<setw(4)<<m[i];
}

void sorting :: sort()


{
int temp,j;
for(int i=1;i<n;i++)
{
int j=i;
while(j>=1)
{
if(m[j]<m[j-1])
{
temp=m[j];

7
CS LAB MANUAL II PUC

m[j]=m[j-1];
m[j-1]=temp;
}
j--;
}
}
}
void main()
{
sorting s;
clrscr();
s.getdata();
s.sort();
s.display();
getch();
}

OUTPUT

8
CS LAB MANUAL II PUC

// 5. Write a program to search for a given element in an array using


binary search method

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class binarysearch
{
private:
int m[100],n,ele,pos,loc;
public:
void getdata();
void search();
void display();
};
void binarysearch :: getdata()
{
cout<<"How many elements";
cin>>n;
cout<<"Enter the elements ";
for(int i=0;i<n;i++)
cin>>m[i];
cout<<"Enter the search elements ";
cin>>ele;
}
void binarysearch :: display()
{
if(loc>=0)
cout<<"Position ="<<loc;
else
cout<<"Search is unsuccessfull ";
}
void binarysearch :: search()
{
int beg,end,mid;
loc=-1;
beg=0;
end=n-1;
while(beg<=end)
{
mid=(beg+end)/2;

9
CS LAB MANUAL II PUC

if(ele == m[mid])
{
loc=mid;
break;
}
else
if(ele < m[mid])
end=mid-1;
else
beg=mid+1;
}
}
void main()
{
binarysearch b;
clrscr();
b.getdata();
b.search();
b.display();
getch();
}

OUTPUT

10
CS LAB MANUAL II PUC

// 6. Write a program to calculate simple interest

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class interest
{
private:
double p,t,r,si;
public:
void getdata();
void compute();
void putdata();
};

void interest :: getdata()


{
cout<<"Enter principle amount, time and rate "<<endl;
cin>>p>>t>>r;
}

void interest :: compute()


{
si=(p*t*r)/100;
}

void interest :: putdata()


{
cout<<" Principle "<<p<<endl;
cout<<" Time "<<t<<endl;
cout<<"Rate "<<r<<endl;
cout<<" Simple interest "<<si<<endl;
}

void main()
{
interest i;
clrscr();
i.getdata();
i.compute();
i.putdata();
getch();
}

11
CS LAB MANUAL II PUC

OUTPUT

12
CS LAB MANUAL II PUC

/ * 7. Write a program to calculate real and imaginary parts of a quadratic


equation */

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<math.h>
#include<process.h>

class quadratic
{
private:
double a,b,c,r1,r2;

public:
void getdata();
void roots();
void putdata();
};
void quadratic :: getdata()
{
cout<<"Enter the co-efficients "<<endl;
cin>>a>>b>>c;

}
void quadratic :: roots()
{
double d=b*b-4*a*c;
if(d==0)
{
cout<<"Roots are equal "<<endl;
r1=-b/(2*a);
r2=r1;
}
else
{
if(d>0)
{
cout<<"Roots are positive and different ";
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
}

13
CS LAB MANUAL II PUC

else
{
cout<<"Roots are imaginary"<<endl;
}
}
}

void quadratic :: putdata()


{
cout<<"First root ="<<r1<<endl;
cout<<"Second root ="<<r2;
}

void main()
{
quadratic q;
clrscr();
q.getdata();
q.roots();
q.putdata();
getch();
}

OUTPUT

14
CS LAB MANUAL II PUC

/* 8.Write a program to find the area of a square/rectangle/triangle using


function overloading */

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<math.h>

class funoverload
{
private: float s;

public:

double area(double a)
{
return a*a;
}
double area(double l, double b)
{
return l*b;
}
double area(double a, double b, double c)
{
s=(a+b+c)/2;
return(sqrt(s*(s-a)*(s-b)*(s-c)));
}
};

void main()
{
clrscr();
double x,y,z;
int ans;
funoverload f1;
cout<<"Enter the choice "<<endl;
cin>>ans;
if(ans==1)
{
cout<<"Enter the sides ";
cin>>x;
cout<<"area of the square ="<<f1.area(x)<<endl;
}

15
CS LAB MANUAL II PUC

else
{
if(ans==2)
{
cout<<"Enter two sides "<<endl;
cin>>x>>y;
cout<<"Area of the rectangle ="<<f1.area(x,y)<<endl;
}
else
if(ans == 3)
{
cout<<"Enter three sides ";
cin>>x>>y>>z;
cout<<setprecision(8);
cout<<"Area of a triangle = "<<f1.area(x,y,z)<<endl;
}
else
cout<<"invalid input";
}
getch();
}

OUTPUT

16
CS LAB MANUAL II PUC

// 9. Write a program to find the cube of a number using inline functions

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class findcube
{
public:
inline int cube(int x)
{
return(x*x*x);
}
};

void main()
{
findcube f;
int n;
clrscr();
cout<<"Enter the number"<<endl;
cin>>n;
cout<<"CUBE of "<<n<<"="<<f.cube(n);
getch();
}

OUTPUT

17
CS LAB MANUAL II PUC

/* 10. Write a program to find the sum of the series 1+x+x2+...+xn using
constructors */

#include<iostream.h>
#include<conio.h>
#include<math.h>

class series
{
private:
int sum, x, n;

public:

series(int y, int m)
{
sum=1;
x=y;
n=m;
}

int sumseries();
};

int series::sumseries()
{
for(int i=1; i<=n;i++)
sum=sum+pow(x,i);

return sum;
}

void main()
{
int x, n;
clrscr();
cout<<”Enter the value for Base(X)=”<<endl;
cin>>x;
cout<<”Enter the value for Power(n)”<<endl;
cin>>n;
series s1(x,n);
series s2=s1;

18
CS LAB MANUAL II PUC

cout<”Sum of Series using Parameterized constructor:”;


cout<<s1.sumseries()<<endl;
cout<<”sum of series using copy constructor”;
cout<<s2.sumseries();
getch();
}

OUTPUT

19
CS LAB MANUAL II PUC

// 11. write a program to calculate the students percentage using


inheritance concept

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class student
{
private:
int rollno;
char name[20];

public:

void read()
{
cout<<"Enter the name ";
cin.getline(name,20);
cout<<"Enter The Roll No";
cin>>rollno;
}

void display()
{
cout<<"Roll no"<<rollno<<endl;
cout<<"Name "<<name<<endl;
}

};

class marks : public student


{
private:
int m1,m2, total;
public:
void read1()
{
cout<<"Enter two subject marks"<<endl;
cin>>m1>>m2;
total=m1+m2;
}

20
CS LAB MANUAL II PUC

void display1()
{
cout<<"Subject 1 ="<<m1<<endl;
cout<<"Subject 2 ="<<m2<<endl;
cout<<" Total marks ="<<total<<endl;
}
};

void main()
{
marks obj;
clrscr();
obj.read();
obj.read1();
obj.display();
obj.display1();
getch();
}

OUTPUT

21
CS LAB MANUAL II PUC

/* 12. write a program to accept student details and display it using


pointers */

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>

class student
{

private:
int regno;
char name[20];
float fees;

public:
void readdata();
void display();
};

void student :: readdata()


{
cout<<"Enter the Registr Number"<<endl;
cin>>regno;
cout<<"Enter the student name"<<endl;
cin>>name;
cout<<"Enter student fees"<<endl;
cin>>fees;
}

void student :: display()


{
cout<<”Register number :"<<regno<<endl;
cout<<"Student name :"<<name<<endl;
cout<<"Student fees : "<<fees;
}

22
CS LAB MANUAL II PUC

void main()
{
student *S;
clrscr();
S->readdata();
S->display();
getch();
}

OUTPUT

23
CS LAB MANUAL II PUC

SQL PROGRAM – 1
Q: create database and use it
Ans: create database electricity;
use electricity;

Q: Write a create table command for the below structure


Table Name: ebill
Field Name Type
rrno varchar(25)
cname varchar(25)
billdate date
units int(5)
Ans:
create table ebill(rrno varchar(25) primary key, cname varchar(25),
billdate date, units int(5));

Q: Insert 3 rows of information


Ans:
insert into ebill values(‘A101’,’Saradha’,’2019-12-15’,50);
insert into ebill values(‘A102’,’Fathima’,’2019-11-15’,58);
insert into ebill values(‘A103’,’manish’,’2019-10-15’,110);

Q: Check the structure of the table


Ans: desc ebill;

24
CS LAB MANUAL II PUC

Q: Add two more fields to the table


billamt int(6)
duedate date
Ans:
alter table ebill add(billamt int(6), duedate date);

Q: compute the bill amount for each consumer as per the following
rules:
1. min_amt Rs.50
2. first 100 units Rs.4.50 per unit
3. >100 units Rs. 5.50 per unit
Ans:
1. update ebill set billamt=50;
2. update ebill set billamt=billamt+units*4.50 where units<=100;
3. update ebill set billamt=billamt+100*4.50+(units-100)*5.50
where units>100;

Q: compute due date as billdate+15;


Ans: update ebill set duedate=billdate+15;

Q: List all the bills generated


Ans: select * from ebill;

25
CS LAB MANUAL II PUC

SQL PROGRAM – 2

Q: Create database and use it


Ans: create database student;
use student;
Q: Create a table for a class of students with the following details
FIELD NAME TYPE
sid int(5)
sname varchar(20)
sub1 int(4)
Sub2 int(4)
Sub3 int(4)
Sub4 int(4)
Sub5 int(4)
Sub6 int(4)

create table student(sid int(4), name varchar(15), sub1 int(4), sub2


int(4), sub3 int(4), sub4 int(4), sub5 int(5), sub6 int(4));

Q2: Add 2 records into table


Ans: insert into student values(101, ‘sharath’,55,56,78,45,76,89);
insert into student values(102, ‘manish’,64,48,34,45,88,41);

Q3: To view the structure of the table


Ans: desc student;

Q4: Add the columns : total, per, result


Ans: alter table student add(total int(4), per int(4), result varchar(5));

Q5: To calculate total and percentage


Ans: 1.update student set total=sub1+sub2+sub3+sub4+sub5+sub6;

26
CS LAB MANUAL II PUC

2. update student set per=total/6;

Q6: To compute result as “PASS” or “FAIL” by checking if the student has scored
more than 35 marks in each subject.
Ans:
update student set result=’pass’ where(sub1>=35 and sub2>=35 and
sub3>=35 and sub4>=35 and sub5>=35 and sub6>=35);

update student set result=’fail’ where(sub1<35 or sub2<35 or sub3<35 or


sub4<35 or sub5<35 or sub6<35);
Q7: List the contents of the table
Ans: select * from student;

Q8: Retrieve only student id and student name of all the students.
Ans. select sid, name from student;

Q9. List the students who have result as ‘pass’


Ans. select * from student where result=’pass’;

Q10. List the students who have result as ‘fail’


Ans. select * from student where result=’fail’;

Q11. Count the number of students who have passed


Ans. select count(*) from student where result=’pass’;
Q12. Count the number of students who have failed.
Ans. select count(*) from student where result=’fail’;

Q13. List the students who have percentage greater than 60


Ans. select * from student where per>=60;

Q14. Sort the table according to the order of student id.


Ans. select * from student order by sid;
27
CS LAB MANUAL II PUC

HTML 1: TIME TABLE CREATION

<HTML>
<HEAD>
<TITLE> CLASS TIME TABLE </TITLE>
</HEAD>
<BODY>
<CENTER> <H3> PU SCIENCE COLLEGE </H3>
<CENTER> <H4> TIME TABLE 2024-25 </H4>
<TABLE BORDER=10 BORDERCOLOR=RED BGCOLOR=CORNSILK
CELLSPACING=2
CELLPADDING=15>
<CAPTION> <B> II PUC PCMCs </B> </CAPTION>
<TR BGCOLOR=PEACHPUFF>
<TD ROWSPAN=2 ALIGN=CENTER> <B> DAY </B> </TD>
<TD COLSPAN=8 ALIGN=CENTER> <B> TIMINGS </B></TD>
</TR>
<TR BGCOLOR=RED>
<TH> 9.20 - 10.20 </TH>
<TH> 10.20 - 11.20 </TH>
<TH> 11.20 - 11.30 </TH>
<TH> 11.30 - 12.30 </TH>
<TH> 12.30 - 1.30 </TH>
<TH> 1.30 - 2.30 </TH>
<TH> 2.30 - 3.15 </TH>
<TH> 3.15 - 4.00 </TH>
</TR>
<TR>
<TD> MONDAY </TD>
<TD> MATHS </TD>
<TD> PHYSICS </TD>
<TD ROWSPAN=6 ALIGN=”CENTER”>SHORT BREAK</TD>
<TD> CHEMISTRY </TD>
<TD> COMP SCI </TD>
<TD ROWSPAN=6 ALIGN=CENTER>LUNCH BREAK</TD>
<TD COLSPAN=2ALIGN=CENTER><………COMP SCI LAB…..> </TD>
28
CS LAB MANUAL II PUC

</TR>
<TR>
<TD>TUESDAY</TD>
<TD> PHYSICS </TD>
<TD> MATHS </TD>
<TD> CHEMISTRY </TD>
<TD> ENGLISH </TD>
<TD COLSPAN=2 ALIGN=CENTER><………PHYSICS LAB……></TD>
</TR>
<TR>
<TD> WEDNESDAY </TD>
<TD> COMP SCI </TD>
<TD> PHYSICS </TD>
<TD> MATHS </TD>
<TD> KANNADA </TD>
<TD COLSPAN=2 ALIGN=CENTER><……CHEMISTRY LAB….></TD>
</TR>

</TABLE>
</CENTER>
</BODY>
</HTML> OUTPUT

29
CS LAB MANUAL II PUC

HTML-2 : FORM CREATION

<HTML>
<HEAD>
<TITLE> ONLINE APPLICATION </TITLE>
</HEAD>
<BODY>
<FORM>
<H3 ALIGN=CENTER> FIRST PUC APPLICATION FORM </H3>
<TABLE BORDER= 5 CELLSPACING=5 CELLPADDING=5%
ALIGN=CENTER>
<TR>
<TD ALIGN=LEFT>STUDENT NAME: </TD>
<TD><INPUT TYPE=”TEXT” NAME=”STUNAME”></TD>
</TR>

<TR>
<TD ALIGN=LEFT>GENDER: </TD>
<TD><INPUT TYPE=RADIO NAME=GEN VALUE=”M”>MALE
<INPUT TYPE=RADIO NAME=GEN VALUE=”F”>FEMALE</TD>
</TR>
<TR>

<TD ALIGN=LEFT>Indicate the Board PASSED: </TD>


<TD ALGIN=LEFT><INPUT TYPE=”TEXT” NAME=”QUALIFICATION” >
<SELECT NAME=”DROPDOWN” SIZE=2 ID=QUALI>
<OPTION VALUE=1>PU</OPTION>
<OPTION VALUE=2>CBSE</OPTION>
</SELECT>
</TD>
</TR>
<TR>
30
CS LAB MANUAL II PUC

<TD ALGIN=LEFT>SUBJECT CHOOSEN: </TD>


<TD ALGIN=LEFT>

<INPUT TYPE=CHECKBOX NAME=SUB1 >PHYSICS


<INPUT TYPE=CHECKBOX NAME=SUB2 >CHEMISTRY
<INPUT TYPE=CHECKBOX NAME=SUB3 >MATHS
<INPUT TYPE=CHECKBOX NAME=SUB5 >COMP SCI

</TD>
</TR><TR>
<TD><INPUT TYPE="SUBMIT" VALUE="SUBMIT THE FORM"> </TD>
<TD><INPUT TYPE="RESET" VALUE="RESET THE FORM"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
OUTPUT

31

You might also like