Pages

Thursday, May 29, 2025

D. Create a C++ class template named Pair that represents a pair of values. (University Topic of OOPs)

#include <iostream>

#include <string>

#include <vector>

using namespace std;


// D. Create a C++ class template named Pair that represents a pair of values. 


template <typename T>


class Pair {

private:

    T A1;

    T A2;

    

public:

    Pair(T val1,T val2) {

        A1 = val1;  // initialize first ehe private variable then the Public variable

        A2 = val2;


    }

    

    // display

    void display() {

        cout << "value A: " << A1 << " \nvalue B: " << A2 << endl;

    }

};





int main() {

    int x, y;

    cout << "enter first value : ";

    cin >> x;

        

    cout << "enter second value : ";

    cin >> y;

    

    Pair<int> class1(x, y);

    

    class1.display();

    

    return 0;

}

No comments:

Post a Comment

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...