Electrofriends

c++ Program to illustrate the use of difference operators using friend function

by Ranjith | March 13th, 2010.

AIM:
A program to illustrate the use of difference operators to access the class member using friend function

ALGORITHM:
1) Start the process
2) Invoke the classes
3) Call the set_xy() first
a) Assign the value of x and y
b) Print the value of x and y
4) Call the sum() for second(friend)
a) Again assign the temp value of x and y
5) Print the value of x and [...]

Read More..

C++ program to print student details using constructor and destructor

by Ranjith | March 12th, 2010.

CONSTRUCTOR AND DESTRUCTOR
AIM:
A program to print student details using constructor and destructor
ALGORITHAM:
1. Start the process
2. Invoke the classes
3. Call the read() function
a. Get the inputs name ,roll number and address
4. Call the display() function
a. Display the name,roll number,and address of the student
5. Stop the process
PROGRAM

#include<iostream.h>
#include<conio.h>
class stu
{
private: char name[20],add[20];
int roll,zip;
public: stu ( );//Constructor
~stu( );//Destructor
void read( );
void disp( );
};
stu :: [...]

Read More..

C++ program for implementation of class

by Ranjith | March 12th, 2010.

AIM:
A program to solve a quadratic equation, using OOP techniques.
ALGORITHM:
1) Start the process
2) Invoke the classes
3) Get the input for a,b,c;
4) Call the function getinfo() and display()
5) Check if a=0
a) True : compute c/b;
i) Print the value of a/c;
b) False: compute b*b-4*a*c;
i) If ( b*b-4*a*c)=0
ii) Call img();
iii) Otherwise : call real(a,b,c);
6) Stop the process
PROGRAM:

#include<iostream.h>
#include<conio.h>
class equation
{
private:float a,b,c;
public: void getinfo(float a, float b,float c );
void display( [...]

Read More..

C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem

by Ranjith | March 11th, 2010.

/* Write a C++ program that uses dynamic programming algorithm to solve the optimal binary search tree problem */

#include<iostream>
#include<conio.h>
#include<stdio.h>
using namespace std;
#define MAX 10
int find(int i,int j);
void print(int,int);
int p[MAX],q[MAX],w[10][10],c[10][10],r[10][10],i,j,k,n,m;
char idnt[7][10];
 
main()
{
cout << "enter the no, of identifiers";
cin >>n;
cout <<"enter identifiers";
for(i=1;i<=n;i++)
gets(idnt[i]);
cout <<"enter success propability for identifiers";
for(i=1;i<=n;i++)
cin >>p[i];
cout << "enter failure propability for identifiers";
for(i=0;i<=n;i++)
cin >> q[i];
for(i=0;i<=n;i++)
{
w[i][i]=q[i];
c[i][i]=r[i][i]=0;
w[i][i+1]=q[i]+q[i+1]+p[i+1];
r[i][i+1]=i+1;
c[i][i+1]=q[i]+q[i+1]+p[i+1];
}
w[n][n]=q[n];
r[n][n]=c[n][n]=0;
for(m=2;m<=n;m++)
{
for(i=0;i<=n-m;i++)
{
[...]

Read More..

C++ program to implement dynamic programming algorithm to solve the all pairs shortest path problem

by Ranjith | March 11th, 2010.

/* Write a C++ program to implement dynamic programming algorithm to solve the all pairs shortest path problem */

#include<iostream>
#include<conio.h>
using namespace std;
int min(int a,int b);
int cost[10][10],a[10][10],i,j,k,c;
 
main()
{
int n,m;
cout <<"enter no of vertices";
cin >> n;
cout <<"enter no od edges";
cin >> m;
cout<<"enter the\nEDGE Cost\n";
for(k=1;k<=m;k++)
{
cin>>i>>j>>c;
a[i][j]=cost[i][j]=c;
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
{
if(a[i][j]== 0 && i [...]

Read More..

C++ programs for sorting a given numbers in ascending order using Merge sort

by Ranjith | March 11th, 2010.

/* Write C++ programs for sorting a given list of elements in ascending order using Merge sort methods */

#include<iostream>
#include<conio.h>
using namespace std;
void mergesort(int *,int,int);
void merge(int *,int,int,int);
int a[20],i,n,b[20];
 
main()
{
cout <<"\n enter no of elements";
cin >> n;
cout <<"enter the elements";
for(i=0;i<n;i++)
cin >> a[i];
mergesort(a,0,n-1);
cout <<" numbers after sort";
for(i=0;i<n;i++)
cout << a[i] << " ";
getch();
}
 
void mergesort(int a[],int i,int j)
{
int mid;
[...]

Read More..

C++ programs for sorting numbers in ascending order using Quick sort method

by Ranjith | March 11th, 2010.

/* Write C++ programs for sorting a given list of elements in ascending order using Quick sort sorting methods */

#include<iostream.h>
#include<conio.h>
int a[10],l,u,i,j;
void quick(int *,int,int);
void main()
{
clrscr();
cout <<"enter 10 elements";
for(i=0;i<10;i++)
cin >> a[i];
l=0;
u=9;
quick(a,l,u);
cout <<"sorted elements";
for(i=0;i<10;i++)
cout << a[i] << " ";
getch();
}
 
void quick(int a[],int l,int u)
{
int p,temp;
if(l<u)
{
p=a[l];
[...]

Read More..

C++ program that uses non-recursive functions to traverse a binary tree in Post-order

by Ranjith | March 11th, 2010.

/* Write C++ program that uses non-recursive functions to traverse a binary tree in Post-order */

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
 
class node
{
public:
class node *left;
class node *right;
int data;
};
 
class tree: public node
{
public:
int stk[50],top;
node *root;
tree()
{
root=NULL;
top=0;
}
void insert(int ch)
{
node *temp,*temp1;
if(root== NULL)
{
root=new node;
root->data=ch;
root->left=NULL;
root->right=NULL;
return;
}
temp1=new node;
temp1->data=ch;
temp1->right=temp1->left=NULL;
temp=search(root,ch);
if(temp->data>ch)
temp->left=temp1;
else
temp->right=temp1;
 
}
node *search(node *temp,int ch)
{
if(root== NULL)
{
cout <<"no node present";
return NULL;
}
if(temp->left==NULL && temp->right== NULL)
return temp;
 
if(temp->data>ch)
{ if(temp->left==NULL) return temp;
search(temp->left,ch);}
else
[...]

Read More..

C++ program that uses non-recursive functions to traverse a binary tree in In-order

by Ranjith | March 11th, 2010.

/* Write C++ program that uses non-recursive functions to traverse a binary tree in In-order */

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class node
{
public:
class node *left;
class node *right;
int data;
};
 
class tree: public node
{
public:
int stk[50],top;
node *root;
tree()
{
root=NULL;
top=0;
}
void insert(int ch)
{
node *temp,*temp1;
if(root== NULL)
{
root=new node;
root->data=ch;
root->left=NULL;
root->right=NULL;
return;
}
temp1=new node;
temp1->data=ch;
temp1->right=temp1->left=NULL;
temp=search(root,ch);
if(temp->data>ch)
temp->left=temp1;
else
temp->right=temp1;
 
}
 
node *search(node *temp,int ch)
{
if(root== NULL)
{
cout <<"no node present";
return NULL;
}
if(temp->left==NULL && temp->right== NULL)
return temp;
 
if(temp->data>ch)
{ if(temp->left==NULL) return [...]

Read More..

C++ program that uses non-recursive functions to traverse a binary tree in Pre-order

by Ranjith | March 11th, 2010.

/* Write C++ program that uses non-recursive functions to traverse a binary tree in Pre-order */

#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class node
{
public:
class node *left;
class node *right;
int data;
};
 
class tree: public node
{
public:
int stk[50],top;
node *root;
tree()
{
root=NULL;
top=0;
}
void insert(int ch)
{
node *temp,*temp1;
if(root== NULL)
{
root=new node;
root->data=ch;
root->left=NULL;
root->right=NULL;
return;
}
temp1=new node;
temp1->data=ch;
temp1->right=temp1->left=NULL;
temp=search(root,ch);
if(temp->data>ch)
temp->left=temp1;
else
temp->right=temp1;
 
}
 
node *search(node *temp,int ch)
{
if(root== NULL)
{
cout <<"no node present";
return NULL;
}
if(temp->left==NULL && temp->right== NULL)
return temp;
 
if(temp->data>ch)
{ if(temp->left==NULL) return [...]

Read More..
Copyright©2009 www.electrofriends.com All Rights Reserved. Powered by Dhyeya