fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class class1
  5. {
  6. public:
  7. int n;
  8. double* arr = new double[n];
  9. void get();
  10. void sort_ascend();
  11. void display();
  12. };
  13.  
  14. void class1::get()
  15. {
  16. cout << "Enter the number of elements in the array: ";
  17. cin >> n;
  18. cout << "Enter the elements one by one: ";
  19. for (int i = 0; i < n; i++)
  20. {
  21. cin >> arr[i];
  22. }
  23. }
  24.  
  25. void class1::sort_ascend()
  26. {
  27. for (int j = 0; j < n - 1; j++)
  28. {
  29. for (int k = j + 1; k < n; k++)
  30. {
  31. if (arr[j] > arr[k])
  32. {
  33. int t;
  34. t = arr[j];
  35. arr[j] = arr[k];
  36. arr[k] = t;
  37. }
  38. }
  39. }
  40. }
  41.  
  42. void class1::display()
  43. {
  44. cout << "The array after sorting in ascending order is: {";
  45.  
  46. for (int i = 0; i < n; i++)
  47. {
  48. cout << arr[i];
  49. if (i != n - 1)
  50. {
  51. cout << ", ";
  52. }
  53. }
  54. cout << "}";
  55. }
  56.  
  57. int main()
  58. {
  59. class1 a;
  60. a.get();
  61. a.sort_ascend();
  62. a.display();
  63. }
Success #stdin #stdout 0s 5284KB
stdin
5
-8.65
9.66
8.5
12
0
stdout
Enter the number of elements in the array: Enter the elements one by one: The array after sorting in ascending order is: {-8.65, 0, 8, 9, 12}