#include using namespace std; class linears { protected: int n; public: int item,i,s=0,a; linears() { cout<<"Enter Array length :"<>a; n=a; } ~linears() { cout<<"Default destructor created "<>a[i]; } cout<<"Enter your element to search : "<>item; for(i=0;i<n;i++) { if(a[i]==item){ cout<<"Your element found on " << i <<" "<<"position"<< endl; s=1; break; } } if(s==0) cout<<"Item is not in your array ."<<endl; }
#include using namespace std; class linear { public: int data[10]={22,1,43,23,99,3,77,11,55,65}; int n=10,k=0,item=11,loc=-1; linear() { while(loc==-1 && k<n) { if(item==data[k]) loc=k; k+=1; } } ~ linear() { cout<<"Destructing";
} int print(); }; int linear::print() { if(loc==-1) cout<<"Item is not in array"<<endl; else cout<<"The location of item is: "<<loc<<endl; } int main() { linear l; l.print(); }
#include
ReplyDeleteusing namespace std;
class linears
{
protected:
int n;
public:
int item,i,s=0,a;
linears()
{
cout<<"Enter Array length :"<>a;
n=a;
}
~linears()
{
cout<<"Default destructor created "<>a[i];
}
cout<<"Enter your element to search : "<>item;
for(i=0;i<n;i++)
{
if(a[i]==item){
cout<<"Your element found on " << i <<" "<<"position"<< endl;
s=1;
break;
}
}
if(s==0)
cout<<"Item is not in your array ."<<endl;
}
};
int main()
{
equ obj;
obj.get_v();
}
#include
ReplyDeleteusing namespace std;
class Search
{
public:
int n,i,item,flag=0;
int a[];
Search()
{
cout<<"Enter your array length:"<>n;
cout<<"Enter your array elements:"<>a[i];
}
for(i=0;i>item;
for(i=0;i<n;i++)
{
if(item==a[i])
{
flag=1;
cout<<"Item found in: "<<i<<" location"<<endl;
}
}
if(flag==0)
cout<<"Item not found"<<endl;
}
~Search()
{
cout<<"Distructor"<<endl;
}
};
int main()
{
Search s;
s.met();
}
#include
ReplyDeleteusing namespace std;
class linear
{
public:
int data[10]={22,1,43,23,99,3,77,11,55,65};
int n=10,k=0,item=11,loc=-1;
linear()
{
while(loc==-1 && k<n)
{
if(item==data[k])
loc=k;
k+=1;
}
}
~ linear()
{
cout<<"Destructing";
}
int print();
};
int linear::print()
{
if(loc==-1)
cout<<"Item is not in array"<<endl;
else
cout<<"The location of item is: "<<loc<<endl;
}
int main()
{
linear l;
l.print();
}