0% found this document useful (0 votes)
16 views30 pages

Screenshot 2024-12-18 at 9.34.35 AM

The document contains practical programming exercises for CS-1 at Shree L R Tiwari Jr College of Commerce and Science, covering various C++ and HTML programs. It includes tasks such as swapping numbers, checking Armstrong numbers, creating classes for circles and complex numbers, implementing virtual functions, and writing HTML pages with specific features. Additionally, it features a VB script for collecting user information and calculating age based on date of birth.

Uploaded by

dhodip09
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)
16 views30 pages

Screenshot 2024-12-18 at 9.34.35 AM

The document contains practical programming exercises for CS-1 at Shree L R Tiwari Jr College of Commerce and Science, covering various C++ and HTML programs. It includes tasks such as swapping numbers, checking Armstrong numbers, creating classes for circles and complex numbers, implementing virtual functions, and writing HTML pages with specific features. Additionally, it features a VB script for collecting user information and calculating age based on date of birth.

Uploaded by

dhodip09
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/ 30

SHREE L R TIWARI JR COLLEGE OF COMMERCE AND SCIENCE

CS 1 PRACTICALS

PRACTICAL-1 INPUT:

// Aim : Swapping of two numbers


#include<iostream.h>
#include<conio.h>
void swap(int,int);
void main()
{
clrscr();
int a=1,b=2;
cout<<"\n a="<<a<<" "<<"b="<<b;
swap(a,b);
getch();
}
void swap (int a, int b)
{
int c;
c=a;
a=b;
b=c;
cout<<"\n a="<<a<<" "<<"b="<<b;
}

OR

PRACTICAL 1 INPUT :
#include<iostream.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
clrscr();
int a=1,b=2;
cout<<"\n a="<<a<<" "<<"b="<<b;
swap( &a, &b);
cout<<”\n a=”<<a<<” “<<”b= “<<b;
getch();
}
void swap (int *a, int *b)
{
int c;
c=*a;
*a=*b;
*b=*c;
}

PRACTICAL-1 OUTPUT:
PRACTICAL 2 INPUT:

//Aim:write a program to check a number is an armstrong or not.

#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int n,n1,d,s=0;
cout<<"\n Enter a number:";
cin>>n;
n1=n;
while(n>0)
{
d=n%10;
s=(s+pow(d,3));
n=n/10;
}
if(n1==s)
{
cout<<"\n It is an Armstrong number";
}
else
{
cout<<"\n It is not an armstrong number";
}
getch();
}
PRACTICAL 2 OUTPUT:
PRACTICAL 3 INPUT :
/*Aim : Write a program in C++ with the help of ratio class using member
functions like assign() function to initialise its members data, convert()
function to convert ratio into double(), invert() function to get inverse
of the ratio and print function to get the ratio and reciprocal*/

#include<iostream.h>
#include<conio.h>
class ratio
{
private:
float num,den,f,ref;
double n;

public:
void assign();
void convert();
void invert();
void print();
};
void ratio::assign()
{
cout<<"Enter the numerator of the ratio \n";
cin>>num;
cout<<"Enter the denominator of the ratio \n";
cin>>den;
f=(float)num/den;
}
void ratio::convert()
{
n=f;
}
void ratio::invert()
{
ref =1/f;
}
void ratio::print()
{
cout<<"Original ratio : "<<f<<endl;
cout<<"Reciprocal ratio :"<<ref<<endl;
}
void main()
{
clrscr();
ratio r1;
r1.assign();
r1.convert();
r1.invert();
r1.print();
getch();
}

PRACTICAL 3 OUTPUT:
PRACTICAL 4 INPUT:
/*program 4:
Aim : Implement a circle class in C++ each object will represent a circle
storing its radius and x and y coordinates and centre as float include a
default constructor, access function() and an area function()
and circumference function() the program must print the coordinates with
radius area and circumference of the circle */

#include<conio.h>
#include<iostream.h>
class circle
{
private:
float x,y,pi,rad;
public:
circle()
{
pi=3.14;
}
void accept()
{
cout<<"Enter x coordinate \n";
cin>>x;
cout<<"Enter y coordinate \n";
cin>>y;
cout<<"Enter the radius \n";
cin>>rad;
}
void display()
{
cout<<"\nX coordinate of the circle is = "<<x<<endl;
cout<<"Y coordinate of circle is = "<<y<<endl;
}
void area()
{
float ar= pi*rad*rad;
cout<<"\n Area of circle is = "<<ar;
}
void circum()
{
float cr= 2*pi*rad;
cout<< "\n Circumference is ="<<cr;
}

};
void main()
{
clrscr();
circle c;
c.accept();
c.display();
c.display();
c.area();
c.circum();
getch();
}

