// Addition of two vectors, who are dynamically allocated and deallocated. // Assignment-02 // vectsum.cpp, Author - Krishna Kumar Khatri. // Uncomment ONLY the following line if you are using Turbo/Borland compiler. // #define TC #ifdef TC #include #else #include using namespace std; #endif #include // For getch. int main() { #ifdef TC clrscr(); #endif const int MAX = 5; int* vect1 = new int[MAX]; int* vect2 = new int[MAX]; static int* vectres = new int[MAX]; int vectsize = 0; int i; do { cout << "What is the size of vector (1-" << MAX << "): "; cin >> vectsize; } while (vectsize < 1 || vectsize > MAX); cout << "Enter " << vectsize << " elements for vector-1: "; for (i = 0; i < vectsize; i++) { cin >> vect1[i]; vectres[i] += vect1[i]; } cout << "Now enter " << vectsize << " elements for vector-2: "; for (i = 0; i < vectsize; i++) { cin >> vect2[i]; vectres[i] += vect2[i]; } cout << endl << endl << "The resultant vector is, "; for (i = 0; i < vectsize; i++) (i + 1) != vectsize ? cout << vectres[i] << ", " : cout << vectres[i]; cout << endl; cout << endl << endl << "Program over. Press any key to exit..."; getch(); return 0; // Successful termination. }