Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <<<<<<<<<<<<<<<<<Mangdong.h>>>>>>>>>>>>>>>>
- #pragma once
- #include <iostream>
- using namespace std;
- class CArrayInt
- {
- public:
- CArrayInt(int);
- ~CArrayInt();
- void input();
- void output();
- void sort();
- int second();
- private:
- int n;
- int *arr;
- };
- <<<<<<<<<<<<<<<<<<.MangDong.cpp>>>>>>>>>>>>>>>>>>>
- #include "CArrayInt.h"
- void CArrayInt::input() {
- cout << "Nhap kich thuoc cua mang: ";
- cin >> n;
- arr = new int[n];
- for (int i = 0; i < n; i++) {
- cout << "Nhap vao phan tu thu " << i << " la: ";
- cin >> arr[i];
- }
- }
- void CArrayInt::output() {
- for (int i = 0; i < n; i++) {
- cout << " " << arr[i];
- }
- cout << endl;
- }
- void CArrayInt::sort() {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- if (arr[i] > arr[j]) {
- swap(arr[i], arr[j]);
- }
- }
- }
- }
- int CArrayInt::second() {
- for (int i = 0; i < n - 1; i++) {
- for (int j = i + 1; j < n; j++) {
- if (arr[i] > arr[j]) {
- swap(arr[i], arr[j]);
- }
- }
- }
- return arr[n - 2];
- }
- CArrayInt::CArrayInt(int soluong) {
- n = soluong;
- arr = new int[n];
- for (int i = 0; i < n; i++)
- {
- arr[i] = 0;
- }
- }
- CArrayInt::~CArrayInt() {
- delete[] arr;
- }
- <<<<<<<<<<<<<<<<<<<<<main.cpp>>>>>>>>>>>>>>>>>>>>
- #include"CArrayInt.h"
- int main() {
- CArrayInt arr(10);
- arr.input();
- cout << "Arry Not Sort: ";
- arr.output();
- cout << "Array Sort: ";
- arr.sort();
- arr.output();
- cout << "Seccond: " << arr.second();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement