/*A program to empelement spars matrix operations.
compiler- Turbo c++ author- Mangilal Sharma
--------------------------------------------------------*/
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class spars
{
private:
int m[4][4],i,j,choice;
public:
void usm();
void lsm();
void tdsm();
spars();
};
void spars::usm()
{
cout<<"Enter the elements for upper sparce matrix:\n";
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
if(i<j) m[i][j]=0;
else cin>>m[i][j];
}
cout<<"\n\nUpper sparce matrix is:\n";
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
cout<<m[i][j]<<"\t";cout<<"\n";
}
}
void spars::lsm()
{
cout<<"\n\nEnter the elements for lower sparce matrix:\n";
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
if(i>j) m[i][j]=0;
else cin>>m[i][j];
}
cout<<"\n\nLower sparce matrix is:\n";
for(i=0;i<3;i++)
{
for(j=0; j<3; j++)
cout<<m[i][j]<<"\t";cout<<"\n";
}
}
void spars::tdsm()
{
cout<<"\n\nEnter the elements for tridiogonal sparce matrix:\n";
for(i=0;i<4;i++)
{
for(j=0; j<4; j++)
if(i<j-1||j<i-1) m[i][j]=0;
else cin>>m[i][j];
}
cout<<"\n\nTridiogonal sparce matrix is:\n";
for(i=0;i<4;i++)
{
for(j=0; j<4; j++)
cout<<m[i][j]<<"\t";
cout<<"\n";
}
}
spars::spars()
{
do
{
cout<<"\n\t\t\tSPARS MATRIX\n";
cout<<"\t\t1. Upper sparce matrix\n";
cout<<"\t\t2. Lower sparce matrix\n";
cout<<"\t\t3. Tridiogonal sparce matrix\n";
cout<<"\t\t4. To Main page\n";
cout<<"\t\t5. To Exit from Program\n";
cout<<"\n\t\t Enter Your Choice= ";
cin>>choice;
switch(choice)
{
case 1:
usm();break;
case 2:
lsm();break;
case 3:
tdsm();break;
case 4:
return;
case 5:
exit(1);
default:cout<<"\n\t\tWrong Choice, Enter Again\n";
}
}while(1);
}
/*=========================3Nov.,2010=============================*/
.thank you for sharing useful post.
ReplyDeleteweb programming tutorial
welookups
nice article for beginners.thank you.
javacodegeeks