Algorithm Flowchart Program Cpp
Algorithm Flowchart Program Cpp
The
program must sort numbers in ascending order using BUBBLE-SORT method. It
should print given list of numbers as well as the sorted list.
Algorithm for sort the given list in ascending order
Step1 : START
Step2 : Declare array variable A[7], and two loop variable I, J
and one variable TEMP as integer
Step3 : Assign values 2,3,4,10, 9, 7,8,6,5,1 to A[10] means A[10]={ 2,3,4,10, 9, 7,8,6,5,1}
Step4 : Take a loop and initialize initial value one to I means I := 0
Step5 : Check condition I < 10 then Step6 else Step8
Step6 : Display A[I]
Step7 : Increase I by one and return to Step5
Step8 : Take a loop and initialize initial value one to I means I := 0
Step9 : Check condition I < 10-1 then Step10 else Step18
Step10 : Take a loop and initialize initial value zero to J means J := 0
Step11 : Check condition J < 10-i-1 then Step11 else Step17
Step12 : Check condition A[J] > A[J+1] then Step13 else Step16
Step13 : Assign value A[J] to TEMP means TEMP := A[J]
Step14 : Assign value A[J+1] to A[J] means A[J] := A[J+1]
Step15 : Assign value TEMP to A[J+1] means A[J+1] := TEMP
Step16 : increase J by one and return to Step11
Step17 : increase I by one and return to Step9
Step18 : Take a loop and initialize initial value one to I means I := 0
Step19 : Check condition I < 10 then Step20 else Step22
Step20 : Display A[I]
Step21 : Increase I by one and return to Step19
Step22 : END
// PROGRAM FOR BUUBLE SORT ASCENDING ORDER
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10]={ 2, 3, 4, 10, 9, 7, 8, 6, 5, 1},t;
int i,j;
clrscr();
cout<< “Output”;
cout<<“Before sorting array elements are “;
for(i=0;i<10;i++)
{
cout<<a[i]<<” \t “;
}
for(i=0; i<10-1; i++)
{
for(j=0; j<10-i-1; j++)
{
if(a[j] >a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<“After sorting array elements are “;
for(i=0;i<10;i++)
{
cout<<a[i]<<” \t“;
}
getch();
}
Output
Before sorting array elements are
2 3 4 10 9 7 8 6 5 1
After sorting array elements are
1 2 3 4 5 6 7 8 9 10
Write a program in C++ that first initializes an array off given 10 real numbers. The program
must sort numbers in descending order using BUBBLE-SORT method. It should print given list
of numbers as well as the sorted list.
Algorithm for sort the given list in descending order
Step1 : START
Step2 : Declare array variable A[7], and two loop variable I, J
and one variable TEMP as integer
Step3 : Assign values 2,3,4,10, 9, 7,8,6,5,1 to A[10] means A[10]={ 2,3,4,10, 9, 7,8,6,5,1}
Step4 : Take a loop and initialize initial value one to I means I := 0
Step5 : Check condition I < 10 then Step6 else Step8
Step6 : Display A[I]
Step7 : Increase I by one and return to Step5
Step8 : Take a loop and initialize initial value one to I means I := 0
Step9 : Check condition I < 10-1 then Step10 else Step18
Step10 : Take a loop and initialize initial value zero to J means J := 0
Step11 : Check condition J < 10-i-1 then Step11 else Step17
Step12 : Check condition A[J] < A[J+1] then Step13 else Step16
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10]={ 2, 3, 4, 10, 9, 7, 8, 6, 5, 1},t;
int i,j;
clrscr();
cout<< “Output”;
cout<<“Before sorting array elements are “;
for(i=0;i<10;i++)
{
cout<<a[i]<<” \t “;
}
for(i=0; i<10-1; i++)
{
for(j=0; j<10-i-1; j++)
{
if(a[j] < a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
cout<<“After sorting array elements are “;
for(i=0;i<10;i++)
{
cout<<a[i]<<” \t“;
}
getch();
}
Output
Before sorting array elements are
2 3 4 10 9 7 8 6 5 1
After sorting array elements are
10 9 8 7 6 5 4 3 2 1
Write a program in C++ that exchanges data (passing by reference) using SWAP function to
interchange the given two variable
Algorithm for exchange the values using Function
Step1 : START
Step2 : Declare A,B as integer Variable
Step3 : Accept value from user and store it in A & B
Step4 : call the function SWAP(A,B) goto Step6
Step5 : END
Step6 : calling function SWAP(int X, int Y)
Step7 : Declare T as integer
Step8 : Assign the value X to T i.e. T := X
Step9 : Assign the value Y to X i.e. X := Y
Step10 : Assign the value T to Y i.e. Y := T
Step11 : Display X & Y
Step12 : Return to Step5
//PROGRAM FOR SWAP (EXCHANGE THE VALUES OF 2 VARIABLES
# 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;
cout<<”Output \n Enter any two number : ”;
cin>>a>>b;
cout<<”Before swapping : \n”
cout<<” a := ” << a <<” b := ”<< b<< endl;
cout<<”After swapping : \n”
swap(a,b);
cout<< ”a:= ”<< a<< ” b := ”<< b<< endl;
getch( );
}
Output:
Enter any two number :
2
4
Before swapping
a:= 2 b:= 4
After swampping
a:= 4 b: =2
/* Write a program in C++ with ratio class using member functions like assign ( ) function to
initialise 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 reciprocal. */
Step1 : Define class class ratio
Step2 : Declare member function assign(int, int), convert( ), invert( ), print( ) and data members
num,den;
Step3 : return
Step1 : START
Step2 : Create object of class ratio as X
Step3 : Call function assign(22,7)
Step4 : Call function print( )
Step5 : Call function convert( )
Step6 : Call function invert( )
Step7 : Call function print( )
Step8 : END
/* Write a program in C++ with ratio class using member functions like assign ( ) function to
initialise 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 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; clrscr( );
cout<<"Output";
x.assign(22,7);
cout<<"x=";
x.print();
cout<<"="<<x.convert( )<<"\n";
x.invert( );
cout<<"1/x=";
x.print( );
cout<<"\n";
getch(); }
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
/* Implement a circle class in C++ Each object of this class will represent a circle, storing its
radius and x and y co-ordinates of its centre as floats. Include a default constructor, access
functions, an area ( ) function on and a circumference ( ) function. The program must print the
co-ordinates with radius, area and circumference of the circle.*/
Step1: START
Step2 : Create object C1 of class Circle
Step3 : Call function C1.assign( )
Step4 : Call function C1.area()
Step5 : Call function C1.circumf();
Step6 : Call function C1.printc();
Step7 : END
/* Implement a circle class in C++ Each object of this class will represent a circle, storing its
radius and x and y co-ordinates of its centre as floats. Include a default constructor, access
functions, an area ( ) function on and a 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 coordinatesof 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 coordinates=”<<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 coordinatesof the center 2 1
type the radius :2
X,Y coordinates=2 1
the radius is 2
the area is12.56
the circumference is 12.56
/* Write a program in C++ that initialises a Static 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 reaches the end of its scope. */
Step1 : START
Step2 : Create object x of class ratio and call constructor after that call destructor
Step3 : END
#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<<” Output\n 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
object dies
/* Write a program in C++ with a complex constructor to add the given two complex numbers
A =______ and B = ______. The program should print the given complex number and their
sum. */
Step1 : START
Step2 : Create object C1, C2, C3 of class complex
Step3 : Assign values to object C1 means C1=complex(2.5,3.5)
Step4 : Assign values to object C2 means C2=complex(1.6,2.7)
Step5 : Add C1 and C2 and store it in C3 means C3=c1+c2;
Step6 : Call function C1.display( );
Step7 : Call function C2.display();
Step8 : Call function C3.display();
Step9 : END
/* Write a program in C++ with a complex constructor to add the given two complex numbers
A =______ and B = ______. 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
/* Define two classes polar and Rectangle in C++ to represent points in the polar and
rectangular systems. Use conversion routines from one system to the other. */
Step1 : START
Step2 : Create object rec of class record
Step3 : Call function polcord(10.0,0.785398)
Step4: Assign polcord class to record class
Step4 : Call function display ( ) of class polcord
Step5 : Call function display ( ) of class record
Step6 : END
/* Define two classes polar and Rectangle 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<<"Xcoordinate="<<xcord<<"\n"<<"Ycoordinate="<<ycord;
}
};
void main( )
{
rec record;
polar polcord(10.0,0.785398);;
record=polcord;
cout<<"\n Output is “\n";
cout<<"Polar coordinates:\n";
cout<<"Polar coordinates:\n";
polcord.display();
cout<<"\nRectangular coordinates:";
record.display();
}
Output is:
Polar coordinates
Radius =10 Angle=0.785398
Rectangular coordinates
Xcoordinate=
7.07107
Ycoordinate=
7.07107
/* 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 number , individual marks obtained in two subject, sports and total marks. */
Algorithm to implement the following class hierarchy single inheritance
Step1 : START
Step2 : Declare Object of class result as st1
Step3 : Call function get_no( ) of class Students
Step4 : Call function get_marks( ) of class Test
Step5 : Call function get_score of class Sports
Step6 : Call function display( ) of class result
Step7 : END
#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);
cout<<”Output is “;
st1.display();
}
Output is:
roll_no:101
marks obtained :
s1=39
s2=65
sports marks :29
total score=133
Write a program in Visual Basic that calculates area and selections of two shapes, Circle and
Rectangle.
Properties
Label1
Caption = “Enter radius
Label2
Caption = “Area of circle is”
Label3 Command1
Caption = “ ” Caption = Display
Text1 Command2
Text = “ “ Caption = Clear
Text2 Command3
Text = “ “ Caption = “Circle”
Text3 Command4
Text = “ “ Caption = “Rectangle”
Text4
Text = “ “
Text5
Text = “ “
Private Sub Command1_Click( )
Frame1.Visible = True
Frame2.Visible = False
End Sub
Private Sub Command2_Click( )
Frame1.Visible = False
Frame2.Visible = True
End Sub
Private Sub Command3_Click( )
Text2.Text = 3.14 * Val(Text1.Text) * Val(Text1.Text)
End Sub
Private Sub Command4_Click( )
Text5.Text = Val(Text3.Text) * Val(Text4.Text)
End Sub
Private Sub Command5_Click( )
Text1.Text = "" Text2.Text = ""
End Sub
Private Sub Command6_Click( )
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
End Sub
Private Sub Form_Load( )
Form1.WindowState = 2
Frame1.Visible = False
Frame2.Visible = False
End Sub
Write a program in Visual Basic to find the sum of first 100 numbers entered using Do loop.
Properties:
Label1
caption = “ Sum of 1 to 100 nos.”
Lalbel2
caption=” ”
Command1
Caption = “While”
Command2
Caption = “Do..While”
Command3
Caption = “for”
Command4
Caption = “Exit”
Form1
caption = “Form1”
Private Sub Command1_Click( )
Dim N As Integer
Dim S As Integer
S=0
n=1
Do While N <= 100
S=S+N
N=N+1
Loop
Label2.Caption = S
End Sub
<html>
<head> <title>WIPRO</title> </head>
<body bgcolor="aqua">
<marquee><font color="black" size="8"> Welcome To Wipro</font></marquee>
<a href="www.wirpo.com"><img src=file:///D: /wipro.png width=40% height=200
alt="WIPRO"> </img></a>
<hr>
<h2><center>ABOUT</center></h2>
<font color="red" size="5"><p>
Wipro Ltd (NYSE:WIT) is a global information technology, consulting and
outsourcing company with 170,000+ workforce serving clients in 175+ cities
across 6 continents. The company posted revenues of $7.7 Billion for the financial
year ended Mar 31, 2016.
</font></p>
<hr>
<h2><center>CAREER</center></h2>
<font color="green" size="5"><p>
<table border="2">
<tr>
<th>Campus</th>
<th> Work with Us</th>
<th colspan="2"> staffing partners </th>
</tr>
<tr>
<td> Engineering</td>
<td> Job Search </td>
<td> Permanant Staffing </td>
<td> Contractual Staffing </td>
</tr>
<tr>
<td> MBA</td>
<td> Hiring Process </td>
<td> ABC </td>
<td> XYZ </td>
</tr>
<tr>
<td> Science Graduates </td>
<td> Wipro Americas </td>
<td> DEF </td>
<td> UVW</td>
</tr>
</table>
</font></p>
<hr>
<h2><center>CONTACT US</center></h2>
<font color="orange" size="5"><p>
Wipro Limited<br>
Doddakannelli, Sarjapur Road, <br>Bangalore - 560035<br> Phone:
+91 80 28440011<br>Fax No: +91 80 28440256 Website:-
<a href="www.wipro.com">WIPRO</a></font></p>
</body>
</html>
Write a Algorithm to display a series of Fibonacci number using constructor
Step1 : START
Step2 : Declare the Fibonacci Class with 3 data member as F0, F1 & FIB as private & one
constructor as Fibonacci( ) as public & two functions as increment( ) and display( )
Step3 : Define the Fibonacci( ) of Fibonacci class which will assign the zero to F0 and one to
F1 and add F0 and F1 and store it in FIB.
Step4 : Define the increment( ) of Fibonacci class which will assign the F1 to F0 and FIB to
F1 and add F0 and F1 and store in FIB.
Step5 : Define the display( ) of Fibonacci class which will display the FIB number
Step6 : Declare the object number of class Fibonacci.
Step7 : Take a loop and initialize initial value zero to I means I := 0
Step8 : check condition I <= 5 then Step9 else Step12
Step9 : Call the function display( )
Step10 : call the function increment( )
Step11 : increase I by one and return to Step8
Step12 : STOP
Draw the flow chart to display a series of Fibonacci number using constructor
/* Write a program in C++ to display a series of Fibonacci number using constructor */
#include<iostream.h>
#include<conio.h>
class fibonacci
{
private:
unsigned long int f0, f1, fib;
public:
fibonacci();
void increment();
void display();
};
fibonacci :: fibonacci()
{ f0 = 0;
f1 = 1;
fib = f0 + f1; }
void fibonacci :: increment()
{ f0 = f1;
f1 = fib;
fib = f0 + f1; }
void fibonacci :: display()
{ cout << fib << "\n"; }
void main()
{
fibonacci number;
clrscr();
cout << "Output \n";
for(int i = 0; i <= 5; i++)
{ number.display();
number.increment(); }
getch();
}
Output
1
2
3
5
8
13
Write a program in C++ to read data variable day, month & year of a class date by member
function & display the content of class object.
Algorithm for date display
Step1 : START
Step2 : Declare the date class with 3 data members as day, month, year as private and two
functions as getdata( ) and putdata( )
Step3 : Define the getdata( ) of date class which will take the day, month and year of date
Step4 : Define display ( ) of date class which will display the day, month and year of date
Step5 : Declare the object today of class date
Step6 : Call the getdate( )
Step7 : Call the display( )
Step8 : END
Draw the flowchart to read data variable day, month & year of a class date by member function
& display the content of class object.
/* Write a program in C++ to read data variable day, month & year of a class date by member
function & display the content of class object. */
#include<iostream.h>
#include<conio.h>
class date
{
private:
int day;
int month;
int year;
public:
void getdate()
{
cout<<"Enter date : " << endl;
cin >> day >> month >> year;
}
void display()
{
cout << "Todays date = " << day << "/";
cout << month << "/" << year << endl;
}
};
void main()
{
clrscr();
class date today;
cout << “Output \n” ;
today.getdate();
today.display();
getch();
}
Output
Enter date :
11 02 2014
Todays date = 11/2/2014
Write a program in C++ to overload unary minus operator, so that unary minus operator when
applied to an object should change the sign of each of its data item.
Step1 : START
Step2 : Declare a class as space with 3 data members X, Y and Z as private and 3 member
functions as getdata ( )with 3 argument A, B and C as integer and pudata( ) and
operator-( )
Step3 : Define the getdata( ) of class space which will assign the value A to X and B to Y
and C to Z
Step4 : Define the display( ) of class space which will display the value of X, Y, Z
Step5 : Define the Operator-( ) of class space which will assign the minus operator as –X to
X and –Y to Y and –Z to Z
Step6 : Declare the object S of class space
Step7 : Call the getdata( )
Step8 : Call the display ( )
Step9 : Call the operator-( )
Step10 : Call the display( )
Step11 : END
Draw the flowchart to overload unary minus operator, so that unary minus operator when
applied to an object should change the sign of each of its data item.
/* Write a program in C++ to overload unary minus operator, so that unary minus operator
when applied to an object should change the sign of each of its data item. */
#include<iostream.h>
#include<conio.h>
class space
{ int X, Y, Z;
public:
void getdata(int a, int b, int c);
void display(void);
void operator-(); };
void space::getdata(int a, int b, int c)
{ X = a; Y = b; Z = c; }
void space :: display(void)
{ cout << X << " ";
cout << Y << " ";
cout << Z << " "; }
void space :: operator-()
{ X = -X; Y = -Y; Z = -Z; }
void main()
{ space S;
clrscr();
cout << "Output \n";
S.getdata(10, -20, 30);
cout << "Output\n";
cout << "Before Unary Operator\n";
cout << "S : ";
S.display();
-S;
cout << "\n\nAfter Unary Operator \n";
cout << "\nS : ";
S.display();
getch();
}
Output
Before Unary Operator
S : 10 -20 30
After Unary Operator
S : -10 20 -30