fork(1) download
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4.  
  5. class vecto{
  6. private:
  7. int *a;
  8. int n;
  9. public:
  10. void nhapbp();
  11. void xemmh();
  12. vecto operator+(vecto);
  13. };
  14. void vecto::nhapbp(){
  15. cout<<"Nhap so luong phan tu cua vector: "; cin>>n;
  16. a = new int[n];
  17. for(int i=0; i<n; i++){
  18. cin>>a[i];
  19. }
  20. }
  21. void vecto::xemmh(){
  22. for(int i=0; i<n; i++){
  23. cout<<a[i]<<" ";
  24. }
  25. }
  26.  
  27. }
  28. vecto vecto::operator+(vecto v){
  29. vecto m;
  30. for(int i=0; i<v.n; i++){
  31. m.a[i] = this->a[i]+v.a[i];
  32. }
  33. return m;
  34. }
  35.  
  36. int main(){
  37. vecto a;
  38. vecto b;
  39.  
  40. a.nhapbp();
  41. a.xemmh();
  42.  
  43. cout<<endl;
  44.  
  45. b.nhapbp();
  46. b.xemmh();
  47.  
  48. vecto tong=a+b;
  49. tong.xemmh();
  50.  
  51. return 0;
  52. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
3
1 2 3
3
-1 0 1
compilation info
prog.cpp:27:1: error: expected declaration before ‘}’ token
 }
 ^
stdout
Standard output is empty