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

INDEX Practical List

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

INDEX Practical List

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

INDEX

Sr. Name o Program Page Remark


No No.
SECTION-A
1 Write a program in CPP, to print statement using cout () function.
2 Write a program in CPP, Print Number Entered by User.
3 Write a program in CPP, addition of two numbers.
4 Write a program in CPP, to find Size of int, float, double and char data
type.
5 Write a program in CPP, to declare global, static and local variable by
using of scope Resolution Operator.
6 Write a program in CPP, Swapping of two numbers using third
variable.
7 Write a program in CPP, to print ASCII value.
8 Write a program in CPP, to print ASCII value of all character.
9 Write a program in CPP, to perform arithmetic operation.
10 Write a program in CPP, to calculate simple interest.
11 Write a program in CPP, to check whether given number is even or
odd.
12 Write a program in CPP, to calculate total marks and percentage of a
student for five subjects.
13 Write a program in CPP, addition of two number using call by value.
14 Write a program in CPP, addition of three number using default
arguments.
15 Write a program in CPP, addition of two number suing inline
functions.
16 Write a program in CPP, to create class and objects.
17 Write a program in CPP, to addition of two numbers using class.
18 Write a program in CPP, to demonstrate class (member function
outside of class ) and objects.
19 Write a program in CPP, to demonstrate class (member function
inside of class ) and objects.
20 Write a program in CPP, to demonstrate nested member function.
21 Write a program in CPP, to demonstrate static data member.
22 Write a program in CPP, to demonstrate static member function
23 Write a program in CPP, to demonstrate friend function
24 Write a program in CPP, to demonstrate constructor
25 Write a program in CPP, to demonstrate parameterized constructure
26 Write a program in CPP, to demonstrate copy constructure
27 Write a program in CPP, to demonstrate destructure.
28 Write a program in CPP, to demonstrate single inheritance.
29 Write a program in CPP, to demonstrate multilevel inheritance.
30 Write a program in CPP, to demonstrate multiple inheritance.
31 Write a program in CPP, to demonstrate hybrid inheritance.
32 Write a program in CPP, to demonstrate this function.
33 Write a program in CPP, to demonstrate virtual function.
34 Write a program in CPP, to demonstrate Unary operator overloading.
35 Write a program in CPP, to demonstrate Binary operator overloading.
PRACTICAL NO 1
AIM :- Write a program in CPP, to print statement using cout () function.
Code:-
#include<iostream>
using namespace std;

int main(){
cout<<"Hello world";
return 0;
}

Output:-
PRACTICAL NO 2
AIM :- Write a program in CPP, Print Number Entered by User.
Code:-
#include<iostream>
using namespace std;
int main(){
int a;
cout<<"Enter any Number :";
cin>>a;
cout<<"You entered Number is "<<a<<endl;

return 0;
}

Output:-
PRACTICAL NO 3
AIM :- Write a program in CPP, addition of two numbers.
Code:-
#include<iostream>
using namespace std;

int main(){
int a,b,c;
cout<<"Enter Two Number :";
cin>>a>>b;
cout<<endl;
c=a+b;
cout<<"Addition of two Number is : "<<c<<endl;

return 0;
}

Output:-
PRACTICAL NO 4
AIM :- Write a program in CPP, to find Size of int, float, double and char data
type.
Code:-
#include<iostream>
using namespace std;
int main(){
int a;
float f;
double d;
char c;
cout<<"Size of int variable a is : "<<sizeof(a)<<endl;
cout<<"Size of Float variable a is : "<<sizeof(f)<<endl;
cout<<"Size of double variable a is : "<<sizeof(d)<<endl;
cout<<"Size of char variable a is : "<<sizeof(c)<<endl;
return 0;
}

Output:-
PRACTICAL NO 5
AIM :- Write a program in CPP, to declare global, static and local variable by
using of scope Resolution Operator.
Code:-
#include<iostream>
using namespace std;
int a=1000;
static int b;
int main(){
int a=500;
cout<<"Local Variable is a="<<a<<endl;
cout<<"Satatic variable is b = "<<b<<endl;
cout<<"Global Variable is a="<<::a<<endl;
return 0;
}
Output:-
PRACTICAL NO 6
AIM :- Write a program in CPP, Swapping of two numbers using third variable.
Code:-
#include<iostream>
using namespace std;

int main(){
int a,b,c;
cout<<"Enter the value of a : ";
cin>>a;
cout<<endl;
cout<<"Enter the value of b :";
cin>>b;cout<<endl;
cout<<"Before swap a= "<<a<<" and b= "<<b<<endl;
c=a;
a=b;
b=c;
cout<<"After swap a= "<<a<<" and b= "<<b<<endl;
return 0;
}
Output:-
PRACTICAL NO 7
AIM :- Write a program in CPP, to print ASCII value.
Code:-
#include<iostream>
using namespace std;
int main(){
char a;
cout<<"Enter a character ot print ascii value: ";
cin>>a;
cout<<"ASCII value of charecter : "<<a<<" is ="<<int(a)<<endl;
return 0;
}

Output:-
PRACTICAL NO 8
AIM :- Write a program in CPP, to print ASCII value of all character.
Code:-
#include<iostream>
using namespace std;

int main(){
int n;
for(n=0;n<=255;n++)
{
cout<<"ASCII code of "<<char(n)<<" "<<n<<endl;
}
return 0;
}
Output:-
PRACTICAL NO 9
AIM :- Write a program in CPP, to perform arithmetic operation.
Code:-
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cout<<"Enter the A and B values:";
cin>>a>>b;
c=a+b;
cout<<"The sum of "<<a<<" and "<<b<<" is= "<<c<<endl;
c=a-b;
cout<<"The Difference of "<<a<<" and "<<b<<" is= "<<c<<endl;
c=a*b;
cout<<"The Procuct of "<<a<<" and "<<b<<" is= "<<c<<endl;
c=a/b;
cout<<"The Division of "<<a<<" and "<<b<<" is= "<<c<<endl;
bool d=(a==b);
cout<<"is "<<a<<"equal to "<<b<<" ? = "<<d<<endl;
return 0;
}
Output:-
PRACTICAL NO 10
AIM :- Write a program in CPP, to calculate simple interest.
Code:-
#include<iostream>
using namespace std;
int main(){
int p,r,t;
float simple;
cout<<"Enter the Principal Value: ";
cin>>p;cout<<endl;
cout<<"Enter the Rete: ";
cin>>r;cout<<endl;
cout<<"Enter the time : ";
cin>>t;cout<<endl;
simple=p*r*t/100;
cout<<"Simple Intrest is : "<<simple<<endl;
return 0;
}

Output:-
PRACTICAL NO 11
AIM :- Write a program in CPP, to check whether given number is even or odd.
Code:-
#include<iostream>
using namespace std;
int main(){
int n;
cout<<"Enter a number to check even or odd = ";
cin>>n;
if(n%2==0)
{
cout<<"You entered is even number "<<endl;
}
else
{
cout<<"Given number is odd"<<endl;
}
return 0;
}
Output:-
PRACTICAL NO 12
AIM :- Write a program in CPP, to calculate total marks and percentage of a
student for five subjects.
Code:-
#include<iostream>
using namespace std;

int main(){
int cpp,mtcs,cn,na,ds,total;
float percentage;
cout<<"Enter The mark of following subjets(cpp,mtcs,cn,na,ds)= ";
cin>>cpp>>mtcs>>cn>>na>>ds;cout<<endl;
total=cpp+mtcs+cn+na+ds;
percentage=total/5;
cout<<"The total mark of 5 Subject is = "<<total<<endl;
cout<<"The Percentage of 5 Subject is ="<<percentage<<"%";
return 0;
}
Output:-
PRACTICAL NO 13
AIM :- Write a program in CPP, addition of two number using call by value.
Code:-
#include<iostream>
using namespace std;
void add(int a, int b)
{
int c=a+b;
cout<<"Addition = "<<c<<endl;
c=a-b;
cout<<"Subtraction= "<<c<<endl;
}
int main(){
cout<<"1) ";
add(100,200);
cout<<"2) ";
add(150,300);

return 0;
}
Output:-
PRACTICAL NO 14
AIM :- Write a program in CPP, addition of three number using default
arguments.
Code:-
#include<iostream>
using namespace std;
void add(int a, int b, int c=30)
{
int d=a+b+c;
cout<<"Addtion is = "<<d<<endl;
}
int main(){
add(10,20);
add(50,100,150);
return 0;
}

