Advertisement
Guest User

Untitled

a guest
May 26th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6. #pragma hdrstop
  7.  
  8. template <class T1>
  9. class X {
  10. protected:
  11. T1 *mas;
  12. int size;
  13. public:
  14. X(int n) {
  15. size = n;
  16. mas = new T1[n];
  17. for(int i=0; i < n; i++) {
  18. cout « "Enter a[" « i « "]: ";
  19. cin » mas[i];
  20. }
  21. }
  22.  
  23. void run() {
  24. T1 sum = 0;
  25. for(int i=0; i < size; i++) {
  26. sum += mas[i];
  27. mas[i] = sum;
  28. }
  29. }
  30.  
  31. void Print(void) {
  32. cout « "Array:" « endl;
  33. for(int i=0; i<size; i++) {
  34. cout « "a[" « i « "] = " « mas[i] « endl;
  35. }
  36. }
  37.  
  38. ~X() {
  39. delete mas;
  40. }
  41. };
  42.  
  43.  
  44.  
  45. int main(int argc, char* argv[])
  46. {
  47. int n;
  48. cout « "Enter N: ";
  49. cin » n;
  50. cout « endl;
  51.  
  52. X < int > MyInt(n);
  53. MyInt.run();
  54. MyInt.Print();
  55.  
  56.  
  57. system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement