#include<iostream>
using namespace std;

class weight {
    int kilogram;
    int gram;
public:
    void getdata();
    void putdata();
    weight sum_weight(weight);
};

void weight::getdata() {
    cout << "Enter weight in kilograms and grams:\n";
    cout << "Kilogram: ";
    cin >> kilogram;
    cout << "Gram: ";
    cin >> gram;
}

void weight::putdata() {
    cout << "Weight: " << kilogram << " kilograms " << gram << " grams\n";
}

weight weight::sum_weight(weight W2) {
    weight temp;
    temp.gram = gram + W2.gram;
    temp.kilogram = temp.gram / 1000;
    temp.gram = temp.gram % 1000;
    temp.kilogram += kilogram + W2.kilogram;
    return temp;
}

int main() {
    weight W1, W2, W3;
    cout << "Enter weight #1:\n";
    W1.getdata();
    cout << "Enter weight #2:\n";
    W2.getdata();
    W3 = W1.sum_weight(W2);
    cout << "Total weight: ";
    W3.putdata();
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: