bsc

Comprehensive codebase and cou...
Log | Files | Refs | README | LICENSE

pgrm_007.cpp (1311B)


      1 /*
      2  * Author: Amit Dutta <amitdutta4255@gmail.com> | Date: 06 Jul 2026
      3  * Repo: https://github.com/notamitgamer/bsc
      4  * License: MIT
      5  */
      6 
      7 /* Right a program to calculate sum and product of array elements. */
      8 
      9 #include <iostream>
     10 using namespace std;
     11 
     12 class ArrayOperations {
     13     private:
     14         int *arr;
     15         int n;
     16 
     17     public:
     18         int i;
     19         ArrayOperations(int size) {
     20             n = size;
     21             arr = new int[n];
     22         }
     23 
     24         void getData() {
     25             for (i = 0; i < n; i++) {
     26                 cout << "Enter element " << i + 1 << ": ";
     27                 cin >> arr[i];
     28             }
     29         }
     30 
     31         int add() {
     32             int sum = 0;
     33             for (i = 0; i < n; i++) {
     34                 sum += arr[i];
     35             }
     36             return sum;
     37         }
     38 
     39         long product() {
     40             long prod = 1;
     41             for (i = 0; i < n; i++) {
     42                 prod *= arr[i];
     43             }
     44             return prod;
     45         }
     46 
     47         void display() {
     48             cout << "sum = " << add() << endl;
     49             cout << "product = " << product() << endl;
     50         }
     51 
     52         ~ArrayOperations() {
     53             delete[] arr;
     54         }
     55 };
     56 
     57 int main() {
     58     int n;
     59     cout << "Enter size: ";
     60     cin >> n;
     61     ArrayOperations ao(n);
     62     ao.getData();
     63     ao.display();
     64     return 0;
     65 }
© notamitgamer • Site Built: 2026-07-21 13:58:23 UTC • git-mirror commit: 1037f62 [view raw info]
Originally created with stagit • modified by notamitgamer
Forked from github.com/notamitgamer/git-mirror