C Programs

18 Comments

C++ program to implement three classes using multiple inheritance

MULTIPLE INHERITANCES AIM: Write a program to illustrating how all the three classes are implemented in multiple inheritance mode ALGORITHM • Start the process • Invoke the class M • Invoke the another class N • Invoke one more class,ie class P,which is inherited by both M and N • Create an object for class […]

52 Comments

C++ program to illustrate a Single Inheritance

SINGLE INHERITANCE AIM: A program to illustrate a single inheritance. We have a base class B and a derived class D. The class B contains one private data member, one public data member and three public member functions. The class D contains one private data member and two public member functions ALGORITHAM: • Start the […]

23 Comments

C++ program to swap two variables using function overloading

FUNCTION OVERLOADING AIM: A program to demonstrate how function overloading is carried out for swapping of two variables of the various data types, namely integer, floating point number and character types ALGORITHAM: • Start the process • Get the integer values of ix,iy • Get the floating values of fx,fy • Get the character values […]

No Comments

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

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) […]

2 Comments

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

/* 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]); […]

22 Comments

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

/* 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 <<" […]

2 Comments

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

/* 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) { […]

17 Comments

C++ programs to implement the Kruskal’s algorithm to generate a minimum cost spanning tree

/* Write C++ programs to implement the Kruskal’s algorithm to generate a minimum cost spanning tree */ #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,m,c,visit,visited[10],l,v,count,count1,vst,p;   main() { int dup1,dup2; cout<<"enter no of vertices"; cin >> n; cout <<"enter no of edges"; cin >>m; cout <<"EDGE Cost"; for(k=1;k<=m;k++) { cin >>i >>j >>c; cost[i][j]=c; cost[j][i]=c; […]

28 Comments

C++ programs to implement the Prim’s algorithm to generate a minimum cost spanning tree

/* Write C++ programs to implement the Prim’s algorithm to generate a minimum cost spanning tree */ #include<iostream> #include<conio.h> #include<stdlib.h> using namespace std; int cost[10][10],i,j,k,n,stk[10],top,v,visit[10],visited[10],u;   main() { int m,c; cout <<"enterno of vertices"; cin >> n; cout <<"ente no of edges"; cin >> m; cout <<"\nEDGES Cost\n"; for(k=1;k<=m;k++) { cin >>i>>j>>c; cost[i][j]=c; } for(i=1;i<=n;i++) […]