Beruflich Dokumente
Kultur Dokumente
SECOND PUC
COMPUTER SCIENCE
Salma Begum J
Lecturer,
OASIS PU COLLEGE
OUTPUT
OUTPUT
OUTPUT
4 . Write a program to sort the elements of an array in ascending order using insertion sort.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[100],n,i,j,temp;
clrscr();
cout<<"Enter the size of array"<<endl;
cin>>n;
cout<<"Enter the elements of array"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Unsorted array:"<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"
";
}
cout<<endl;
for(i=1;i<n;i++)
{
j=i;
while(j>=1)
{
if(a[j]<a[j-1])
{
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
j=j-1;
}
}
cout<<"Sorted array:"<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<"
";
}
getch();
}
OUTPUT
5. Write a program to search for a given element in an array using Binary search method.
#include<iostream.h>
#include<conio.h>
void main()
{
int a[100],ele,n,i,mid,low,high,loc;
clrscr();
cout<<"Enter the size of array"<<endl;
cin>>n;
cout<<"Enter the elements of array"<<endl;
for(i=0;i<n;i++)
{
cin>>a[i];
}
cout<<"Enter the element to be searched"<<endl;
cin>>ele;
high=n-1;
low=0;
loc=-1;
while(low<=high)
{
mid=(low+high)/2;
if(a[mid]==ele)
{
loc=mid+1;
break;
}
if(ele>a[mid])
low=mid+1;
else
high=mid-1;
}
if(loc==-1)
cout<<"Element not found"<<endl;
else
cout<<"Element "<<ele<<" found at location "<<loc;
getch();
}
OUTPUT
6 . Write a program to create a class with data members principle, time and rate. Create member
functions to accept data values to compute simple interest and to display the result.
#include<iostream.h>
#include<conio.h>
class simple_interest
{
private:
int principle,time,rate;
float si;
public:
void input_data()
{
cout<<"Input Principle amount=";
cin>>principle;
cout<<"Input time in years=";
cin>>time;
cout<<"Input rate of interest=";
cin>>rate;
}
void compute()
{
si=principle*rate*time/100;
}
void display()
{
cout<<"Simple interest="<<si;
}
};
void main()
{
simple_interest s;
clrscr();
s.input_data();
s.compute();
s.display();
getch();
}
OUTPUT
7. Write a program to create a class with data members a, b, c and member functions to input
data, compute the discriminant based on the following conditions and print the roots.
If determinant=0, print the roots that are equal
If the discriminant is>0, print the real roots
If the discriminant<0, print that the roots are imaginary
#include<iostream.h>
#include<conio.h>
#include<math.h>
class roots
{
private:
int a,b,c;
float det,x,x1,x2;
public:
void input_data()
{
cout<<"Input the values for co-efficients (a,b and c)";
cout<<"a=";
cin>>a;
cout<<"b=";
cin>>b;
cout<<"c=";
cin>>c;
}
void compute()
{
det=b*b-4*a*c;
}
void display()
{
if(det==0)
{
x=-b/(2*a);
cout<<"Roots are equal"<<endl;
cout<<"Root is "<<x;
}
if(det<0)
{
cout<<"Roots are imaginary"<<endl;
}
if(det>0)
{
x1=(-b+sqrt(det))/(2*a);
x2=(-b-sqrt(det))/(2*a);
cout<<"Roots are real and distinct"<<endl;
cout<<"Roots are "<<x1<<"and"<<x2;
}
}
};
void main()
{
roots r;
clrscr();
r.input_data();
r.compute();
r.display();
getch();
}
OUTPUT
case 3:area(a,b,c);
break;
default:cout<<"Invalid option";
break;
}
getch();
}
OUTPUT
OUTPUT
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,n,i,x;
public:
series()
{
sum=1;
}
void input_data()
{
cout<<"Enter the value of n"<<endl;
cin>>n;
cout<<"Enter the value of x"<<endl;
cin>>x;
}
void sum_series()
{
for(i=1;i<=n;i++)
{
sum=sum+pow(x,i);
}
}
void display()
{
cout<<"Sum of the series is "<<sum;
}
};
void main()
{
series s;
clrscr();
s.input_data();
s.sum_series();
s.display();
getch();
}
OUTPUT
11. Create a base class containing the data members roll number and name. Also create a member
function 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 roll_no;
char name[50];
public:
void input_data()
{
cout<<"Enter the roll number:";
cin>>roll_no;
cout<<"Enter the name:";
cin>>name;
}
void display_data()
{
cout<<"Roll number:"<<roll_no<<endl;
cout<<"Name of student:"<<name<<endl;
}
};
class marks:public student
{
private:
int m1,m2,total;
public:
void input_marks()
{
cout<<"Enter the marks of two subjects"<<endl;
cout<<"Subject 1:";
cin>>m1;
cout<<"Subject 2:";
cin>>m2;
}
void calculate()
{
total=m1+m2;
}
void display_marks()
{
cout<<"Subject 1="<<m1<<endl;
cout<<"subject 2="<<m2<<endl;
cout<<"Total="<<total;
}
};
void main()
{
marks m;
clrscr();
m.input_data();
m.input_marks();
m.calculate();
m.display_data();
m.display_marks();
getch();
}
OUTPUT
12. Create a class containing the following data members register No., name and fees. Also create a
member function to read and display the data using the concept of pointers to objects.
#include<iostream.h>
#include<conio.h>
class student
{
private:
int roll_no,fees;
char name[50];
public:
void read_data()
{
cout<<"Enter the roll number:";
cin>>roll_no;
cout<<"Enter the name:";
cin>>name;
cout<<"Enter the fees:";
cin>>fees;
}
void display_data()
{
cout<<"Roll number:"<<roll_no<<endl;
cout<<"Name of student:"<<name<<endl;
cout<<"Fees:"<<fees<<endl;
}
};
void main()
{
student *s;
clrscr();
s->read_data();
s->display_data();
getch();
}
OUTPUT
OUTPUT
case 2:s.pop();
break;
case 3:s.display();
break;
default:cout<<"Invalid option"<<endl;
break;
}
cout<<"Do you wish to continue(y/n)"<<endl;
cin>>choice;
}while(choice=='y');
getch();
}
OUTPUT
case 1:q.enque();
break;
case 2:q.deque();
break;
case 3:q.display();
break;
default:cout<<"Invalid option"<<endl;
break;
}
cout<<"Do you wish to continue(y/n)"<<endl;
cin>>choice;
}while(choice=='y');
getch();
}
OUTPUT
void append()
{
cout<<"Enter element to insert"<<endl;
cin>>ele;
newnode=new node;
newnode->data=ele;
newnode->link=NULL;
if(start==NULL)
{
start=newnode;
cout<<ele<<" is inserted"<<endl;
}
else
{
temp=start;
while(temp->link!=NULL)
temp=temp->link;
temp->link=newnode;
cout<<ele<<" is inserted"<<endl;
}
}
void display()
{
if(start==NULL)
{
cout<<"Linked list is empty"<<endl;
return;
}
cout<<"Linked list contains"<<endl;
temp=start;
while(temp!=NULL)
{
cout<<temp->data<<"->";
temp=temp->link;
}
cout<<"NULL"<<endl;
}
};
void main()
{
char choice;
int option;
linked_list l;
clrscr();
do
{
cout<<"Enter:"<<endl;
cout<<"1->Append"<<endl;
cout<<"2->Display"<<endl;
cin>>option;
switch(option)
{
case 1:l.append();
break;
case 2:l.display();
break;
default:cout<<"Invalid choice"<<endl;
break;
}
cout<<"Do you wish to continue(y/n):";
cin>>choice;
}while(choice=='y');
getch();
}
OUTPUT
Section B SQL
17. Generate the Electricity Bill for one consumer
1. Create a table
sql> create table ebill(RR_number varchar(10),Consumer_name
varchar(30),bill_date date,Units_consumed number(5));
4. View table
sql>select * from ebill;
7. View table
sql>select * from ebill;
4. View table
sql>select * from student;
7. View table
sql>select * from student;
10.
Count the nmber of students who have scored more than 60
percentage
sql>select count(*) from student where Percentage>60;
11.
List the students who have failed
sql>select * from student where Result=Fail;
12.
List the students who have passed.
sql>select * from student where Result=First Class or
Result=Second Class;
19 Generate the Employee details and compute the salary based on the
department.
1. Create table
sql>create table employee(Emp_id number(5),Emp_name
varchar(30),Department varchar(20),Salary number(10));
2. Enter 10 rows into table.
sql>insert into employee values(786523,Zain,Accounts,30000);
sql>insert into employee values(786521,Zain,Sales,40000);
sql>insert into employee values(786522,Owais,Purchase,35000);
sql>insert into employee values(786523,Saad, Purchase,25000);
sql>insert into employee values(786524,Zuhair,Sales,20000);
sql>insert into employee values(786525,Akhtar,Purchase,36000);
sql>insert into employee values(786526,Ali, Purchase,45000);
sql>insert into employee values(786527,Dyaan,Sales,27000);
sql>insert into employee values(786528,Yasir,Purchase,39000);
sql>insert into employee values(786529,Aamir,Sales,42000);
sql>insert into employee values(786530,Hashim,Sales,36000);
3. Find the names of the employees who work for sales department
sql>select * from employee where Department=Sales;
6. View table
sql>select * from employee;
10.
Delete the rows for the employee who works for purchase
department.
sql>delete from employee where Department=Purchase;
11.
View table.
sql>select * from employee;
10.
Find the sum of amount withdrawn.
sql>select sum(T_amount) from bank T_type=W;
Section C HTML
21. Write a HTML program to create a study time-table.
<html>
<head>
<title>Table</title>
</head>
<body bgcolor="pink">
<center><h1>MY STUDY TIME TABLE</h1></center>
<center>
<table border=5px bgcolor="orange" height=400px width=800px>
<tr>
<th>DAY</th>
<th>Morning study time</th>
<th>College timings</th>
<th>Evening study time</th>
<th>Question paper solving</th>
</tr>
<tr>
<td>MONDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 4:00</td>
<td>6:00 to 8:30</td>
<td>9:00 to 10:30</td>
</tr>
<tr>
<td>TUESDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 4:00</td>
<td>6:00 to 8:30</td>
<td>9:00 to 10:30</td>
</tr>
<tr>
<td>WEDNESDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 4:00</td>
<td>6:00 to 7:30</td>
<td>9:30 to 10:30</td>
</tr>
<tr>
<td>THURSDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 4:00</td>
<td>6:00 to 7:30</td>
<td>9:30 to 10:30</td>
</tr>
<tr>
<td>FRIDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 4:00</td>
<td>6:00 to 7:30</td>
<td>9:30 to 10:30</td>
</tr>
<tr>
<td>SATURDAY</th>
<td>5:00 to 6:30</td>
<td>8:30 to 1:00</td>
<td>5:00 to 7:30</td>
<td>8:30 to 10:30</td>
</tr>
</table>
</center>
<marquee direction="left"><h1>All the best!!!</h1></marquee>
</body>
</html>
OUTPUT
<tr>
<td>
<label for="mail">Email id</label>
</td>
<td>
<input type="text" name="mail" maxlength="50" size="50">
</td>
</tr>
<tr>
<td>
<input type="Submit" value="Submit form">
</td>
</tr>
</form>
</table>
</body>
</html>
OUTPUT