Reverse String without Built-In Functions

This program is to reverses a String without built-in functions . This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1

This program uses the concept of Arrays for the same. And doesnt use built in string functions.
Can be made into C or C++ program

#include<iostream.h>
#include<conio.h>
char* rev(char *a,int n);
void main()
{
char *a;
char *b;
int n,m;
clrscr();
cout<<"Enter a string of chars ";
cin>>a;
cout<<"Enter the characters in the string";
cin>>m;
cout<<"The string is "<<a<<endl;
cout<<"Array size is "<<n;
b=rev(a,m);
cout<<"Revers of the array is "<<b;
getch();
}
char* rev(char a[],int n)
{
int i,j;
char *tmp;
for(i=0,j=n-1;i<n;i++,j--)
{
tmp[i]=a[j];
cout<<tmp[i]<<endl;;
}
tmp[i]=a[n];
return tmp;
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Returns First Repeating Character from Array

This program is to Returns first repeating character from inputted array . This is a part of Mumbai University MCA Colleges C++ Programs MCA 

This program can be modified as to accept user input and also be made in C++ or C Language.


#include<stdio.h>
#include<conio.h>
#include<iostream.h>
char removeDuplicates(char arr[],int n);
void main()
{
 char s[]={'a','b','n','a','b','c'};
 clrscr();
 printf("\nInput Array is: %s\n",s);

 printf("\nFirst Non repeating character Array is: %c\n",removeDuplicates(s,6));
 getch();
}

char removeDuplicates(char arr[],int n)
{
 int i=0,j,cnt,flag=1;
 char c;
 c=arr[0];
 cnt=0;
 for(j=1;j<n;j++)
 {
 for(i=0;i<n;i++)
{ if (cnt==i){}
else
{
if(c==arr[i])
{
flag=0;
cout<<c<<endl;
break;
}
}
}
if(flag==1)
{
return c;
}
       c=arr[j];
       cnt=j;
       flag=1;
  }
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Return Non Repeating Chars from Array

This program is to return non-repeating character array from inputted array having repeating characters . This is a part of Mumbai University MCA Colleges C Programs MCA Sem 1

This program uses the concept of Arrays for the same. And doesnt use built in string functions.
We can modify the same to accept values from the user directly.

#include<stdio.h>
#include<conio.h>
char* removeDuplicates(char arr[]);
void main()
{
 char s[]={'a','b','c','d','e','g','a','b','c','d','e','f'};
 clrscr();
 printf("\nInput Array is: %s\n",s);
 printf("\nOutput Array is: %s\n",removeDuplicates(s));
 getch();
}

char* removeDuplicates(char arr[])
{
 int i=0,j,k;

 while(arr[i]!=0)
 {
for(j=i+1;arr[j]!=0;j++)
{
if(arr[i]==arr[j])
{
  for(k=j;arr[k]!=0;k++)
arr[k]=arr[k+1];
  arr[k]='\0';
  j--;
}
}
i++;

 }
 return arr;
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Matrix Mulitplication Addition in Cpp / C++

This Cpp program is for Matrix Multiplication, Addition and Display of Matrix / Array 2D. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA. 


In the below program we have used 2 Two Dimensional Arrays to form a Matrix and showed the different operations on Matrix.

#include<iostream.h>
#include<conio.h>
int i,j,k;

class Matrix
{
int a[2][2],b[2][2];
public :
void get_data();
void Show(int [2][2]);
void Add();
void Multi();
};

void Matrix :: get_data()
{
cout<<"Enter data for Matrix A : "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>a[i][j];
}
}

cout<<"Enter data for Matrix B : "<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cin>>b[i][j];
}
}
Show(a);
Show(b);
}


void Matrix :: Show(int x[2][2])
{
cout<<endl<<endl;
cout<<"Array :"<<endl;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<x[i][j];
}
cout<<endl;
}
}

void Matrix :: Add()
{
int c[2][2];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
c[i][j]=0;

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}

cout<<endl<<"Addittion : "<<endl;
Show(c);
}

void Matrix :: Multi()
{
int c[2][2];
for(i=0;i<2;i++)
for(j=0;j<2;j++)
c[i][j]=0;

for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
cout<<endl<<"Multiplication : "<<endl;
Show(c);
}

void main()
{
Matrix m;
clrscr();
m.get_data();
m.Add();
m.Multi();
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.

Dijkstra's Algorithm C program Data Structure

This Program Performs Dijkstra's Algorithm in C Program. This is a part of Mumbai University MCA Colleges Data Structure C Program MCA Sem 2

#include<stdio.h>
#include<conio.h>

#define MAX 10
#define TEMP 0
#define PERM 1
#define infinity 9999

struct node
{
          int predecessor;
          int dist;
          int status;
};

int adj[MAX][MAX];
int n;
void main()
{
          int i,j;
          int source,dest;
          int path[MAX];
          int shortdist,count;
          clrscr();
printf("************************ DIJKSTRA'S SHORTEST PATH **********************");
          create_graph();
          printf("The adjacency matrix is :\n");
          display();

          while(1)
          {
                   printf("\nEnter source node(0 to quit) : ");
                   scanf("%d",&source);
                   printf("\nEnter destination node(0 to quit) : ");
                   scanf("%d",&dest);

                   if(source==0 || dest==0)
                             exit(1);

                   count = findpath(source,dest,path,&shortdist);
                    if(shortdist!=0)
                   {
                             printf("\nShortest distance is : %d\n", shortdist);
                             printf("\nShortest Path is : ");
                             for(i=count;i>1;i--)
                                      printf("%d->",path[i]);
                             printf("%d",path[i]);
                             printf("\n");
                   }
                   else
                             printf("\nThere is no path from source to destination node\n");
          }
          getch();
}

create_graph()
{
          int i,max_edges,origin,destin,wt;

          printf("Enter number of vertices : ");
          scanf("%d",&n);
          max_edges=n*(n-1);

          for(i=1;i<=max_edges;i++)
          {
                   printf("\nEnter edge %d(0 0 to quit) : ",i);
                   scanf("%d %d",&origin,&destin);
                   if((origin==0) && (destin==0))
                             break;
                   printf("\nEnter weight for this edge : ");
                   scanf("%d",&wt);
                   if( origin > n || destin > n || origin<=0 || destin<=0)
                   {
                             printf("\nInvalid edge!\n");
                             i--;
                   }
                   else
                             adj[origin][destin]=wt;
          }
}

display()
{
          int i,j;
          for(i=1;i<=n;i++)
          {
                   for(j=1;j<=n;j++)
                             printf("%3d",adj[i][j]);
                   printf("\n");
          }

}

int findpath(int s,int d,int path[MAX],int *sdist)
{
          struct node state[MAX];
          int i,min,count=0,current,newdist,u,v;
          *sdist=0;
          for(i=1;i<=n;i++)
          {
                   state[i].predecessor=0;
                   state[i].dist = infinity;
                   state[i].status = TEMP;
          }
          state[s].predecessor=0;
          state[s].dist = 0;
          state[s].status = PERM;
          current=s;
          while(current!=d)
          {
                   for(i=1;i<=n;i++)
                   {
                             if ( adj[current][i] > 0 && state[i].status == TEMP )
                             {
                                      newdist=state[current].dist + adj[current][i];
                                      if( newdist < state[i].dist )
                                      {
                                                state[i].predecessor = current;
                                                state[i].dist = newdist;
                                      }
                             }
                   }
                   min=infinity;
                   current=0;
                   for(i=1;i<=n;i++)
                   {
                             if(state[i].status == TEMP && state[i].dist < min)
                             {
                                      min = state[i].dist;
                                      current=i;
                             }
                   }

                   if(current==0)
                             return 0;
                   state[current].status=PERM;
          }
          while( current!=0 )
          {
                   count++;
                   path[count]=current;
                    current=state[current].predecessor;
          }
          for(i=count;i>1;i--)
          {
                   u=path[i];
                   v=path[i-1];
                   *sdist+= adj[u][v];
          }
          return (count);
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Shortest Path using Dijkstras Alogrithm

This program to calculate shortest routing path using Dijkstra’s algorithm. This is a part of Mumbai University MCA Colleges Data Communication and Networking MCA Sem 4 #include<conio.h>

#include<stdio.h>
void main()
{
            int addj[10][10];
            int n, i, j, k, src, des;
            clrscr();
            printf("How many vertices are there : ");
            scanf("%d",&n);
            printf("\nEnter values of matrix: \n");
            for(i=0;i<n;i++)
            {
                        for(j=0;j<n;j++)
                        {
                                    scanf("%d",&addj[i][j]);
                        }
            }
            printf("\nEnter source node: ");
            scanf("%d", &src);

            printf("\nEnter destination node: ");
            scanf("%d", &des);

            for(k=0;k<n;k++)
            {
                        for(i=0;i<n;i++)
                        {
                                    for(j=0;j<n;j++)
                                    {
                                                if(addj[i][j] > addj[i][k]+addj[k][j])
                                                {
                                                            addj[i][j]=addj[i][k]+addj[k][j];
                                                }
                                    }
                        }
            }
           
printf(“\n\n”);
            printf("Shortest path matrix....");
            for(i=0;i<n;i++)
            {
                        printf("\n");
                        for(j=0;j<n;j++)
                        {
                                    printf("%d\t",addj[i][j]);
                        }
            }

            printf("\n\nThe cost of shortest path from %d to %d is %d", src,des,addj[src-1][des-1]);
            getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Function Overloading - Polymorphism Cpp / C++


This Cpp/ C++  Program is for performing Function Overloading / Compile Time Polymorphism. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA. 


The below program performs function overloading to find the sum of 2 numbers.
The function is overloaded to calculate the sum of float, int, double etc.

#include<iostream.h>
#include<conio.h>

class Add
{
float sum1;
public :
void sum(int,int);
void sum(float,int,int);
void sum(float,float);
void sum(double,int);
};

void Add :: sum(int a,int b)
{
sum1=a+b;
cout<<endl<<"Sum : "<<sum1;
}

void Add :: sum(float a,int b,int c)
{
sum1=a+b+c;
cout<<endl<<"Sum : "<<sum1;
}

void Add :: sum(float a,float b)
{
sum1=a+b;
cout<<endl<<"Sum : "<<sum1;
}

void Add :: sum(double a,int b)
{
sum1=a+b;
cout<<endl<<"Sum : "<<sum1;
}

void main()
{
Add a;
clrscr();
a.sum(10,2);
a.sum(2.5,10,5);
a.sum(3.50,3.50);
a.sum(11.22,2);
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.

Templates in Cpp / C++ swapping of 2 numbers


This program is for Swapping of Numbers using Templates . This is a part of Mumbai University MCA Colleges C++ Programs MCA. It uses the concept of template to swap 2 numbers.

Templates in C++ or CPP are basically used when we are not sure of the datatype which the user is going to input. We wrap the data in those templates and perform operations on them. Templates can be said as generic data types in C++ or CPP. This is a simple example to show how different numbers of different data types are swapped using a single function.


#include<iostream.h>
#include<conio.h>

template<class T>T swap(T &first,T &second)
{
T temp;
temp=first;
first=second;
second=temp;
return(0);
}

int swap(int &a,int &b);
float swap(float &x,float &y);
void main()
{
int ix,iy;
float fx,fy;
clrscr();
cout<<"\nEnter two Integers : ";
cin>>ix>>iy;
cout<<"\nEnter two Floating point Numbers : ";
cin>>fx>>fy;
cout<<"\nBefore Swap :";
cout<<"\n  a : "<<ix;
cout<<"\n  b : "<<iy;
swap(ix,iy);
cout<<"\n\nAfter Swap :";
cout<<"\n  a : "<<ix;
cout<<"\n  b : "<<iy;

cout<<"\n\nBefore Swap :";
cout<<"\n  a : "<<fx;
cout<<"\n  b : "<<fy;
swap(fx,fy);
cout<<"\n\nAfter Swap :";
cout<<"\n  x : "<<fx;
cout<<"\n  y : "<<fy;
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Cube and Power without built-in functions Cpp / C++

This Cpp program is for using the Math functions without the Math.h class. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA. 


The below program performs the operations of finding cube and power of a number without the built-in math functions. The Functions for the same are created by the programmer.

#include<iostream.h>
#include<conio.h>
#include<process.h>

class Math_1
{
int cu,num,base,pow,res;
public :
Math_1(){}
Math_1(int n)
{
num=n;
}
Math_1(int b,int p)
{
base=b;
pow=p;
}
~Math_1(){}
void cube();
void power();
};

void Math_1 :: cube()
{
cu=num*num*num;
cout<<endl;
cout<<"Cube of "<<num<<" : "<<cu;
}

void Math_1 :: power()
{

for(int i=0;i<pow;i++)
res=res*base;
cout<<endl;
cout<<"Result : "<<res;
}

void main()
{
int num,b,p,ch;
clrscr();
cout<<"1. Cube"<<endl;
cout<<"2. Power"<<endl<<endl;
cout<<"3. End";
while(1)
{
cout<<"\n\nEnter your choice : ";
cin>>ch;
switch(ch)
{
case 1:
cout<<"Enter Number : ";
cin>>num;
Math_1 m1(num);
m1.cube();
break;

case 2:
cout<<"Enter Base : ";
cin>>b;
cout<<"Enter Power : ";
cin>>p;
Math_1 m2(b,p);
m2.power();
break;

default :
cout<<"Please Enter Right Choice.";
exit(0);

}
}
getch();
}

Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.

Operator Overloading with Pointers


This program is for Operator Overloading in C++ . This is a part of Mumbai University MCA Colleges C++ Programs MCA. It performs the overloading of  '+' and '*' operators. 


C++ or CPP provides us to over load the different operators but the basic working of operators remains the same. Here we have overloaded the operators in a different way by using the local variables and used pointers as reference.



#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>

class OverLoad
{
char *s1,*s2;
public:
void get(char &a,char &b);
void put();
char* operator +();
char* operator *();
};
void OverLoad :: get(char &a,char &b)
{
s1=&a;
s2=&b;

}

void OverLoad :: put()
{
cout<<"String 1 : "<<s1;
cout<<"\nString 2 : "<<s2;

}

char* OverLoad :: operator +()
{
strcat(s1,s2);
return s1;
}

char* OverLoad :: operator *()
{
strrev(s1);
return s1;
}

void main()
{
char *a,*b,*c,*d;
OverLoad obj;
clrscr();
cout<<"Enter First String :";
gets(a);
cout<<"\nEnter Second String : ";
gets(b);
obj.get(*a,*b);
obj.put();
c=+obj;
cout<<"\n\nConcatinated String : "<<c;
d=*obj;
cout<<"\n\nReversed String : "<<d;
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs. Happy Programming and Studying.

Structures in Cpp Student Details

This Cpp program is for Displaying the details of Students with Structures. This is a part of Mumbai University MCA Colleges C++ / CPP Programs MCA. 


Structures are used to store a collection of different types of data types. Structure in C++ or Cpp is a precursor of a Class. Here we have used an array of Structures to Store the Details of Students and Display them. 'Struct' is the keyword we need to use to declare a structure.

#include<iostream.h>
#include<conio.h>
#include<string.h>
struct student
{
char name[20];
int roll;
int age;
char sex;
int height;
}s[20];

void main()
{
int i,n,a;
clrscr();
cout<<"How many records do u want to enter : ";
cin>>n;
for(i=0;i<n;i++)
{
name:
cout<<"\n\nEnter Name For Student "<<i+1<<" : ";
cin>>s[i].name;
roll:
cout<<"Enter Roll Number for Student "<<i+1<<" : ";
cin>>s[i].roll;
if(s[i].roll<1 || s[i].roll>30)
{
cout<<"The Limit Exceeds"<<endl;
goto roll;
}
age:
cout<<"Enter Age for Student "<<i+1<<" : ";
cin>>s[i].age;
if(s[i].age<18 || s[i].age>25)
{
cout<<"The Limit Exceeds"<<endl;
goto age;
}
sex:
cout<<"Enter Sex for Student "<<i+1<<" : ";
cin>>s[i].sex;
if(s[i].sex=='F' || s[i].sex=='M') {}
else
{
cout<<"Enter correct Sex"<<endl;
goto sex;
}
height:
cout<<"Enter Height for Student "<<i+1<<" : ";
cin>>s[i].height;
if(s[i].height<50 || s[i].height>250)
{
cout<<"The Limit Exceeds"<<endl;
goto height;
}
}
cout<<endl<<endl;
for(i=0;i<n;i++)
{
cout<<"-----Student  "<<i+1<<"-----"<<endl;
cout<<"Name :"<<s[i].name<<endl;
cout<<"Roll No. :"<<s[i].roll<<endl;
cout<<"Age :"<<s[i].age<<endl;
cout<<"Sex :"<<s[i].sex<<endl;
cout<<"Height :"<<s[i].height<<endl;
cout<<endl<<endl;
}
getch();
}


Hope this Program is useful to you in some sense or other. Keep on following this blog for more Mumbai University MCA College Programs and Simple Programs. Happy Programming and Studying.