Output:-
PRACTICAL NO 15
AIM :- Write a program in CPP, addition of two number suing inline functions.
Code:-
#include<iostream>
using namespace std;
inline void add(int a, int b)
{
int c=a+b;
cout<<"addtion = "<<c<<endl;
}
int main(){
int a,b;
cout<<"Enter the value of a & b:";
cin>>a>>b;
add(a,b);
return 0;
}
Output:-
PRACTICAL NO 16
AIM :- Write a program in CPP, to create class and objects.
Code:-
#include<iostream>
using namespace std;
class student{
public:
int id;
int f;
};
int main(){
student s;
s.id=6047;
s.f=18500;
cout<<"Id= "<<s.id<<endl;
cout<<"F="<<s.f<<endl;
return 0;
}
Output:-
PRACTICAL NO 17
AIM :- Write a program in CPP, to addition of two numbers using class.
Code:-
#include<iostream>
using namespace std;
class add {
int a,b;
public:
void getdata()
{
cout<<"Enter the value of a and b :";
cin>>a>>b;
}
void addition()
{
cout<<"Addtion of two number is : "<<a+b<<endl;
}
};
int main(){
add ad;
ad.getdata();
ad.addition();
return 0;
}
Outptu:-
PRACTICAL NO 18
AIM :- Write a program in CPP, to demonstrate class (member function outside
of class ) and objects.
Code:-
#include<iostream>
using namespace std;
class add{
int a,b;
public:
void getdata();
void addition();
};
void add:: getdata() {
cout<<"Enter the value of a and b :";
cin>>a>>b; }
void add:: addition() {
cout<<"Addtion of two number is : "<<a+b<<endl; }
int main(){
add ad;
ad.getdata();
ad.addition();
return 0; }
Output:-
PRACTICAL NO 19
AIM :- Write a program in CPP, to demonstrate class (member function inside
of class ) and objects.
Code:-
#include<iostream>
using namespace std;
class student
{
int roll;
char name[20];
float fee;
public:
void bcs(){
cout<<"I am BCS student "<<endl;
}
void getdata()
{
cout<<"Enter Your Roll Number = ";
cin>>roll;cout<<endl;
cout<<"Enter Your Name =";
cin>>name;cout<<endl;
cout<<"Ente Your Fees= ";
cin>>fee;cout<<endl;
}
void display()
{
cout<<"Roll No.= "<<roll<<endl;
cout<<"Name = "<<name<<endl;
cout<<"Fees ="<<fee<<endl;
}
};
int main(){
student s;
s.getdata();
s.bcs();
s.display();

return 0;
}
Output:-
PRACTICAL NO 20
AIM :- Write a program in CPP, to demonstrate nested member function.
Code:-
#include<iostream>
using namespace std;
class number{
int a, b;
public:
void getdata();
void putdata(); };
void number::getdata() {
cout<<"Enter The value of a and b:";
cin>>a>>b;cout<<endl;
putdata(); }
void number::putdata() {
if(a>b) {
cout<<"A is Largest Number"; }
else{
cout<<"B is Largest Number"; }
}
int main(){
number n;
n.getdata();
return 0; }
Output:-
PRACTICAL NO 21
AIM :- Write a program in CPP, to demonstrate static data member.
Code:-
#include<iostream>
using namespace std;
class emplouee{
int id;
static int count;
public:
void setdata() {
cout<<"Enter Employee Id = ";
cin>>id;
count++; }
void gettdata()
{
cout<<"The id of this employee is = "<<id<<endl;
cout<<"This is employ number = "<<count<<endl; }
};
int emplouee::count;
int main(){
emplouee e,a;
e.setdata(); Output:-
e.gettdata();
a.setdata();
a.gettdata();
return 0; }
PRACTICAL NO 22
AIM :- Write a program in CPP, to demonstrate static member function.
Code:-
#include <iostream>
using namespace std;
class Note
{
static int num;
public:
static int func ()
{
return num;
}
};
int Note :: num = 5;
int main ()
{
cout << " The value of the num is: " << Note:: func () << endl;
return 0;
}
Output:-
PRACTICAL NO 23
AIM :- Write a program in CPP, to demonstrate friend function
Code:-
#include <iostream>
using namespace std;
class box
{
private:
int length;
public:
box(): length(0) { }
friend int printlength(box);
};
int printlength(box b)
{
b.length= 10;
return b.length;
}
int main()
{
box b;
cout<<"Length of box: "<< printlength(b)<<endl;
return 0;
}
Output:-
PRACTICAL NO 24
AIM :- Write a program in CPP, to demonstrate constructor
Code:-
#include<iostream>
using namespace std;
class constructor {
int a, b;
public:
constructor();
void printvalue() {
cout<<"The value is "<<a<<" + "<<b<<endl; }
void add() {
cout<<"addtion = "<<a+b; }
};
constructor::constructor() {
a=10;
b=20; }
int main(){
constructor c1,c2;
c1.printvalue();
c1.add();
return 0;
}
Output:-
PRACTICAL NO 25
AIM :- Write a program in CPP, to demonstrate parameterized constructure
Code:-
#include<iostream>
using namespace std;
class complex{
int a,b;
public:
complex(int ,int);
void printvalue()
{
cout<<"The number is "<<a<<" + "<<b<<endl;
}
void add()
{
cout<<"addtion is = "<<a+b;
}
};
complex::complex(int x, int y)
{
a=x;
b=y;
}
int main(){
int a,b;
cout<<"Ente the value of a and b:";
cin>>a>>b;cout<<endl;
complex m(a,b);
m.printvalue();
m.add();
// b.printvalue();
return 0;
}
Output:-
PRACTICAL NO 26
AIM :- Write a program in CPP, to demonstrate copy constructure
Code:-
#include<iostream>
using namespace std;
class num{
int a;
public:
num(int x)
{
a=x;
}
void display()
{
cout<<"The value of a is :"<<a<<endl;
}
num(num &obj) {
a=obj.a; }
};
int main(){
num a1(10);
a1.display();
num n=a1; Output:-
n.display();

return 0;
}
PRACTICAL NO 27
AIM :- Write a program in CPP, to demonstrate destructure.
Code:-

You might also like