Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <iostream>
- using namespace std;
- #pragma hdrstop
- template <class T1>
- class X {
- protected:
- T1 *mas;
- int size;
- public:
- X(int n) {
- size = n;
- mas = new T1[n];
- for(int i=0; i < n; i++) {
- cout « "Enter a[" « i « "]: ";
- cin » mas[i];
- }
- }
- void run() {
- T1 sum = 0;
- for(int i=0; i < size; i++) {
- sum += mas[i];
- mas[i] = sum;
- }
- }
- void Print(void) {
- cout « "Array:" « endl;
- for(int i=0; i<size; i++) {
- cout « "a[" « i « "] = " « mas[i] « endl;
- }
- }
- ~X() {
- delete mas;
- }
- };
- int main(int argc, char* argv[])
- {
- int n;
- cout « "Enter N: ";
- cin » n;
- cout « endl;
- X < int > MyInt(n);
- MyInt.run();
- MyInt.Print();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement