-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.cpp
62 lines (62 loc) · 1014 Bytes
/
array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include<iostream>
#include<stdlib.h>
using namespace std;
class array{
int n;
int *a;
public :
void nhap();
void xuat();
int sosanh(array b);
array tong(array b);
};
void array::nhap(){
cout<<"Nhap so luong phan tu mang: ";
cin>>n;
a = new int [n];
for(int i=0;i<n;i++){
cout<<"Nhap phan tu thu "<<i<<":";
cin>>a[i];
}
cout<<endl;
}
void array::xuat(){
cout<<"Phan tu cua mang la: "<<endl;
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
}
int array::sosanh(array b){
if(n!=b.n)
return 0;
for(int i=0;i<n;i++)
if(a[i]!=b.a[i])
return -1;
return 1;
}
array array::tong(array b){
array c;
if(n!=b.n)
exit(0);
for(int i=0;i<n;i++)
c.a[i]=a[i]+b.a[i];
return c;
}
int main(){
array a,b,c;
a.nhap();
b.nhap();
a.xuat();
b.xuat();
if(a.sosanh(b)==0)
cout<<"2 mang co kich thuoc khac nhau";
if(a.sosanh(b)==-1)
cout<<"2 mang khac nhau";
if(a.sosanh(b)==1)
cout<<"2 mang bang nhau";
cout<<endl;
cout<<"Tong 2 mang la: ";
c=a.tong(b);
c.xuat();
return 0;
}