Professional Documents
Culture Documents
Class :- 12th
write a program in C++ that first initialises an array of given 10 real numbers. The
program must Sort numbers in scending order using Bubble-Sort method. It should print
the given list of numbers as well as the sorted list. */
#include<iostream.h>
#include<conio.h>
void main()
int a[10],i,j,t;
clrscr();
for(i=0;i<10;i++)
cin>>a[i];
cout<<"******OUTPUT******"<<endl;
for(i=0;i<10;i++)
cout<<" "<<a[i];
for(i=0;i<9;i++)
for(j=0;j<10-i;j++)
if(a[i]>a[j+1])
{
t=a[j]’
a[j]=a[j+1];
a[j+1=t;
cout<<endl;
for(i=0;i<10;i++)
cout<<" "<<<a[i];
getch();
Output:-
*******OUTPUT*******
Class :- 12th
write a program in C++ that first initialises an array of given 10 real numbers. The
program must Sort numbers in descending order using Bubble-Sort method. It should
print the given list of numbers as well as the sorted list. /
#include<iostream.h>
#include<conio.h>
void main()
int a[10],i,j,t;
clrscr();
for(i=0;i<10;i++)
cin>>a[i];
cout<<"******OUTPUT******"<<endl;
for(i=0;i<10;i++)
cout<<" "<<a[i];
for(i=0;i<9;i++)
for(i=0;ij<10-i;j++)
if(a[j]<aa[j+]
t-alil:
a[j]=a[j+1];
a[j+1]=t;
cout<<endl;
for(i=0;i<10;i++)
cout<<" "<<a[i];
getch();
Output:
******OUTPUT******
Class :- 12th
/ Write a program in C++ that exchanges data (passing by refrence) using swap function
to.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
clrscr();
int a, b;
cin>>>>>b;
cout<<"\n\t\tA= "<<<<"and";
cout<<"B"<<b;
geten(); }
void swap (int *a, int b) //function definition
int t;
ta; a=b; b
Output:-
A=45and B= 23
Experiment . 4
Name :-Spandan Mendhe
Class :- 12th
/a) Write a program in C++ that first initialises an array of given 10 sorted real numbers.
The program must verify whether a given element belongs this array or not, using
Binary Search technique. The element (to be searched) is to be entered at the time of
execution. if the number is found, the program should print its position in the array
otherwise it should print "The number not found." "/
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
for(i=0; i<10;1++)
{ cin>>arr[i]; }
cin>>num;
first = 0;
last 9;
while(first last)
{
if(arr[middlel<num)
first middle+1; =
else if(arr[middle]==num)
break;
}
else
last = middle-1;
middle = (first+last)/2;
}
if(first>last)
getch();
return 0;
}
/* Output one:
Output two :-
Class :- 12th
a) Write a program in C++ that first intialises an array of given numbers (short/ float/
double). The program must add these numbers by traversing this array with a pointer.
The output should print the starting address of the array with the size of the number (in
bytes) to whit it points. The program must also print the sum and pointer address with
the addition of every number as well as the ending address. */
#include<iostream.h>
#include<conio.h>
void main()
{ float a[5]={1,2,3,4,5),sum,y,*p,x=0;
int i;
clrscr();
for(i=0;j<5;i++)
{ cout<<"\t"<<a[i]; }
p=&a[0];
cout<<"\n starting address of element :- "<<p<<"\n";
sum=0;
for(i=0;i<5;i++)
{ sum=sum+a[i];
p=∑
fori-05
{ p=∑
y=sizeof(*p);
getch(); }
/* Output:-
size in bytes 20 */
Experiment . 6
Class :- 12th
Write function in C++ to input the given string (including space) and reverse it using a
function which locate the end of a string and swaps the frist character witth the last
character,second character with the second last character and so on."/
#include <iostream.h>
#include <conio.h>
#include <string.h>
int main()
18/44
{ clrscr();
char a[80];
gets(a);
char temp
for(i=0;mid; i++)
{ temp = a[i];
a[lent - 1] = temp;
lent--;
puts(a);
return 0;
/*Output;
Class :- 12th
/*a) write a program in Cwith a ratio class using member function like assign function to
initialize its member data, integer numerator and denominator. Convert/function to
convert the ratio into double, invert function to get the inverse of the ratio and print
function to print the ratio and its reciprocal. */
#include<iostream.h>
#include<conio.h> #include<stdio.h>
class ratio
int a:
int b:
double rat.iny:
public:
{ a=x: b=y: }
void convert
{ rat (double)a/b: }:
void invert()
{ iny I/rat: }
void print()
{
};
void main
{
int x:y:
ratio A:
int
clrscr():
cin>>>>y:
Aassignts. A.convert():
A.invert():
A print()
getch():
return(0)
}
OUTPUT
Enter two integer numbers 25 5 Given Numbers are25and5
Ratio and Inverse of ratio are5and0.2
Experiment . 8
Class :- 12th
/* implement a circle class in c++. Each object of this class will represent a circle storing
its radius and x y coordinates of its centers as float. Include a default constructor,
access function, an area function and a circumference function, the program must print
the coordinates with radius,
#include<iostream.h>
#include<conio.h>
class circle
{
float x, y, r
void access()
void area()
void circumference()
public:
circle()
cin>>>>>>>y; }
void output()
void circle::output()
{ access(); area();circumference() }
clrscr();
circle A;
A.output();
getch();
return(0);
Class :- 12th
/* Write a program in C++ with a complex constructor to add the given two complex
number A and B The program should print the given complex numbers and their sum. "/
#include<iostream.h>
#include<conio.h>
class complex
{` double real,imag.
public:
complex(){:}
complex(double x,double y)
{ real=x; imag-y. }
complex sum(complex.complex);
void output()
{
cout<<"\n\n\tThe Complex Number is "<<real<<"+"<<imag<<"";
}
};
complex complex::sum(complex x,complex y)
{ complex.z;
z.real-x.real+y.real;
z.imagex.imag+y.imag
return(z); }
main()
int x,y;
clrscr();
cin>>>>>y;
complex A(x,y):
cin>>>>>y;
complex B(x,y);
complex C-A.sum(A,B);
A.output();
B.output();
C.output();
getch();
return(0);
Class :- 12th
*Two classes Polar and Rectangle in C to represent points in the polar and rectangular
systems, conversion) routines from one system to the other."/
#include<iostream.h>
#include<math.h>
#include<stdio.h>
#include<conio.h>
class polarClass
{
public
float r,th,
{ r=a th=b; }
void show()
};
public:
{ xp.rcos(p.th).
Y p.r*sin(p.th), }
void show()
};
int main()
{ clrscr();
cin>>rad>>thet;
polarClass p[rad,thet);
p.show();
rectangular Class r;
r=p;
r show();
getch(),
return 0;
/*Output:
free the the value radius and theta 35.6) In polar form
In Rectangular form:
x-2.326697and y-1.8938 */
Experiment . 11
Class :- 12th
/*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 total
marks. The program must print the roll numbers, individual marks obtained in two
subjects, sports and total marks."/
#include<iostream.h>
#include<conio.h>
class student
protected:
public:
(roll_number=a; }
(cout<<"\n\tRoll No:"<<roll_number<<endl;)
};
class test:public student
protected:
public:
float prt1.pr12,spr
cin>>roin;
cin>>prt1>>prt2;
cin>>spr.
cout<<endl<<endl;
result R
R.get_number(roln):
R.get marks(prt1,p12),
Rget score(sor);
R.display:
getch().
return(0).
/*Output
Roll No:9
Marks obtained
Subject1-98
Subject2 98
Sports Score 95
Total 291
cout<<"\n\t\t\tSubject2= "<<part2;
}
};
class sports
protected:
float score:
public:
{score=S; }
};
protected:
float total;
public:
{
total part1+part2+score;
put_number();
put_marks();
put_score();
cout<<"\n\n\t\t\tTotal = "<<total; }
int main()
Experiment . 12
Class :- 12th
/Write a program in using sus function. The program must declare p to be a pointer to
object of the base class person: First the program must sign p to point an instance x
(the name of the person cg Bob) of class person. The program must then assign p to
point at an instance y (name of student ep. Tom) of the derived class student. a print
function in the base class such that it invokes the same base class function to print the
name of the person by default. The call for the same should envoke the derived class
function to print the name of the student."/
#include<iostream.h>
#include<conio.h>
class x
(char name[10]:
public: x()
class y public x
{ char name[10];
void main()
{ clrscr();
xA; yB;
x*p; p-&A;
p>print();p&B:cout<<"\n
p>print();
getch(), }
Class :- 12th
a)Write a program in C to read the name of the 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 corresponding capital in the output b)Enter the program and
verify proper execution of the same on the computer c)Obtain the hardcopy of the
program listing as well as output.
#include fstream.h>
#include<conio.h>
void main()
clrscr();
ofstream fout:
fout.close():
fin.opent "country"
while(fin.cof) ()
fin.getline(line.n):
coutline<<endl
fin.close
fin.openCapital”);
whiletin.cof) 0)
fin.getline(line.ny):
cout<<line<endl
fin.close():
getch();
OUTPUT
United Kingdom
South Korea
Washington
London
Seoul
Experiment . 14
Class :- 12th
a)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
initalisation. It should display the message "NOW X IS ALIVE", when the first member
function Ratio x is called. The program must misplay "OBJECT DIES" when the class
destructor is called for the object when it reaches the end of its scope
#include<iostream.h> #include<conio.h>
class ratio
public: ratio()
ratio(int)
~ratio()
cout<<"In OBJECT IS DIES\n";
void main()
clrscr(); fatio r.
r=ratio(80);
getch();
Output:-
OBJECT IS BORN
NOW X IS ALIVE
OBJECT IS DIES