fork download
  1. #include<iostream>
  2. #include<stdio.h>
  3. #define MAX 10
  4. using namespace std:
  5. class array adt
  6. {
  7. public
  8. int a,i,size,n,p,e,f,pos,b[20],x;
  9. void create()
  10. {
  11. cout<<"Creating a list\n";
  12. cout<<"enter the size of the array:";
  13. cin>>size;
  14. for (i=0;i<size:i++)
  15. {
  16. cin>>b[i]
  17. }
  18. }
  19. void is full()
  20. {
  21. if (size==0)
  22. {
  23. cout<<"the array is empty:\n";
  24. }
  25. else
  26. {
  27. cout<<"the array is full:\n";
  28. }
  29. }
  30. void isempty()
  31. {
  32. if (size==0)
  33. {
  34. cout<<"the array is empty\n";
  35. }
  36. else
  37. {
  38. cout<<"the array is full\n";
  39. }
  40. }
  41. void insert()
  42. {
  43. cout<<:Enter the position of the array for the element to be inserted:";
  44. cin>>pos;
  45. if(pos>=size)
  46. {
  47. cout<<"invalid position\n";
  48. }
  49. else
  50. {
  51. for(i=MAX:i>=pos;i--)
  52. {
  53. b[i]=b[i-1];
  54. }
  55. cout<<"enter the element to be inserted;\n";
  56. cin>>p;
  57. b[pos]=p:size++;
  58. }
  59. cout<<"list after insertion\n";
  60. for(i=0:i<size:i++)
  61. {
  62. cout<<b[i]<<"it";
  63. }
  64. }
  65. void delete()
  66. {
  67. cout<<"\n enter the position of the array for the element to be deleted:";
  68. cin>>pos;
  69. if(Pos>=size)
  70. {
  71. cout<<"invalid position\n";
  72. }
  73. else
  74. {
  75. for(i=pos+1;i<size;i++)
  76. {
  77. b[i-1}=b[i];
  78. }
  79. size--;
  80. }
  81. cout<<"the list after deletion\n";
  82. for(i=0:i<size:i++)
  83. {
  84. cout<<b[i]<<"it";
  85. }
  86. }
  87. void find()
  88. {
  89. cout<<"\n enter the element to be searched:";
  90. cin>>x;
  91. for(i-0;i<size;i==)
  92. {
  93. cout<<"element is at position:"<<i<<"\n";
  94. }
  95. }
  96. }
  97. void find KTH()
  98. {
  99. cout<<"enter the position of to be searched:";
  100. cin>>e;
  101. cout<<"the element at the given position is:"<<b[e]<<"\n";
  102. }
  103. void print()
  104. cout<<"the final array\n";
  105. for(i=0;i<size;i++)
  106. }
  107. }
  108. };
  109. int main()
  110. {
  111. array adt obj;
  112. obj.create();
  113. obj.isfull();
  114. obj.isempty(;
  115. obj.delete();
  116. obj.find();
  117. obj.findKTH();
  118. obj.print();
  119.  
Success #stdin #stdout 0.03s 25852KB
stdin
Standard input is empty
stdout
#include<iostream>
#include<stdio.h>
#define MAX 10
using namespace std:
class array adt
{
  public
    int a,i,size,n,p,e,f,pos,b[20],x;
  void create()
	{
      cout<<"Creating a list\n";
      cout<<"enter the size of the array:";
      cin>>size;
	  for (i=0;i<size:i++)
	  {
		cin>>b[i]
	  }
    }
    void is full()
    {
    	if (size==0)
	{
	  cout<<"the array is empty:\n";
	}
	else
	{
	  cout<<"the array is full:\n";
	}
  }
  void isempty()
  {
  	if (size==0)
	  {
	  	cout<<"the array is empty\n";	
	  }
      else
      {
      	cout<<"the array is full\n";
      }
	}
	void insert()
	{
      cout<<:Enter the position of the array for the element to be inserted:";
	  cin>>pos;
	  if(pos>=size)
	  {
	  cout<<"invalid position\n";
	  }
      else
      {
        for(i=MAX:i>=pos;i--)
       	{
       	  b[i]=b[i-1];
		}
     cout<<"enter the element to be inserted;\n";
     cin>>p;
     b[pos]=p:size++;
     }
    cout<<"list after insertion\n";
    for(i=0:i<size:i++)
     {
  	cout<<b[i]<<"it";
  }
}
void  delete()
{
cout<<"\n enter the position of the array for the element to be deleted:";
cin>>pos;
if(Pos>=size)
{
	cout<<"invalid position\n";
}
else
{
	for(i=pos+1;i<size;i++)
	{
		b[i-1}=b[i];
    }
    size--;
}
cout<<"the list after deletion\n";
for(i=0:i<size:i++)
{
	cout<<b[i]<<"it";
  }
}
void find()
{
	cout<<"\n enter the element to be searched:";
	cin>>x;
	for(i-0;i<size;i==)
	{
		cout<<"element is at position:"<<i<<"\n";	
	}
}
}
void find KTH()
{
	cout<<"enter the position of to be searched:";
	cin>>e;
	cout<<"the element at the given position is:"<<b[e]<<"\n";
}
void print()
cout<<"the final array\n";
for(i=0;i<size;i++)
  }
 }
};
int main()
{
	array adt obj;
	obj.create();
	obj.isfull();
	obj.isempty(;
	obj.delete();
	obj.find();
	obj.findKTH();
	obj.print();