You are on page 1of 48

Department of BCA

Department of BCA
Government First Grade College,
Tumkur

Lab Manual for II BCA (III SEM)

GFGC, Tumkur 1
Department of BCA

C++ LAB PROGRAMS

GFGC, Tumkur 2
Department of BCA
1. Write a C++ program to implement digital clock.

#include<iostream.h>
#include<dos.h>
#include<iomanip.h>
#include<conio.h>
#include<time.h>
void main ()
{
char tbuffer[9];
clrscr();
gotoxy(32,10);
cout<<”digital clock”;
gotoxy(30,11);
cout<<”+---------------+---------------+”;
gotoxy(30,12);
cout<<”|| ||”;
gotoxy(30,13);
cout<<+----------------+----------------+”;
gotoxy(27,18);
cout<<”press any key to exit”;
while(!kbhit())
{
_strtime(tbuffer);
gotoxy(34,12);
cout<<”tbuffer”;
delay(100);
}
getch();
}

GFGC, Tumkur 3
Department of BCA

2. Write a C++ program to calculate area and circumference of a circle using inline
function.

#include<iostream.h>
#include<conio.h>
#include<math.h>
inline float circum (float r)
{
return (2*3.142*r);
}
inline float area (float r)
{
return (3.142*r*r);
}
void main ( )
{
float x;
cout<<”enter the radius of circle”<<endl;
cin>>r;
cout<<”circumference=”<<circum(r) <<endl;
cout<<”area=”<<area(r) <<endl;
getch( );
}

GFGC, Tumkur 4
Department of BCA

3. Write a C++ program to find factorial of given number using command line
argument.

#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
void main(int argc, char *argv[])
{
int i, fact, n;
clrscr();
n=atoi (argv[1]);
fact=1;
cout<<”total number of arguments :”<<argc<<endl;
cout<<”enter the number”;
cin>>”n”;
for(i=1; i<=n; i++)
{
fact=fact*i;
}
cout<<”factorial of “<<n<<”is”<<fact;
getch();
}

GFGC, Tumkur 5
Department of BCA

4. write a c++ program to prepare shopping list using array of object


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
constint size=3;
class item
{
private: char name [25];
float rate;
int qty;
float amount;
public: void getdata()
{
cout<<”enter item name:” ;
cin>>name;
cout<<”enter item quantity:” ;
cin>>qty;
cout<<”enter the rate:” ;
cin>>rate;
cout<<endl;
}
void print()
{
cout<<setw(2)<<name;
cout<<setw(5)<<qty;
cout<<setw(5)<<rate;
amount=rate*qty;
cout<<setw(7)<<amount<<endl;
}
};
void main()
{
clrscr();
item shop[size];
for(int i=0; i<size; i++)
shop[i].getdata();
cout<<”detais of shopping list”<<endl;
cout<<”---------------------------------“<<endl;
cout<<”name”<<setw(8)<<”qty”<<setw(8)<<”rate”<<setw(8)<<”amount”<<end;
for(i=0; i<size; i++)
shop[i]. print();
cout<<endl;
getch();
}
GFGC, Tumkur 6
Department of BCA

5. Write a C++ program to find maximum of two numbers using friend function

#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
class max
{
private: int a, b;
public: void getdata()
{
cout<<”enter two numbers:”;
cin>>a>>b;
}
friend int biggest (max p, max q)
{
if (p.a>q.b)
return p.a;
else
return p.b;
}
};
void main()
{
clrscr();
max r;
r.getdata();
cout<<” maximum of two numbers is”<<biggest(r, r);
getch();
}

GFGC, Tumkur 7
Department of BCA

6. Write a C++ program to swap two number using copy construct.

#include<iostream.h>
#include<conio.h>
class copy
{
private: int v1,v2, t;
public: copy(int a, int b)
{
v1=a;
v2=b;
}
void swap()
{
t=v1;
v1=v2;
v2=v1;
}
void display()
{
cout<<”x=”<<v1;
cout<<”y=”<<v2;
}
};
void main()
{
clrscr();
int x, y;
cout<<”\n enter the value of x and y:”;
cin>>x>>y;
copy obj (x, y);
copy cpy=obj;
cout<<”\n \t”<<”before swapping values are “<<”x=”<<x<<”y=”<<y;
cout<<”\n \t”<<”swapping values using obj objects “;
obj.swap();
obj.display();
cout<<”\n \t”<<”swapping values using copy objects “;
cpy.swap();
cpy.display();
getch();
}

GFGC, Tumkur 8
Department of BCA

7. Write a C++ program to find maximum of two numbers for different data types
using template function.

