#include<iostream.h>
#include<conio.h>
#include<string.h>
class X
{public:
int a[50],n;
char b[20];
char name[20];
void input()
{
 cout<<"Enter the limit upto which you want to enter ";
 cin>>n;
 cout<<"Enter the numbers ";
 for(int i=0;i<n;i++)
 {
  cin>>a[i];
 }
 cout<<"\n enter the string";
 cin>>b;
}
void large()
{
 int c;
 c=a[0];
 for(int i=1;i<n;i++)
 {
 if(c<a[i])
 c=a[i];
 }
 cout<<"Largest element is the array is "<<c;
}
void palin()
{
 int o,m,flag=0;
 o=strlen(b);
 m=o/2;
 for(int i=0;i<=m;i++)
 {
  if(b[i]!=b[o-1-i])
  { flag=1;
  }
 }
 if(flag==1)
 cout<<"\n String is not palindrome";
 else
 cout<<"\n String is palindrome";
 }
 void ninput()
 {
  cout<<"\n enter the name ";
  cin>>name;
  }
 void noutput()
 {
 cout<<"\n"<<name;
}
 };
void main()
{ int f,i,j;
  char temp[100],h;
 X *a[50];
 a[0]=new X;
 a[0]->input();
 a[0]->palin();
 a[0]->large();
 cout<<"\n Enter how many names you want to enter ";
 cin>>f;
 for(i=0;i<f;i++)
 {a[i]=new X;
 a[i]->ninput();
 }
 for(i=1;i<f;i++)
 {strcpy(temp,a[i]->name);
  h=a[i]->name[0];
  j=i-1;
  while((h<a[j]->name[0])&&(j>=0))
  {
  strcpy(a[j+1]->name,a[j]->name);
  j--;
  }
  strcpy(a[i]->name,temp);
  }
 cout<<"\n the sorted name list is as";
 for(i=0;i<f;i++)
 {
 a[i]->noutput();
 }
 getch();
 }

what is the error?

line 66: what if I enter a value of 500? Your program will blow up with that. You need to put a check in there to make sure its a value between 0 and 50.

Edited 4 Years Ago by Ancient Dragon

Maybe you should put the check for j being greater than zero first. You might be trying to access a negative index. Have you printed out j to check what the value is?

Hello
Greetings to all members of this community.I am new member here..
nice to meet you all…….
compile time error....

@ jainny - If you are having a problem start a new thread and post what you issue is. compile time error is not enough information. You have to show your code and also what the error is.

This article has been dead for over six months. Start a new discussion instead.