i have the following code........pls point out my mistakes......the first one is the header file and the second one is the file.........

class array
{
int i, a[100],n,d,t,r,c,e[100][100],f[100][100],s,g[100][100],b[100],j,r1,c1;

char p;
public:
void pro();
void enter();
int arrA(int);
int arrB(int);
int arrAA(int r,int c);
int arrBB(int,int);
void dis();
};
void array::enter()
{    cout<<"Enter the degree of array";
     cin>>d;
     if(d==1)
     {       cout<<"Enter the no of elements you wish to input(less than 100)\n";
     cin>>n;
     t++;
     }

     else if(d==2)
     {    if(s==0)
          {cout<<"\nEnter the no of rows\n";
          cin>>r;
          cout<<"\nEnter the no of columns\n";
          cin>>c;
          }
          else if(s==1)
          {cout<<"\nEnter the no of rows\n";
          cin>>r1;
          cout<<"\nEnter the no of columns\n";
          cin>>c1;
          }
     else
     cout<<"\nWrong";     


}
}

int array::arrA(int n)

{ 

     cout<<"Input the elements\n";
     for(i=0; i<n; i++)
     {
       cin>>a[i];
     }

}
int array:: arrB(int n)

{ 

     cout<<"Input the elements\n";
     for(i=0; i<n; i++)
     {
       cin>>b[i];
     }

}

int array::arrAA(int r, int c)
{
     cout<<"Input the elements\n";
     for(i=0; i<r; i++)
     {        cout<<"\n";
              for(j=0; j<c; j++)
                cin>>f[i][j];

      }
}

int array:: arrBB(int r1,int c2)
{
     cout<<"Input the elements\n";
     for(i=0; i<r1; i++)
     {
              for(j=0; j<c1; j++)
              {
                       cin>>e[i][j];
              }
     }
}
void array::dis()
{    cout<<"Enter the array u wanna display";
     cin>>p;   
     cout<<"The input array is\n";
     switch(p)
     {
              case'a':
    { for(i=0; i<n; i++)
     {
              cout<<a[i]<<"\n";
              }
              }
     break;
           case'b':
                   {for(i=0; i<n; i++)
     {
              cout<<b[i]<<"\n";
              }
              }
     break;
     case'e':
              { for(i=0; i<r; i++)
              {          cout<<"\n";
                         for(j=0; j<c;j++)
                         cout<<f[i][j]<<"\t";
                         }
                         }
              break;
     case'f':
              { for(i=0; i<r1; i++)
              {          cout<<"\n";
                         for(j=0; j<c1;j++)
                         cout<<e[i][j]<<"\t";
                         }
                         }
              break;
     default:
             cout<<"Wrong choice";
}
}
void array:: pro()
{      
     if(d==1)
               {             if(t==0) 
                                arrA( n);
                               else
                               arrB(n);
                               }
     else if(d==2)
                 {
                               if(s==0)
                              { arrAA( r,  c);
                               s++;
                               }
                               else
                               arrBB( r1, c1);
                               }             
else                 cout<<"Wrong choice";
}
#endif

//source file..
#include"HEADER1.h"
#include<iostream>
int main()
{
    array w,l;
    w.enter();
    w.pro();
    w.enter();
    w.pro();
    w.dis();
    w.dis();

     system("pause");
    return 0;
}

pls help me.....

Recommended Answers

All 2 Replies

I just put both files in one for this post.

One huge thing you have to think about is how you format your code and variable names especially when you are going to post on a forum asking for help. I tried to clean it up with some white space to make it easier to read.

The only real errors you have is that you are not assigning values to variables that you are checking.

#include <iostream>
using namespace std;

class array
{
	int i, a[100], n, d, t, r, c, e[100][100], f[100][100], s, g[100][100], b[100], j, r1, c1;
	char p;

	public:
	void pro();
	void enter();
	void arrA( int );
	void arrB( int );
	void arrAA( int, int );
	void arrBB( int, int );
	void dis();
};

void array::enter()
{
	cout << "Enter the degree of array";
	cin >> d;
	if( d == 1 )
	{
		cout << "Enter the no of elements you wish to input(less than 100)\n";
		cin >> n;
		t++;
	}

	else if( d == 2 )
	{
		//did you want to put some code in here where you assign s?
		if( s == 0 ) //s is not assigned a value
		{
			cout << "\nEnter the no of rows\n";
			cin >> r;
			cout << "\nEnter the no of columns\n";
			cin >> c;
		}
		else if( s == 1 ) //s is not assigned a value
		{
			cout << "\nEnter the no of rows\n";
			cin >> r1;
			cout << "\nEnter the no of columns\n";
			cin>>c1;
		}
		else
			cout<<"\nWrong";
	}
}

void array::arrA( int n )
{
	cout << "Input the elements\n";
	for( i = 0; i < n; i++ )
	{
		cin >> a[i];
	}
}

void array::arrB( int n )
{
	cout << "Input the elements\n";
	for( i = 0; i < n; i++ )
	{
		cin >> b[i];
	}
}

void array::arrAA( int r, int c )
{
	cout << "Input the elements\n";
	for( i = 0; i < r; i++ )
	{
		cout << "\n";
		for( j = 0; j < c; j++ )
		cin >> f[i][j];
	}
}

void array::arrBB( int r1, int c2 )
{
	cout << "Input the elements\n";
	for( i = 0; i < r1; i++ )
	{
		for( j = 0; j < c1; j++ )
		{
			cin >> e[i][j];
		}
	}
}

void array::dis()
{
	cout << "Enter the array u wanna display";
	cin >> p;
	cout << "The input array is\n";
	switch( p )
	{
		case'a':
		{
			for( i = 0; i < n; i++ )
			{
				cout << a[i] << endl;
			}
		}
		break;

		case'b':
		{
			for( i = 0; i < n; i++ )
			{
				cout << b[i] << endl;
			}
		}
		break;

		case'e':
		{
			for( i = 0; i < r; i++ )
			{
				cout << endl;
				for( j = 0; j < c; j++ )
					cout << f[i][j] << "\t";
			}
		}
		break;

		case'f':
		{
			for( i = 0; i < r1; i++ )
			{
				cout << endl;
				for( j = 0; j < c1; j++ )
					cout << e[i][j] << "\t";
			}
		}
		break;

		default:
			cout << "Wrong choice" << endl;
			break;
	}
}

void array:: pro()
{
	if( d == 1 )
	{
		//did you want to put some code in here to assign t?
		if( t == 0 ) //t is not assigned a value
			arrA( n );
		else
			arrB( n );
	}
	else if( d == 2 )
	{
		if( s == 0 ) //s is not assigned a value
		{
			arrAA( r, c );
			s++;
		}
		else
			arrBB( r1, c1);
	}
	else
		cout << "Wrong choice" << endl;
}

int main()
{
	array w, l;
	w.enter();
	w.pro();
	l.enter(); //guessing you wanted this as l not w
	l.pro(); //guessing you wanted this as l not w
	w.dis();
	l.dis(); //guessing you wanted this as l not w

	system("PAUSE");
	return 0;
}

thanks.....and about s and t......it was to check whether array was being called for the first time or second time...if array was being called first time it would call array a and if second time it would call array b...i did this to prevent overwriting....what i want to ask is...can anything else be done to call an array repeatedly without overwriting.......

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.