#include<iostream.h>
#include<conio.h>
Template <class L>
l find (l &m, l &n)
{
l temp;
if(m>n)
temp=m;
else
temp=n;
return[temp];
};
void main()
{
int a, b, l1;
float x, y, l2;
clrscr();
cout<<”enter the two integer”<<endl;
cin>>a>>b;
l1=find(a , b);
cout<<”largest of two integers is “<< l1 <<endl;
cout<<”enter the two real number”<<endl;
cin>>x>>y;
l2=find(x, y);
cout<<”largest of two real number is “<<l2<<endl;
getch();
}

GFGC, Tumkur 9
Department of BCA

8. Write a C++ program to write and read the data in the file.

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
Int main()
{
Char ch, data[100];
Clrscr();
Int lines=0;
Ofstream outfile;
outfile.open(“bca.text”);
cout<<”writing to the file “<<endl;
cout<<”enter your name : “ ;
cin.getline(data,100);
outfile<<data<<endl;
cout<<”Enter your age : “ ;
cin>>data;
outfile<<data<<endl;
outfile .close();
ifstream infile;
inlife .open (“bca.text”);
cout<<”reading from the file “<<endl;
while(!Infile .eof () )
{
Infile.get(ch);
Cout<<ch;
If(ch==”\n”)
++lines;
}
Cout<<”number of lines “<<lines<<endl;
Infile.close();
Getch();
Return 0;
}

GFGC, Tumkur 10
Department of BCA
9. Write a C++ program to perform bank transaction to find balance of amount of
saving account using friend function.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class current;
class saving;
{
private: char name[20];
int accno;
float balance;
public: void getdata()
{
cout<<”\n savings account details \n”;
cout<<” enter a name:“;
cin>>name;
cout<<”account number:”;
cin>>accno;
cout<<”balance:”;
cin>>balane;
}
friend float totbalance(saving ,current);
};
class current
{
private: char name[20];
int accno;
float balance;
public: void getdata()
{
cout<<”\n current account details \n”;
cout<<”\n name: “;
cin>>name;
cout<<”account number:”;
cin>>accno;
cout<<”balance:”;
cin>>balane;
}
friend float totbalance(saving ,current);
};
float totbalance(saving sav, current cur)
{
cout<<endl<<”------------------------------------“<<endl;
cout<<”\n saving account balance:rs “<<setw(6)<<sav.balance<<endl;
cout<<”\n current account balance:rs “<<setw(6)<<cur.balance<<endl;
return (sav.balance+cur.balance);
}

GFGC, Tumkur 11
Department of BCA
void main()
{
saving s;
current c;
clrscr();
s.getdata();
c.getdata();
cout<<”\n total balance :rs “<<setw(6)<<totbalance(s ,c)<<endl;
cout<<endl<<”------------------------------------------“<<endl;
getch();
}

GFGC, Tumkur 12
Department of BCA
10. Write a c++ program to print the sum of two complex numbers using friend
function.
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
class complex
{
private: float real, img;
public: void getdata()
{
cout<<”\n enter real part :”;
cin>>real;
cout<<”\n enter imaginary part :”;
cin>>img;
}
void show()
{
if(img<0)
cout<<real<<”-i”<<img;
else
cout<<real<<”+i”<<img;
}
friend complex operator + (complex ,complex );
};
complex operator + (complex c1 ,complex c2)
{
complex temp;
temp.real=c1.real+c2.real;
temp.img=c1.img+c2.img;
return(temp);
}
void main();
{
clrscr();
complex c1,c2,c3;
cout<<”\n first complex number \n”;
c1.getdata();
cout<<”\n second complex number \n”;
c2.getdata();
c3=c1+c2;
cout<<”\n first complex number \n”;
c1.show();
cout<<”\n second complex number \n”;
c2.show();
cout<<”\n sum of complex number \n”;
c3.show();
getch();
}
GFGC, Tumkur 13
Department of BCA
11. Write a C++ program addition of two matrices using + operator overloading.

#include<iostream.h>
#include<conio.h>
#include<iomanips.h>
class matrix
{
private: int mat[10][10];
int r, c;
public: matrix () { };
void size (int m, int n)
{
r=m;
c=n;
}
void mat input();
void mat print();
matrix operator + (matrix);
};
void matrix : : mat input()
{
cout<<”\n enter “<<r*c<<” elements:”;
for (inti=0;i<r;i++)
for (int j=0; j< c; j++)
cin>> mat [i] [j];
}
void matrix : : mat print ()
{
for (int i=0; i<r; i++)
{
for(int j=0; j<c;j++)
cout<<mat[i][j]<<setw(6);
cout<<”\n”;
}
}
matrix matrix::operator + (matrix m)
{
matrix mat sum;
matsum.size(r,c);
for (int i=0; i<r; i++)
for (int j=0; j<c; j++)
matsum.mat[i][j]=mat[i][j]+m.mat[i][j];
return matsum;
}
void main()
{
clrscr();
matrix a,b,c;

GFGC, Tumkur 14
Department of BCA
int r,c;
cout<<”\n enter the order of matrix “;
cin>>r>>c;
a.size(r,c);
b.size(r,c);
c.size(r,c);
cout<<”\n matrix a”;
a.matinput();
cout<<”\n matrix b”;
b.matinput();
cout<<”\n matrix a”;
a.matprint();
cout<<”\n matrix b”;
b.matprint();
c=a+b;
cout<<”\n sum of matrices :\n”;
c.matprint();
getch();
}

