Two Dimensional array

// Lab 16.cpp : Defines the entry point for the console application.
//

#include"stdafx.h"
#include<iostream>
#include<string>
usingnamespacestd;
intloc;
intsize=3;

voidString();
voidNumeric();

voidInput_String(charA[][3]);
voidOutput_String(charA[][3]);
voidDelete_String(charA[][3]);
voidSearch_String(charA[][3]);
voidInsert_String(charA[][3]);
voidSort_String(charA[][3]);
voidInput_Numeric(intA[][3]);
voidOutput_Numeric(intA[][3]);
voidDelete_Numeric(intA[][3]);
voidSearch_Numeric(intA[][3]);
voidInsert_Numeric(intA[][3]);
voidSort_Numeric(intA[][3]);
voidmain()
{
intchoice;
do
{
cout<<"-----------------------------------------------------"<<endl;
cout<<" ------------- Welcome to Main Manu -----------------"<<endl;
cout<<"-----------------------------------------------------"<<endl;

cout<<"Press 1 for alphabetic "<<endl;
cout<<"Press 2 for numeric "<<endl;
cout<<"Press 3 for Exit "<<endl;

cout<<"----------------------------"<<endl;
cout<<"please Enter your choice "<<endl;
cin>>choice;
switch(choice)
{
case1:
{
String();
break;
}
case2:
{
Numeric();
break;
}
case3:
{

break;
default:

cout<<"Not a Valid Choice. \n"
<<"Choose again.\n";
break;
}

}

}while(choice!=3);

}
/////////////////////////////// String Funtions///////////////////////////
voidString()
{
system("CLS");
intchoice;
charA[3][3];
do
{
cout<<endl

<<" 1 - Enter Array Element .\n"
<<" 2 - Read Array element.\n"
<<" 3 - Delete Array element.\n"
<<" 4 - Search Array element.\n"
<<" 5 - insearting element in array.\n"
<<" 6 - For Sorting.\n"
<<" 7 - Back to Main Menu.\n"
<<" Enter your choice and press return: ";
cin>>choice;
switch(choice)
{
case1:

Input_String(A);

break;
case2:

Output_String(A);

break;
case3:
Delete_String(A);
break;
case4:
Search_String(A);
break;
case5:
Insert_String(A);
break;
case6:
Sort_String(A);
break;
case7:
system("CLS");
break;
default:

cout<<"Not a Valid Choice. \n"
<<"Choose again.\n";
break;

}
}
while(choice!=7);
}
///////////////////Input String//////////////////////////
voidInput_String(charA[][3])
{
system("CLS");
cout<<"please enter the Alphabetic element";
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
cin>>A[i][j];cout<<" ";
}
cout<<endl;
}
////////////////////Output String////////////////////////////////
voidOutput_String(charA[][3])
{
system("CLS");
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}

}
/////////////////////Delete String////////////////////////////////////////////////////////
voidDelete_String(charA[][3])
{
introw,col;
system("CLS");
cout<<"Please enter the row value you want to delete"<<endl;
cin>>row;
cout<<"Please enter the col value you want to delete"<<endl;
cin>>col;
if(row>=size+1&&col>=size+1)
{
cout<<"Deleation is not possible";
}
else
for(inti=0;i<size;i++)

for(intj=0;j<size;j++)
{
A[row][col]=A[i+1][j+1];
}
A[row][col]='\0';
cout<<"Resultant array is "<<endl;
for(inti=0;i<size;i++)

for(intj=0;j<size;j++)
{cout<<"Array value on index A ["<<i<<"] "<<A[i][j]<<" "<<endl;

}

}
/////////////////////////////Search string////////////////////////////////
voidSearch_String(charA[][3])
{
system("CLS");
charvalue,find;
introw,col;
cout<<" Enter the value to be searched:"<<endl;
cin>>value;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
if(A[i][j]==value)
{
find=A[i][j];
row=i;
col=j;
break;
}
}
cout<<endl;
}
if(value==find)
{
cout<<"Value Founded :"<<"Row :"<<row<<" Column :"<<col<<endl;
}
else
{
cout<<"Not Found"<<endl;
}

}
//////////////////////Inserting String////////////////////////////////
voidInsert_String(charA[][3])
{
system("CLS");
charvalue;
introw,col;
cout<<"Enter the row "<<endl;
cin>>row;
cout<<"Enter the col "<<endl;
cin>>col;
cout<<"Enter the value to insert"<<endl;
cin>>value;
A[row][col]=value;
cout<<"Resultant array is"<<endl;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}
}
//////////////////////////////sort string/////////////////////////////
voidSort_String(charA[][3])
{
intx;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
x=j+1;
for(intk=i;k<size;k++)
{
for(intm=x;m<size;m++)
{
if(A[i][j]>A[k][m])
swap(A[i][j],A[k][m]);
}
x=0;
}
}
}
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
}
}



///////////////////////////////// Numeric Funtions///////////////////////////
voidNumeric()
{
system("CLS");

intchoice;
intA[3][3];
do
{
cout<<endl

<<" 1 - Enter Array Element .\n"
<<" 2 - Read Array element.\n"
<<" 3 - Delete Array element.\n"
<<" 4 - Search Array element.\n"
<<" 5 - insearting element in array.\n"
<<" 6 - For Sorting.\n"
<<" 7 - Back to Main Menu.\n"
<<" Enter your choice and press return: ";
cin>>choice;
switch(choice)
{
case1:

Input_Numeric(A);

break;
case2:

Output_Numeric(A);

break;
case3:
Delete_Numeric(A);
break;
case4:
Search_Numeric(A);
break;
case5:
Insert_Numeric(A);
break;
case6:
Sort_Numeric(A);
break;
case7:
system("CLS");
break;
default:
cout<<"Not a Valid Choice. \n"
<<"Choose again.\n";
break;
}
}
while(choice!=7);
}
/////////////////////////////Input Numeric///////////////////////////////////
voidInput_Numeric(intA[][3])
{
system("CLS");
cout<<"please enter the Numeric element";
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
cin>>A[i][j];cout<<" ";
}
cout<<endl;
}
///////////////////////////output Numeric/////////////////////////////////////
voidOutput_Numeric(intA[][3])
{
system("CLS");
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}

}
//////////////////////////Delete Numeric/////////////////////////////////////////
voidDelete_Numeric(intA[][3])
{
introw,col;
system("CLS");
cout<<"Please enter the row value you want to delete"<<endl;
cin>>row;
cout<<"Please enter the col value you want to delete"<<endl;
cin>>col;
if(row>=size+1&&col>=size+1)
{
cout<<"Deleation is not possible";
}
else
for(inti=row;i<size;i++)

for(intj=col;j<size;j++)
{
A[row][col]=A[i+1][j+1];

}

cout<<"Resultant array is "<<endl;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<"Array value on index A ["<<i<<"] "<<A[i][j]<<" "<<endl;
}
}

}
////////////////////////Search Numeric////////////////////////////////

voidSearch_Numeric(intA[][3])
{
system("CLS");
intvalue,find;
introw,col;
cout<<" Enter the value to be searched:"<<endl;
cin>>value;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
if(A[i][j]==value)
{
find=A[i][j];
row=i;
col=j;
break;
}
}
cout<<endl;
}
if(value==find)
{
cout<<"Value Founded :"<<"Row :"<<row<<" Column :"<<col<<endl;
}
else
{
cout<<"Not Found"<<endl;
}

}
///////////////////////////////inserting numeric/////////////////////

voidInsert_Numeric(intA[][3])
{
system("CLS");
intvalue;
introw,col;
cout<<"Enter the row "<<endl;
cin>>row;
cout<<"Enter the col "<<endl;
cin>>col;
cout<<"Enter the value to insert"<<endl;
cin>>value;
A[row][col]=value;
cout<<"Resultant array is"<<endl;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
cout<<endl;
}
}
////////////////////////Sort Numeric//////////////////////////
voidSort_Numeric(intA[][3])
{
intx;
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
x=j+1;
for(intk=i;k<size;k++)
{
for(intm=x;m<size;m++)
{
if(A[i][j]>A[k][m])
swap(A[i][j],A[k][m]);
}
x=0;
}
}
}
for(inti=0;i<size;i++)
{
for(intj=0;j<size;j++)
{
cout<<A[i][j]<<" ";
}
}
}
/////////////////////////////////////Program End////////////////////////////////////////////////



No comments:

Post a Comment