#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();
}
rajat.sethi93
-3
Newbie Poster
Recommended Answers
Jump to Postwhat 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.
Jump to PostMaybe 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?
All 6 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
rajat.sethi93
-3
Newbie Poster
rajat.sethi93
-3
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
jainny
0
Newbie Poster
NathanOliver
429
Veteran Poster
Featured Poster
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.