GFGC, Tumkur 15
Department of BCA

12. Write a C++ program to perform multiplication of two matrices using *


operator overloading.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<stdlib.h>
class matrix
{
private: int mat[10][10];
int r, c;
public: matrix () { };
void size (int m, int n)
{
r=m;
c=n;
}
void mat input();
void mat print();
matrix operator * (matrix);
}
void matrix : : mat input()
{
cout<<”\n type “<<r<<”*”<<r<<” elements:”;
for (int i=0; i<r; i++)
for (int j=0; j<c; j++)
cin>> mat[i][j];
}
void matrix : : mat print ()
{
for(int i=0; i<r; i++)
{
for(int j=0; j<c;j++)
cout<<mat[i][j]<<setw(6);
cout<<”\n”;
}
}
matrix matrix::operator * (matrix m)
{
matrix matprod;
matprod.size(r,c);
for (int i=0; i<r; i++)
for (int j=0; j<c; j++)
{
matprod.mat[i][j]=0;
for (int k=0; k<r; k++)
matprod.mat[i][j]=matprod.mat[i][j]+mat[i][k]*m.mat[k][j];

GFGC, Tumkur 16
Department of BCA
}
return matprod;
}
void main()
{
clrscr();
matrix a, b, c;
int r, c;
cout<<”\n enter the order of matrix “;
cin>>r>>c;
a.size(r,c);
b.size(r,c);
c.size(r,c);
cout<<”\n matrix a”;
a.matinput();
cout<<”\n matrix b”;
b.matinput();
cout<<”\n matrix a”;
a.matprint();
cout<<”\n matrix b”;
b.matprint();
c=a*b;
cout<<”\n product of matrices :\n”;
c.matprint();
getch();
}

GFGC, Tumkur 17
Department of BCA

13. Write a C++ program to compare two given string using == operator with
friend function.

#include<iosrteam.h>
#include<conio.h>
#include<string.h>
class string
{
private:char str[50];
public:void show();
{ cout<<str;
}
void getdata()
{
cin>>str;
}
friend int operator ==(string , string);
};
int operator ==(string t1 , string t2)
{
if(strcmp(t1.str ,t2.str)==0)
return 1;
else
return 2;
}
void main()
{
clrscr();
srtings1, s2;
cout<<”enter the first string :”<<endl;
s1.getdata();
cout<<”enter the second string :”<<endl;
s2.getdata();
cout<<endl<<” first string :”<<endl;
s1.show();
cout<<endl<<”second string :”<<endl;
s2.show();
if(s1==s2)
cout<<endl<<”string are equal”<<endl;
else
cout<<endl<<”string are not equal”<<endl;
getch();
}

GFGC, Tumkur 18
Department of BCA

14. Write a C++ program to concatenate two given string using + operator with
friend function.

#include<iosrteam.h>
#include<conio.h>
#include<string.h>
class string
{
private:char str[80];
public: void show();
{
cout<<str;
}
void getdata()
{
cin>>str;
}
friend int operator + (string , string);
};
string operator ==(string t1 , string t2)
{
string temp;
strcpy(temp.str ,t1.str);
strcpy(temp.str ,t2.str);
return(temp);
}
void main()
{
clrscr();
srtings1, s2, s3;
cout<<”enter the first string :”<<endl;
s1.getdata();
cout<<”enter the second string :”<<endl;
s2.getdata();
cout<<endl<<” first string :”<<endl;
s1.show();
cout<<endl<<”second string :”<<endl;
s2.show();
s3=s1+s2;
cout<<”concatenated string is :”<<endl;
s3.show();
getch();
}

GFGC, Tumkur 19
Department of BCA

15. Write a C++ program to create student report using inheritance technique.

#include<iostream.h>
#include<conio.h>
#include<string.h>
class student
{
private: char name[20];
int regno;
public: void getdata()
{
cout<<”\n enter the name and regno of student “;
cin>>name>>regno;
}
void printdata()
{
cout<<”\n student details “;
cout<<name;
cout<<regno;
}
};
class marks: public student
{
private:int oops , os , dbms ;
float precent ;
public: void getmarks()
{
cout<<”enter the marks of oops ,os ,dbms :”;
cin>>oops>>os>>dbms;
}
void printmarks()
{
percent=(oops+os+dbms)/3;
cout<<”percentage is “<<percent<<endl;
}
};
void main()
{
clrscr();
marks m;
m.getdata();
m.printdata();
m.getmarks();
m.printmarks();
getch();
}

GFGC, Tumkur 20
Department of BCA

16. Write a C++ program to implement area of geometrical figures (Circle and
square ) using pure virtual function.

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
#include<math.h>
class shape
{
public: virtual void getdata()=0;
virtual float area()=0;
};
class square: public shape
{
float side;
public: void getdata()
{
cout<<”\n enter a side “;
cin>>side;
}
float area()
{
return side*side;
}
};
class circl : public shape
{
private: float r;
public: voidgetdata()
{
cout<<”\n enter the radius :”;
cin>>r;
}
float area()
{
return (3.142*r*r);
}
};
voidmain()
{
square s;
circle c;
clrscr();
cout<<setprecision(2);
GFGC, Tumkur 21
Department of BCA
cout<<”\n square input \n”;
s.getdata();
cout<<”\n area:”<<s.area() <<endl;
cout<<”\n circle input \n”;
c.getdata();
cout<<”\n area :”<<c.area() <<endl;
getch();
}

GFGC, Tumkur 22
Department of BCA

HTML / IP

GFGC, Tumkur 23
Department of BCA

1. Write a HTML code to create simple Web page to display your college
information.
<html>
<head><h1><center> college information.</center></h1>
<title> college information.</title>
</head>
<body>
<font size=05 face=jokerman color=green>Government First Grade College, Tumkur</font>
<br>
<font size=05 face=Calibri color=green>It is an Government Institution</font><br>
<br>
<h2>List of Courses offered</h2>
<pre

1. BCA
2. BSc
3. BA
4. BCom
5. BBM
</pre>
</body>
</html>

2. Write a HTML code to display different levels of headings.


<html>
<head>
<title> Headings</title>
<body>
<font size=05 face=Calibri color=green>Different levels of headings</font><br>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
</body>
</html>

GFGC, Tumkur 24
Department of BCA

3. Write a HTML code to illustrate all text formatting tags.


<html>
<head>
<title> Text Tags </title>
</head>
<body>
<center>
<h1 align="center">To illustrate text formatting tags </h1>
<hr color="red">
<P><marquee behavior="alternate">This is an alternate Marquee text
</marquee>
<p>This is <i>italized</i></p>
<p>This is <u> underlined </u></p>
<p>This is <b> bold </b></p>
<p>This is <em> emphasized </em></p>
<p>This is <Strong> Strong Text </strong></p>
<p>This is <s>striked text </s></p>
<p>This is <code> computer code </code></p>
<p>This is <sup> superscript </sup> code </p>
<p>This is <sub> subscript </sub> code </p>
<p>This is <big> big text </big></p>
<p>This is <small> small text </small></p>
</center>
</body>
</html>

GFGC, Tumkur 25
Department of BCA

4. Write a HTML code to create different types of ordered lists.


<html>
<head>
<title> Order List tag </title>
</head>
<body>
<h3 align="center" style="color:blue">To illustrate ORDER list tags</h3>
<hr COLOR="BLUE">
<h4>Numbered list:</h4>
<ol>
<li>Mango</li>
<li>Bananas</li>
<li>Watermelon</li>
<li>Grapes</li>
</ol>
<h4>Uppercase Letters list:</h4>
<ol type="A">
<li>Mango</li>
<li>Bananas</li>
<li>Watermelon</li>
<li>Grapes</li>
</ol>
<h4>Lowercase letters list:</h4>
<ol type="a">
<li>Mango</li>
<li>Bananas</li>
<li>Watermelon</li>
<li>Grapes</li>
</ol>
<h4>Roman numbers list:</h4>
<ol type="I">
<li>Mango</li>
<li>Bananas</li>
<li>Watermelon</li>
<li>Grapes</li>
</ol>
<h4>Lowercase Roman numbers list:</h4>
<ol type="i">
<li>Mango</li>
<li>Bananas</li>
<li>Watermelon</li>
<li>Grapes</li>
</ol>
</body>
</html>

GFGC, Tumkur 26
Department of BCA

5. Write a HTML code to display the glossary of any 5 HTML tags using definition
lists.
<html>
<head>
<title>Lab-5 definition lists</title>
<./head>
<body bgcolor=”greenyellow” leftmargin=”10” topmargine=”50”>
<font size=”5”>
<dl>
<dt><b><u>Body Tag:</u></b></dt>
<dd>It selects with &lt; body &gt; indicating body beginning, it has various attributes like
bgcolor, background, b property, topmargin, text, title that helps inserting different properties to
entire body<br>
Example : &lt; body bgcolor=”green” text=”red” &gt;
------------------
&lt; /body &gt;
</dd>
</dl>
<dt><b><u>center Tag:</u></b></dt>
<dd> Center tag is used to align the center enclosed within the tag to center, contents may be any
text, image, table<br>
Example : &lt; center &gt;
------------------
&lt; /center &gt;
</dd>
</dl>
<dl>
<dt><b><u>Horizontal line(HR Tag):</u></b></dt>
<dd> Horizontal line tag is used to insert a horizontal line within the document. We can provide
the attribute such as align, color, normal, size, width<br>
Example : &lt; hr align =”center” color=”pink” size=” 15” width=”100%” &gt;
</dd>
<dl>
<font>
</body>
</html>

GFGC, Tumkur 27
Department of BCA

6. Write a HTML code to insert an image of ‘Tim Berners Lee’ and displayhis Bio
data.

<html>
<head>
<title>Lab-6 Biodata </title>
</head>
<body bgcolor=”palevioletered” text=”green” scroll=”yes” leftmargin=”10” topmargine=”50”>
<center>
<font size=”+4” face=”cartellar”>Bio-Data of Tim Berners Lee</font></center>
<img src=”tim.jpg” width=”250” border=”3” height=”25” act=tim” align=”right”>
<h1>
<b>Name:</b> <font color=”white” size=”5”> Tim Berners Lee</font><br>
<b>DOB:</b> <font color=”white” size=”5”> 8<sup>th</sup>June 1995</font><br>
<b>Father Name:</b> <font color=”white” size=”5”> Conway Berners-Lee</font><br>
<b>Mother Name:</b> <font color=”white” size=”5”> Mary Lee Woods</font><br>
<b>spouse:</b><font color=”white” size=”5”> Rosemary Leith and Nancy Carlson</font><br>
<b>Education:</b> <font color=”white” size=”5”> The Queen’s College, Oxford</font><br>
<b>Award:</b><font color=”white” size=”5”> Queen Elizabeth Prize[2013], OM[2007],
KEB[2004],FRS[2001],FRENF[2001],…….etc</font><br>
<b>Institution he worked:</b> <font color=”white” size=”5”> University South Ampton
University of Oxford, World Wide Web Consortium</font><br>
</h1>
<h2>
<marquee direction=”right”>Berners Lee worked as director n of WWW and contributed in
development of WWW consortium<br></font>
</h2>
</body>
</html>

GFGC, Tumkur 28
Department of BCA

7. Write a HTML code to embed multimedia on to a web page.


<html>
<head>
<title> Lab-7 vedio </title>
</head>
<body bgcolor=”yellow” text=”raddlebrown” leftmargin=”10” topmargine=”155” >
<center>
<font size=”+4” face=”cartellar”>
<b>******** video Tag*******</b>
</font><br><br>
<embed src=”v.3gp” height=”400” width=”400”>
</center>
</body>
</html>

8. Write a HTML code to create text and images as links.


<html>
<head>
<title> Image Tag </title>
</head>
<body>
<h3 align="center" style="color:blue"> To illustrate image tags</h3><hr>
<p>
<a href=” ”> This text is used as link. </a>
</p>
<br><br><br><br><hr>
<p>
<a href=” ”><imgsrc="Tulips.jpg" align="left" height="100" width="100"/>
This image is used as link</a>
</body>
</html>

GFGC, Tumkur 29
Department of BCA

9. Write a HTML code to create your class time table.


<html>
<head>
<title> Lab-9 Time Table </title>
</head>
<body bgcolor=”red”>
<p align="center">
<font size=”6 ” face=”cooper”>
GOVERNMENT FIRST GRADE COLLEGE,TUMKUR<br></font>
<font size=”5” face=”cooper” color=”darkblue”>
DEPARTMENT OF COMPUTER SCIENCE <br></font>
</p>
<center>
<table cellpading=”5” cellspacing=”5” border=”5” =”red” align="center" width=”60%”>
<caption>
<font size=”5” face=”FootlightMT”>
3<sup>rd</sup> sem BCA Time Table</font>
</caption>
<font size=”5” face=”copperplate Gathic”>
<tr height=”50”>
<th> Day/Time</th>
<th>8:30-9:20</th>
<th>9:20-10:10</th>
<th>10:10-11:00</th>
<th>11:30-11:50</th>
<th colspan=”8”>12:00-4:00</th>
</tr>
<tr align=”center” height=”50”>
<th> Section</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th colspan=”4”>5</th>
</tr>
<tr align=”center” height=”50”>
<th>MONDAY</th>
<th>C++</th>
<th>IP</th>
<th>NALP</th>
<th>KAN</th>
<th colspan=”8”>----------</th>
</tr>
<tr align=”center” height=”50”>
<th>TUESDAY</th>
<th>C++</th>

GFGC, Tumkur 30
Department of BCA
<th>IP</th>
<th>ENG</th>
<th>KAN</th>
<th colspan=”8”>---NALP LAB ---</th>
</tr>
<tr align=”center” height=”50”>
<th>WEDNESDAY</th>
<th>C++</th>
<th>KAN</th>
<th>NALP</th>
<th>ENG</th>
<th colspan=”8”>----------</th>
</tr>
<tr align=”center” height=”50”>
<th>THURSDAY</th>
<th>IP</th>
<th>C++</th>
<th>C++</th>
<th>ENG</th>
<th colspan=”8”>----------</th>
</tr>
<tr align=”center” height=”50”>
<th>FRIDAY</th>
<th>IP</th>
<th>KAN</th>
<th>3ENG</th>
<th>NALP</th>
<th colspan=”8”>----------</th>
</tr>
<tr align=”center” height=”50”>
<th>SATURDAY</th>
<td colspan=”4” align=”center”> ---IP Lab--- </td>
<td colspan=”4” align=”center”> ---C++ Lab--- </td>
</tr>
</center>
</table>
</body>
</html>

GFGC, Tumkur 31
Department of BCA

10.Write a HTML code to create a form to accept student details.


<html>
<head>
<title> Lab-10 Student Details </title>
</head>
<body bgcolor=”cornsilk” text=”maroon” leftmargin=”10” topmargine=”50”>
<center>
<font size=”+4” face=”cooper”>
STUDENT DETAILS
</font>
</center>
<form action=” ” method=”get”>
<hr color=”gold” size=”4” width=”95%”>
<font size=”+2” face=”cooperplate Gathic”>
<b>Name:</b> <input type=”text” name=”stdname” size=”20”><br><br>
<b>Father Name:</b> <input type=”text” name=”fname” size=”20”><br><br>
<b>Mother Name:</b> <input type=”text” name=”fname” size=”20”><br><br>
<b>Date of Birth:></b><select name =”dd”>
<option>dd</option>
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>

GFGC, Tumkur 32
Department of BCA
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<b>/</b><select name =”mm”>
<option>mm</option>
<option>JAN</option>
<option>FEB</option>
<option>MAR<option>
<option>APR</option>
<option>MAY</option>
<option>JUN</option>
<option>JUL</option>
<option>AUG</option>
<option>SEPT</option>
<option>OCT</option>
<option>NOV</option>
<option>DEC</option>
</select>
<b>/</b><select name =”yy”>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
</select><br><br>
<b>Sex:</b><input type=”radio” name=”sex” value=”male”>Male
<input type=”radio” name=”sex” value=”female”> female<br> <br>
<b> course:</b><br>
<input type=”checkbox” name =”SSLC”>SSLC<br>
<input type=”checkbox” name =”PUC”>PUC<br>
<input type=”checkbox” name =”DIPLOMA”>DIPLOMA<br>
<center>
<b> attach file:</b><input type=”file” name=”photo”></b>
</center>
</font>
</form>
</body>
</html>

GFGC, Tumkur 33
Department of BCA

11.Write a HTML code to display a menu of twelve months.


<html>
<head>
<title> Lab-11 Menu Tag </title>
</head>
<body bgcolor=”turquoise” text=”darkblue” leftmargin=”10” topmargine=”50” >
<form action=” ” method=”get”>
<font size=”+4” face=”copper”>
<center> Select the Month You were born</center>
<hr size=”5”>
<center>
<b>DATE:</b>
<select the name=”DD”>
<option>DD</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>

GFGC, Tumkur 34
Department of BCA
</select>
<b>/</b><select name =”mm”>
<option>mm</option>
<option>JAN</option>
<option>FEB</option>
<option>MAR<option>
<option>APR</option>
<option>MAY</option>
<option>JUN</option>
<option>JUL</option>
<option>AUG</option>
<option>SEPT</option>
<option>OCT</option>
<option>NOV</option>
<option>DEC</option>
</select>
<b>/</b><select name =”yy”>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
</select><br><br>
<INPUT TYPE="submit" value=”submit”>
<INPUT TYPE=”reset” value=”clear”>
</center>
</form>
</body>
</html>

GFGC, Tumkur 35
Department of BCA

12.Write a HTML code to create nested frames.


<html>
<head>
<title> Frame tag </title>
</head>
<frameset Cols="20,60">
<frame src="f1.html">
<frame src="f2.html" name="main">
</frameset>
</html>
f1.html
<html>
<head>
<title> f1.html </title>
</head>
<body>
<h3> States of karnataka </h3>
<a href="banglore.html" target="main"> Banglore<br></a>
<a href="mysore.html" target="main"> Mysore<br> </a>
</body>
</html>
f2.html
<html>
<head>
<title> f2.html </title>
</head>
<body>
<h1> Click on any state to get a welcome message </h2>
</body>
</html>
Bangalore.html
<html>
<head>
<title> Banglore.html </title>
</head>
<body bgcolor="green">
<h1> Welcome to banglore </h1>
</body>
</html>
Mysore.html

<html>
<head>
<title> mysore.html </title>

GFGC, Tumkur 36
Department of BCA
</head>
<body bgcolor="red">
<h1> Welcome to mysore </h1>
</body>
</html>

13.Writing XML web Documents which make use of XML Declaration,Element


Declaration, Attribute Deceleration.
<? XML version=”1.0” encoding=”UTF-8”?>
<!DOC TYPE books>
<!—Text book information
<books>
<book category=”TextBook”>
<title> Programing The Word Wide</title>
<author>Robert W Seberts<author>
<publication>Person Education</publication>
</book>
<book category=”text book”>
<title> Programing The Word Wide</title>
<author>Robert W Seberts<author>
<publication>Person Education</publication>
</book>
<book category=”text book”>
<title> Web Programing</title>
<author> Srikanth S <author>
<publication>Sky word Publication</publication>
</book>
<book category=”text book”>
<title> C++</title>
<author>Balaguru Swamy<author>
<publication>Tata McGrow Publication</publication>
</book>
</books>
Internal DTD=>
<? XML version=”1.0” >
<!DOC TYPE books[
<! ELEMENT books (book)>
<! ELEMENT books (title,author,publication)>
<! ELEMENT title (#PCDATA)>
<! ELEMENT author (#PCDATA)>
<! ELEMENT publication (#PCDATA)>
]>
<!---Text book information -
<books>
<book category=”text book”>
<title> Programing The Word Wide</title>
<author>Robert W Seberts<author>
<publication>Person Education</publication>

GFGC, Tumkur 37
Department of BCA
</book>
<book category=”text book”>
<title> Web Programing</title>
<author> Srikanth S <author>
<publication>Sky word Publication</publication>
</book>
<book category=”text book”>
<title> C++</title>
<author>Balaguru Swamy<author>
<publication>Tata McGrow Publication</publication>
</book>
</books>

14.Usage of Internal DTD, External DTD, Entity Declaration.


<? XML version=”1.0” encoding=”UTF-8”?>
<!---Text book information -
<books>
<book category=”text book”>
<title> Programing The Word Wide</title>
<author>Robert W Seberts<author>
<publication>Person Education</publication>
</book>
<book category=”text book”>
<title> Web Programing</title>
<author> Srikanth S <author>
<publication>Sky word Publication</publication>
</book>
<book category=”text book”>
<title> C++</title>
<author>Balaguru Swamy<author>
<publication>Tata McGrow Publication</publication>
</book>
</books>

GFGC, Tumkur 38
Department of BCA

NALP / NT

GFGC, Tumkur 39
Department of BCA

1.Write a program to find the roots of an equation f(x)=0 using bisection method

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{
return(pow(x,3)+2*x+7);
}
void main()
{
int i=1;
float x0,x1,x2,acc;
double f0,f1,f2;
clrscr();
printf("\n enter the value for x0 and x1");
scanf("%f %f",&x0,&x1);
printf("\n enter accuracy ");
scanf("%f",&acc);
printf("\n iteration \t x0 \t x1 \tx2 \tf0 \t f1 \t f2");
do
{
x2=(x0+x1)/2;
f0=f(x0);
f1=f(x1);
f2=f(x2);
printf("\n %d %f %f %f %f %f %f",i,x0,x1,x2,f0,f1,f2);
if((f0*f2)<0)
x1=x2;
else
x0=x2;
i++;
}

while(fabs(f2)<acc);
printf("\n \n approximated root is %f",x2);
getch();
}

GFGC, Tumkur 40
Department of BCA

2.Write a program to find the simple or multiple root of f(x)=0 using newton raphson
method
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
float fx,dfx,x[50],acc,diff;
int n;
clrscr();
printf("\n Newton rapson method \n");
printf("\n Enter the initial approximation \n");
scanf("%f",&x[0]);
printf("\n enter the accuerace \n");
scanf("%f",&acc);
n=0;
do
{
fx=pow(x[n],3)-24;
dfx=3*pow(x[n],2);
x[++n]=x[n-1]-fx/dfx;
diff=fabs(x[n]-x[n-1]);
printf("\n approximation root =%f fx=%f at step number=%d",x[n],fx,n);
}
while(diff>=acc);
printf("Real root of equation in %f at step number %d",x[n],n);
getch();
}

GFGC, Tumkur 41
Department of BCA
3.write a program to find the root of system of non linear algebraic equation using
newton’s method

GFGC, Tumkur 42
Department of BCA
4.write a program to find the root of f(x)=0 using secant method

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<conio.h>
float f(float x);
void main()
{
float x1,x0,x,f0,f1,fx,acc,t1,t2;
int iter=0;
clrscr();
printf("\n secant method \n");
printf("enter the values of x0,x1 and acc \n");
scanf("%f%f%f",&x0,&x1,&acc);
f0=f(x0);
f1=f(x1);
printf("\n secant method");
printf("\n slno \tx0 \tx1 \tx \tf0 \tf1 \tfx \n");
do
{
iter++;
x=(x0*f(x1)-x1*f(x0))/(f(x1)-f(x0));
fx=f(x);
if(fx<0)
{
x0=x;
x1=x1;
}
else
{
x0=x0;
x1=x;
}
t2=x1-x0;
if(t2<0)
t2=-t2;
printf(" \n %3d %8.4f %8.4f %8.4f %8.4f %8.4f %8.4f \n",iter,x0,x1,x,f0,f1,fx);
}
while(t2>=acc);
printf("\n \t root %f in %d iteration \n",fx,iter);
getch();
return;
}
float f(float x)
{
return(x*x-25);
}

GFGC, Tumkur 43
Department of BCA
5.write a program to find the integral of a function using trapezoidal rule

#include<stdio.h>
#include<math.h>
#include<conio.h>
float find (float x);
void main()
{
float x0,xn,h,sum;
int i,n;
clrscr();
printf("\n trapezoidal rule\n");
printf("\n enter number of intervals \n");
scanf("%d",&n);
printf("\n enter lower limit \n");
scanf("%f",&x0);
printf("\n enter upper limit\n");
scanf("%f",&xn);
h=(xn-x0)/n;
sum=find(x0)+find(xn);
for(i=1;i<=n-1;i++)
sum=sum+2*find(x0+i*h);
sum=h/2.0*sum;
printf("\n interval=%f",sum);
getch();
}
float find(float x)
{
return(1.0/(1.0+x*x));
}

GFGC, Tumkur 44
Department of BCA

6.write a program to find the integral of a function using simpson’s 1/3rd and 3/8th
rule switch case

#include<stdio.h>
#include<math.h>
#include<conio.h>
float find (float x);
void main()
{
float x0,xn,h,sum;
int i,n;
clrscr();
printf("\n trapezoidal rule\n");
printf("\n enter number of intervals \n");
scanf("%d",&n);
printf("\n enter lower limit \n");
scanf("%f",&x0);
printf("\n enter upper limit\n");
scanf("%f",&xn);
h=(xn-x0)/n;
sum=find(x0)+find(xn);
for(i=1;i<=n-1;i++)
{
if(i%2==0)
sum=sum+2*find(x0+i*h);
else
sum=sum+4*find(x0+i*h);
}
sum=h/3.0*sum;
printf("\n interval=%f",sum);
getch();
}
float find(float x)
{
return(1.0/(1.0+x*x));
}

GFGC, Tumkur 45
Department of BCA

7.write a program to find the integral of a function using adaptive simpson method

#include<stdio.h>
#include<math.h>
#include<conio.h>
float find(float x);
void main()
{
float x0,xn,h,sum=0;
int i,n;
clrscr();
printf("\n trapezoidal rule\n");
printf("\n enter number of intervals \n");
scanf("%d",&n);
printf("\n enter lower limit \n");
scanf("%f",&x0);
printf("\n enter upper limit\n");
scanf("%f",&xn);
h=(xn-x0)/n;
sum=find(x0)+find(xn);
for(i=1;i<=n-1;i++)
{
if(i%3==0)
sum=sum+2*find(x0+i*h);
else
sum=sum+3*find(x0+i*h);
}
sum=3*h/8+sum;
printf("\n interval=%f",sum);
getch();
}
float find(float x)
{
return(1.0/(1.0+x*x));
}

GFGC, Tumkur 46
Department of BCA

8.write a program to find the value of a function at a point using lagrange’s


interpolation

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
float x[100],f[100],fx,sum=0,total1,total2;
int i,j,n;
clrscr();
printf("\n enter the values of n \n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the value at x[%d]",i);
scanf("%f",&x[i]);
}
for(i=0;i<n;i++)
{
printf("\n enter the value of f[%d]",i);
scanf("%f",&f[i]);
}
printf("\n enter the value of x",i);
scanf("%f",&fx);
for(i=0;i<n;i++)
{
total1=1;
total2=1;
for(j=0;j<n;j++)
{
if(j!=i)
{
total1=total1*(fx-x[j]);
total2=total2*(x[i]-x[j]);
}
}
sum=sum+total1/total2*f[i];
}
printf("\n lagranges interpolation at %f is %f \n",fx,sum);

getch();
}

GFGC, Tumkur 47
Department of BCA

GFGC, Tumkur 48

You might also like