fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Bai1 {
  5. private:
  6. double* arr;
  7. int sl;
  8. public:
  9. ~Bai1() {
  10. delete[] arr;
  11. sl = 0;
  12. arr = nullptr;
  13. }
  14. Bai1(int s = 0) {
  15. sl = s;
  16. arr = new double[sl];
  17. }
  18. void Nhap() {
  19. cin >> sl;
  20. arr = new double[sl];
  21. for (int i = 0; i < sl; i++) {
  22. cin >> arr[i];
  23. }
  24. }
  25. void Xuat() {
  26. for (int i = 0; i < sl; i++) {
  27. cout << arr[i] << " ";
  28. }
  29. cout << "\n";
  30. }
  31. void Tim(double x) {
  32. bool tim_thay = false;
  33. for (int i = 0; i < sl; i++) {
  34. if (arr[i] == x) {
  35. tim_thay = true;
  36. break;
  37. }
  38. }
  39. if (tim_thay) cout << "Ton tai " << x << " trong mang!\n";
  40. else cout << "Khong ton tai " << x << " trong mang!\n";
  41. }
  42. void Tong() {
  43. double tong = 0;
  44. for (int i = 0; i < sl; i++) {
  45. tong += arr[i];
  46. }
  47. cout << "Tong la " << tong << "\n";
  48. }
  49. void Thong_ke() {
  50. for (int i = 0; i < sl; i++) {
  51. bool tim_thay = false;
  52. for (int j = 0; j < i; j++) {
  53. if (arr[i] == arr[j]) {
  54. tim_thay = true;
  55. break;
  56. }
  57. }
  58. if (!tim_thay) {
  59. int dem = 0;
  60. for (int j = i; j < sl; j++) {
  61. if (arr[i] == arr[j]) {
  62. dem++;
  63. }
  64. }
  65. cout << "So lan xuat hien cua " << arr[i] << " trong mang: " << dem << "\n";
  66. }
  67. }
  68. }
  69. };
  70.  
  71. int main() {
  72. Bai1 a;
  73. a.Nhap();
  74. a.Xuat();
  75. double x; cin >> x;
  76. a.Tim(x);
  77. a.Tong();
  78. a.Thong_ke();
  79. return 0;
  80. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Khong ton tai 4.64724e-310 trong mang!
Tong la 0