Program 1:-
Write a function in C++ that exchanges data (passing by references )using swap function to interchange the given two numbers.*/
#
include<iostream.h>
#
include<conio.h>
void swap(float &x ,float &y)
{
float
t=x;
x=y;
y=t;
}
void
main()
{
void
swap(float &,float &);
float
a,b;
cin>>a>>b;
cout<<”
a := ” << a <<” b := ”<< b<< endl;
swap(a,b);
cout<<
”a:= ”<< a<< ” b := ”<< b<<
endl;
}
Output:
2
4
a :=
2 b:= 4
a:= 4 b:
=2
Program 2:-
Write a program in C++ with a ratio class using member functions like assign () function to initialize its member data integer numerator and denominator ,convert() function to convert the ratio into double, invert() to get the inverse of the ratio and print() function to print the ratio and its reciprocal.*/
Write a program in C++ with a ratio class using member functions like assign () function to initialize its member data integer numerator and denominator ,convert() function to convert the ratio into double, invert() to get the inverse of the ratio and print() function to print the ratio and its reciprocal.*/
#include<iostream.h>
#include<conio.h>
class
ratio
{ public:
void assign(int, int); double convert();
void invert(); void print();
private:
int num,den; };
void
main()
{ratio
x;
x.assign(22,7);
cout<<”x=”;
x.print();
cout<<”=”<<x.convert()<<”\n”;
x.invert();
cout<<”1/x=”;
x.print();
cout<<”\n”;
}
void
ratio::assign(int numerator,int denominator)
{
num=numerator; den=denominator;
}
double
ratio :: convert()
{
return double((num)/den); }
void
ratio :: invert()
{ int
temp=num;
num=den;
den=temp;
}
void
ratio::print()
{
cout<<num<<”/”<<den;}
Output:
X=22/7=3
1/x=7/22
Assignment No:-3
Program 3:- Implement a circle class in C++ .Each object of this will
represent a circle ,storing its radius and X and Y co-ordinates of
its centers as floats .Include a default constructor ,access
functions ,an area() function and circumference () function .The
program must print the co-ordinates with radius ,area and
circumference of the circle .
#
include<iostream.h>
#include<conio.h>
class
circle
{ private
:
float x,y,r;
float area1,circum;
public:
void assign(); void area();
void circumf(); void printc();
};
void
circle ::assign()
{ cout<<”type
the x & y co-ordinatesof the center \n”;
cin>>x>>y;
cout<<”type the radius :- “;
cin>>r; }
void
circle :: area()
{ area1=3.14*r*r; }
void
circle :: circumf()
{ circum=2*3.14*r; }
void
circle ::printc()
{ cout<<”X,Y
co-ordinates =”<<x<<”\t”<<y<<endl;
cout<<”the radius is =”<<r<<endl;
cout<<”the area is =”<<area1<<endl;
cout<<”the circumference is =”<<circum<<endl; }
void
main ()
{ circle
c1;
c1.assign();
c1.area();
c1.circumf();
c1.printc();
}
Output
For Circle area:
type
the x & y co-ordinates of the center 2 1
type
the radius :- 2
X,Y
co-ordinates =2 1
the
radius is 2
the
area is12.56
the
circumference is 12.56
Assignment No:-4
Program 4:- Write a program in C++ that initializes a Ratio class with no
parameters, as a default constructor the program must print the
message “OBJECT IS BORN “ during initialization .It should
display the message “NOW X IS ALIVE “, When the first member
function Ratio x is called.The program must display “OBJECT DIES
“when the class destructor is called for the object when it reached
the end of its scope.
#include<iostream.h>
#include<conio.h>
class
ratio
{
public:
ratio()
{
cout<<”object
is born \n”;
}
~ratio()
{
cout<<
“object dies \n”;
}
private:
int
num,den;
};
void
main ()
{
ratio
x;
cout<<”
now x is alive \n”;
cout<<”at
the end of program \n”;
}
Output:
Object
is born
now
x is alive;
at
the end of program
Assignment No:-5
Write
a program in C++ with a complex constructor to add the given two
complex numbers.The program should print the given complex number and
their sum.
#include<iostream
.h>
#include<conio.h>
class
complex
{ float
x,y;
public:
complex(){ }
complex(float real,float img)
{x=real; y=img; }
complex operator+(complex);
void display(void);
};
complex
complex :: operator +(complex c)
{
complex
t;
t.x=x+c.x;
t.y=y+c.y;
return(t);
};
void
complex:;display (void)
{
cout<<x<<”+j”<<y<<”\n; }
void
main()
{complex
c1,c2,c3;
c1=complex(2.5,3.5);
c2=complex(1.6,2.7);
c3=c1+c2;
cout<<”c1=”;
c1.display();
cout<<”c2=”;
c2.display();
cout<<”c3=”;
c3.display();
}
Output
:
C1=2.5
+j3.5
C2=1.6+j2.7
C3=4.1+j6.2
Assignment No:-6
Define
two classes Polar and Rectangular in c++ to represent points in the
polar and rectangular systems. Use conversion routines from one
system to the other.
#include<iostream.h>
#include<math.h>
#include<conio.h>
class
polar
{
private:
double
radius;
double
angle;
public:
polar()
{
radius=0.0;
angle=0.0;
}
polar (double r, double a)
{
radius=
r;
angle=a;
}
void
display()
{
cout<<"Radius="<<radius<<"\t"<<"Angle="<<angle;
}
double
getr()
{
return
radius;
}
double
geta()
{
return
angle;
}
};
class
rec
{
private:
double
xcord;
double
ycord;
public:
rec()
{
xcord=0.0;
ycord=0.0;
}
rec(double
x,double y)
{
xcord=x;
ycord=y;
}
rec(polar p)
{
float
r=p.getr();
float
a=p.geta();
xcord=r*cos(a);
ycord=r*sin(a);
}
void
display()
{
cout<<"X-coordinate="<<xcord<<"\n"<<"Y-coordinate="<<ycord;
}
};
void
main()
{
rec
record;
polar
polcord(10.0,0.785398);;
record=polcord;
cout<<"Polar
coordinates:\n";
polcord.display();
cout<<"\nRectangular
coordinates:";
record.display();
}
Output is:
Polar
coordinates
Radius
=10 Angle=0.785398
Rectangular
coordinates
X-coordinate=7.07107
Y-coordinate=7.07107
Assignment No:-7
Program:- Write a program in c++ to implement the following class
hierarchy;
Class student to obtain Roll Number ,Class Test to obtain marks
scored in two different subjects,Class sports to obtain weightage
(marks) in sports and Class Result to calculate the marks . The
program must print the roll number ,individual marks obtained in two
subject, sports and total marks.
Student
Test
Sports
Result
#include <iostream.h>
#include<conio.h>
class students
{
int roll_no;
public:
void get_no(int a)
{
roll_no=a;
}void put_no(void)
{ cout<<”roll_no: 0”<<roll_no;
}
};
class test :public student
{public:
float s1,s2;
public:
void get_marks(float x, float y)
{
s1=x;s2=y;
}
void put_marks(void)
{cout<<”marks obtained :\ns1=”<<s1<<”\ns2=”<<s2;
}
};
class sports
{
public:
int score;
void get_score(int x)
{
score=x;
}
void put_score(void)
{cout<<”sports marks :”<<score;
}
};
class result : public test,public sports
{
float tot;
public:
void display(void)
{tot=s1+s2+score;
put_no();
put_marks();
put_score();
cout<<”total score =”<<tot;
};
void main(){
{
result st1;
st1.get_no(101);
st1.get_marks(39,65);
st1.get_score(29);
st1.display();
}
Output is:
roll_no:0101 marks obtained :
s1=39
s2=65 sports marks :29 total score=133
Assignment No: 8
Write
a program in c++ to read the name of a country from one text file and
name of its corresponding capital city from another text file. The
program must display the country name and indicate its corresponding
capital in the output.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void
main()
{char
line[80]; ofstream fout;
fout.open("country");
fout<<"United
states of America\n";
fout<<"United
Kingdom\n";
fout<<"South
Korea\n";
fout<<"India\n";
fout<<"Pakistan\n"; fout.close();
fout.open("capital");
fout<<"Washington\n";
fout<<"London\n";
fout<<"Seoul\n";
fout<<"New
Delhi\n";
fout<<"Islamabad\n"; fout.close();
ifstream
fin1,fin2;
fin1.open("country"); fin2.open("capital");
cout<<"Contry\t\t\t\t
Capital\n";
for(int
i=1;i<=10;i++)
{if(fin1.eof()!=0)
{cout<<"Exit
from country\n";
exit(1);}
fin1.getline(line,80);
cout<<line<<"\t";
if(fin2.eof()!=0)
{cout<<"Exit
from Capital\n";
exit(1);}
fin2.getline(line,80);
cout<<line<<"\n";}
}
Output
is:
Country Capital
United
states of America Washington
United Kingdom
London
South
Korea Seoul
India
New Delhi
Pakistan Islamabad
Write a program in Visual Basic that create a simple form, which ask a the user to enter name of the student, marks obtained in subject 1, subject 2 and subject 3. As the name and marks obtained in the various subjects are entered, the pointer should automatically point at the next field to be entered.At the end it should move to the command butoon.When the command button is clicked, the program must save the record.
Private
Sub Command1_Click()
Dim
savefile As Long
savefile
= FreeFile
Open
"D:\sub123.txt" For Output eAs #savefile
Print
#savefile, Label1.Caption + Label2.Caption + Label3.Caption +
Label4.Caption + Label5.Caption + Text1.Text + Text2.Text +
Text3.Text + text4text,
Close
#savefile
End
Sub
Private
Sub Text1_KeyPress(KeyAscii As Integer)
If
KeyAscii = 13 Then ' The ENTER key.
SendKeys
"{tab}" ' Set the focus to the next control.
KeyAscii
= 0 ' Ignore this key.
End
If
End
Sub
Private
Sub Text2_KeyPress(KeyAscii As Integer)
If
KeyAscii = 13 Then ' The ENTER key.
SendKeys
"{tab}" ' Set the focus to the next control.
KeyAscii
= 0 ' Ignore this key.
End
If
End
Sub
Private
Sub Text3_KeyPress(KeyAscii As Integer)
If
KeyAscii = 13 Then ' The ENTER key.
SendKeys
"{tab}" ' Set the focus to the next control.
KeyAscii
= 0 ' Ignore this key.
End
If
End
Sub
Private
Sub Text4_KeyPress(KeyAscii As Integer)
If
KeyAscii = 13 Then ' The ENTER key.
SendKeys
"{tab}" ' Set the focus to the next control.
KeyAscii
= 0 ' Ignore this key.
End
If
End
Sub
Write
a program in VB to create a text editor (Notepad),when has the
following option.
- FileEditNewOpenSaveCloseCutCopyPaste
Dim
s As String
Private
Sub mnucopy_Click()
'MsgBox
"please select the text"
s =
RichTextBox1.SelText
RichTextBox1.SelText
= s
End
Sub
Private
Sub mnucut_Click()
s =
RichTextBox1.SelText
RichTextBox1.SelText
= ""
End
Sub
Private
Sub mnuexit_Click()
End
End
Sub
Private
Sub mnufont_Click()
CommonDialog1.ShowFont
End
Sub
Private
Sub mnuopen_Click()
CommonDialog1.ShowOpen
End
Sub
Private
Sub mnupaste_Click()
RichTextBox1.SelText
= s
End
Sub
Private
Sub mnuprint_Click()
CommonDialog1.ShowPrinter
End
Sub
Private
Sub mnusave_Click()
CommonDialog1.ShowSave
End
Sub
Private
Sub mnusaveas_Click()
CommonDialog1.ShowSave
End
Sub
Assignment
No: 11
Write
a program in visual basic that accepts name of the person, date of
birth and telephone number as data during execution. The program must
check the validity of contents and must display an appropriate
corrective suggestion if data is incorrectly entered
Write a program in visual basic that accepts name of the person, date of birth and telephone number as data during execution. The program must check the validity of contents and must display an appropriate corrective suggestion if data is incorrectly entered
Private
Sub Command1_Click()
If
IsDate(Text2.Text) = False Then
MsgBox
"Wrong date"
End
If
If
IsNumeric(Text3.Text) = False Then
MsgBox
"Wrong telephone No."
End
If
Dim
l As Integer
l =
Len(Text3.Text)
If l
< 10 Then
MsgBox
"Please enter 10 digit number"
End
If
If l
> 10 Then
MsgBox
"Please enter 10 digit number"
End
If
End
Sub
Assignment No:- 12 Student Name Rollno
Write a program in VB to find the sum of first 100 numbers entered
using DO loop
Dim a ,sum As Integer
sum = 0
a= 1
Do
Sum =sum + a
a = a+1
Loop While a<=100
MsgBox “The sum of first 100 numbers is “,&sum ”,
vbInformation
End
End Sub
Assignment No: 13
Create
a graphic editor using visual basic, which has the following
functions: change color, change line width, fill color, change border
color etc.
Private
Sub Command4_Click()
Shape1.Shape
= 3
End
Sub
Private
Sub Command5_Click()
Dim
a, b, c As Integer
a =
Val(Text1.Text)
b =
Val(Text2.Text)
c =
a * b
MsgBox
"Area of rectangle is" & c
End
Sub
Private
Sub Form_Load()
End
Sub
Private
Sub HScroll1_Change()
Shape1.BorderWidth
= HScroll1.Value
Shape1.BorderColor
= RGB(Rnd * 255, Rnd * 255, Rnd * 255)
End
Sub
Assignment No:-14
Create simple HTML pages on any of the following topics
College
profile, Computer Manufacturer, or Software Development Company.The
page must of at least 3 paragraphs of text. The page must hava an
appropriate title ,background color or
background
image, and hyperlinks to other pages.The paragraphs must have text
consisting of different colors and style in terms of alignment and
Font size.
<html><head>
<h1
align="center">BINARY SOLUTION</h1></head>
<body
bgcolor="skyblue>
<p><font
size=5 color="red">
<b>BINARY
solution</b> is a software devlopment company.It focuses on
website devlopment.
It
provide software solutions using web and dot net technology.It's head
office is at
pune
.the company have offices all over India and USA</font></p>
<p><font
size =+2 color="green"><i>It is company which
provides creative atmosphere for employees. It also provides
different facilities to their employee. Employee can work and develop
their own ideas.Thus they can convert their virtual ideas into
reality.</i></font></p>
Further
you can contact at following address:
<pre>
Binary
Solutions,
25,Anand
Society,
Sinhagad
Road,
Pune.
Phone:24359871
Email:Binary_s@rediffmail.com
</pre>
<A
HREF="c:\clients.html">
<align="right"><h2>CLIENTS</h2></align></A>
</body>
</html>
Link
page :Clients.html
<html>
<head>
<h1
align="center">BINARY SOLUTION</h1>
</head>
<body
bgcolor="skyblue">
<h1>Clients</h1>
<ol>
<li>Borgaon
Sugar Factory</li> <li> Indo Instruments</li>
<li>Nehru
English School</li> <li>ABC Publications</li>
<li>Indian
Insurance Company</li> <li>Toyato Limited</li>
</ol></body></html>
Assignment No:-15 Student Name Rollno
Create
simple HTML pages on any of the following topics
College
profile,Computer Manufacturer,or Software Development Company.The
page must of at least 3 paragraphs of text. The page must hava an
appropriate title,background color or
background
image,and hyperlinks to other pages.The paragraphs must have text
consisting of different colors and style in terms of alignment and
Font size.
<HTML>
<HEAD>
<H1
ALIGN="CENTER">S.J.V</H1>
</HEAD>
<BODY
BGCOLOR="SILVER">
<h1>COLLEGE
PROFILE</H1>
<P>
<FONT FACE="Arial Rounded MT Bold" SIZE=20
ALIGN="right" COLOR="ORANGE">
<B>INSTRCTION</B>
IN OUR COLLEGE THERE ARE TWO MEDIUMS ENGLISH AND MARATHI </FONT>
</P>
<P>
<FONT FACE="Arial Rounded MT Bold" SIZE=10
ALIGN="RIGHT" COLOR="WHITE">
<I>IN
COMPUTER SCIENCE WE HAVE A LAB TO PRACTICALS FOR STUDENTS AND ALSO
FOR IT STUDENTS</I> </P>
<P>
<FONT FACE="Arial Rounded MT Bold" SIZE=10
COLOR="GREEN" ALIGN="RIGHT">
<U>IN
OUR COLLEGE WE HAVE BIG GROUND TO PLAY</U>
<A
HREF="C:\COURSE.HTML">
<ALIGN="CENTER"><H2>COURSE</H2></ALIGN></A>
<A
HREF="C:\PuneUniversity.BMP">
<ALIGN="CENTER"><H2>VIEW
UNIVERSITY PHOTO</H2></ALIGN></A>
</BODY></HTML>
Link
page : COURSE.html
<HTML><HEAD>
<H1
ALIGN="CENTER">COURSES AVALIABLE IN COLLEGE</H1></HEAD>
<table
border="5">
<BODY
BGCOLOR="SILVER">
<H1>COURSES</H1>
<OL>
<LI>COMPUTER
SCIENCE</LI>
<LI>INFORMATION
TECNOLOGY (IT) </LI>
<LI>BCS</LI>
<LI>BCA</LI>
</OL>
</BODY>
</HTML>