PRACTICAL 4 OUTPUT:
PRACTICAL 5 INPUT :
/*Program 5 aim: Write a program in C++ with a complex constructor to add the given two
complex .A=____ and B=____. the program should print the given complex no and their sum.*/

#include<iostream.h>
#include<conio.h>
class complex
{
private:
float x;//real
float y;//imaginaery
public:
complex(){}
complex(float real, float imag)
{
x=real;
y=imag;
}
void display()
{
cout<<x<<"+"<<y<<"i\n";
}
complex operator + (complex c)
{
complex temp;
temp.x=x+c.x;
temp.y=y+c.y;
return (temp);
}
};

void main()
{
clrscr();
complex c1,c2,c3;
c1=complex(3.2,2.5);
c2=complex(4.5,2.5);
c3=c1+c2;
cout<<"First object:";
c1.display();
cout<<"Second object:";
c2.display();
cout<<"\nResult:";
c3.display();
getch();
}

PRACTICAL 5 OUTPUT :
/* PRACTICAL 6 :
Aim : write program in c++ using a virtual function. The program must declare P to a pointer to
objetcs of the base class person first the program must assign p to a point at an instance y (name of
the student, eg"tom") of derived classes student. Define a print function in the same base class
function to print the name of the student.*/

#include<iostream.h>
#include<conio.h>
class person
{
public:
virtual void print()
{
cout<<"\nName of the person assigned through base object is BOB"<<endl;
}
};

class student:public person


{
public:
void print()
{
cout<<"\nName of the person assigned through the derived class is TOM"<<endl;
}
};
void main()
{
clrscr();
person *p,x;
student y ;
p=&x;
p->print();
p=&y;
p->print();
getch();
}

PROGRAM 6 OUTPUT:
PRACTICAL 7 INPUT:

aim: write a program in c++ that initialises a ratio class with no parameters as a default constructor.

the program must print the message "object is born" during initialising it.it should display the

msg "now x i alive" when the first member function ratio is called.the program display"object dies"

when class defination is end of its object when it reaches the end of its scope*/

#include<iostream.h>

#include <conio.h>

class ratio

public:

ratio()

cout<<"It was a rainy day"<<endl;

~ratio()

cout<<"but needs pratical Marks:)))"<<endl;


}

};

void main()

clrscr();

ratio x;

cout<<"i Don't wanna come to clg"<<endl;

getch();

Practical 7 output

PRACTICAL 7 OUTPUT :
Practical 8
Aim: Write a program to implement function overloading.

#include<iostream.h>
#include<conio.h>
class demo
{
int a,b;
public:
void show()
{
cout<<"\n Hello My Friend";
}
void show(int x,int y)
{
a=x;
b=y;
cout<<"\n a="<<a<<" "<<"b="<<b;
}
};
void main()
{
clrscr();
demo d;
d.show();
d.show(10,20);
getch();
}

OUTPUT:
EXP-9

Aim: Create a simple HTML page on the following topics:


College profile, Computer Manufacturer, or Software DevelopmentCompany
The page must consist of at least 3 paragraphs of text. The page must have an appropriate title,
background color or background image, andhyperlink to other pages. The paragraphs must have
text consisting ofdifferent colors and styles in terms of alignment and Font Size.

Program:
<HTML>
<head>
<title>
NMFC college
</title>
</head>
<body bgcolor="yellow">
<a href="www.google.co.in"> click here </a>
<p>
<font color="red" size="5">
Nirmala Memorial Foundation College of Commerce and Science, aflourishing institution
affiliated to the

University of Mumbai made its humble genesis in 2003, through theenlightened vision and
guidance of Mr.

Thakurbhai Desai.
</font>
</p>
<p>
<font color="blue" size="6">
The eight storied building includes modern air-conditioned officeblocks, well equipped
classrooms, well

planned corridors and 2 elevators.


Air-conditioned computer labs with 150 advanced machines andlicensed software
</font>
</p>
<p>
<font color="green" size="6">
Fully furnished library with large collection of books, periodicals andjournals (both Indian &
Foreign) and

spacious reading rooms.


</font>
</p>
</body>
</HTML>
OUTPUT:
EXP-10
Aim: Create a simple HTML page on the following topics:
College profile, Computer Manufacturer, or Software DevelopmentCompany
The page must consist of a scrolling marquee displaying an appropriateMessage. The page must
include a table with at last 5 rows and 3 columns having merged cells at least at 1 place. The
page must also display an image, an image such that when the same is viewed througha browser
and the mouse is placed (hovered) on the image, an appropriate text message should be
displayed. The image itself should also act as a hyperlink to another page.
Program:
<html>
<head>
<title>Apple</title>
</head>
<body>
<p>
<font size="6">
<marquee> Apple </marquee>
</font>
<p>
v
<center>
<font size="5" face="Times New Roman">
We are very happy to announce the brand new series of iPhonesreleasing this March. Getting to
know the true

sense of the new era of the technological world.


Visit us at <a href="www.apple.com"> www.apple.com</a>
</p>
<p>
<font size="5" >
Experience the amazing new-generation technology in your hands. Themost beautiful part about
this is the

ease of access of the iPhone. The new UI makes sure that you can usethis amazing technology to
its best. All

the new OS updates of IOS (iPhone Operating System) will be availableas soon as they are
developed.
</font>
</p>

<table border="5" cellspacing="3" cellpadding="2">


<tr align="center" >
<th>Product
<th>iPhone 6 Plus
<th>iPhone 6
<th>iPhone 5s
<th>iPhone 5c
</tr>

<tr align="center">
<th>Processor
<td colspan="2">A8 processor chip
<td>A7
<td>A6
</tr>

<tr align="center">
<th>Video Recording
<td>1080p HD 120 fps
<td>720p 60 fps
<td colspan="2">720p 30 fps
</tr>

<tr align="center">
<th>Graphic Processor
<td>M8 Motion Co-processor
<td colspan="2">M7
<td>M6
</tr>

<tr align="left">
<th>Additional Features:
<ul type="disc">
<li>Gyrometer
<li>Magnetic sensor
<li>Ambient Light Sensor
<td><br>
Yes<br>
Yes<br>
Yes<br>
<td><br>
Yes<br>
Yes<br>
No<br>
<td colspan="2">
<br>
Yes<br>
No<br>
No<br>
</tr>

<tr>
<th>Price
<td> <ul type="circle">
<li> 32 GB $550
<li> 64 GB $600
<li> 128 GB $650

<td colspan="2"> <ul type="circle">


<li> 16 GB $450
<li> 32 GB $500
<li> 64 GB $550

<td> <ul type="circle">


<li> 8 GB $400
<li> 16 GB $450
<li> 32 GB $500
<td>
</table>
<br>

<center>
<a href="www.apple.com">
<img src=Sunset.jpg size="50%" alt="Sunset" height="250">
</a>
</center>

</body>
</html>
OUTPUT:

EXP-11
Aim: Write a simple VB Script to do the following task whenexecuted:
Collect Information of Name, Date of Birth and Gender from anindividual.
Using Date of birth, calculate the age.
If page 15 16 years or less, then ask for Name or School, if age is morethan 16 years but less
than or equal to 22 years then ask for Name ofCollege and if age is grater then 22 years then ask
for name of the individual’s workplace.
Display a page based on all the above information that would display, the Individuals Name,
Date of Birth, Gender as well as the appropriateEntry made as mentioned in Point iii).
Program:
<html>
<body>
<script language="vbscript">dim
name,age,gender,sc
name=inputbox("Enter ur name") document.write"your name is
",name,"<br>" gender=inputbox("Enter gender")
document.write"your gender is ",gender,"<br>"
bdate=inputbox("enter your birth date like 16-May-1998")
age=datediff("YYYY",bdate,date())
document.write "your Age is ",age,"<br>"
if(age<16)then
sc=inputbox("enter your school name ") document.write"your school
name is",ucase(sc)else if(age<22)then
sc=inputbox("enter your college name") document.write"your
college name is ",ucase(sc)else
sc=inputbox("enter your workplace name") document.write"your
workplace name is",ucase(sc)end if
end if
</script>
</body>
</html>
OUTPUT:
SHREE L R TIWARI JR COLLEGE OF COMMERCE AND SCIENCE
SCIENCE DEPARTMENT
PRACTIICALS OF CS-1/SYJC/2023-2024

EXP-12
Aim: Write a program in Visual Basic that calculates area andselections of two shapes,
Circle and Rectangle.
Program:
Private Sub Command1_Click()
Frame1.Visible = True Frame2.Visible =
False
Text2.Text = Val(3.142 * Text1.Text * Text1.Text)End Sub
Private Sub Command2_Click()Text1.Text
= ""
Text2.Text = ""
Frame1.Visible = True
Frame2.Visible = TrueEnd
Sub
Private Sub Command3_Click()
Frame1.Visible = False Frame2.Visible =
True
Text5.Text = Text3.Text * Text4.TextEnd Sub
Private Sub Command4_Click()Text3.Text
=""
Text4.Text = " " Text5.Text
= "" Frame1.Visible = True
Frame2.Visible = TrueEnd
Sub
SHREE L R TIWARI JR COLLEGE OF COMMERCE AND SCIENCE
SCIENCE DEPARTMENT
PRACTIICALS OF CS-1/SYJC/2023-2024

OUTPUT:

You might also like