---
title: "LandMeasure class and sum function"
subject: "Object Oriented Programming"
chapter: 4
key: "semester_3/object_oriented_programming:landmeasure-class-sum"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/landmeasure-class-sum
site: BCT Engineering
---

# LandMeasure class and sum function

Object Oriented Programming · Chapter 4: Objects and Classes

- Asked in: 2068 Chaitra, 6 marks
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/landmeasure-class-sum
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-4

## Question

Write a program to create a class LandMeasure that reads Ropani, Ana, Paisa and Dam as data members. Write a function to pass two objects of type Land Measure and return their sum. (16 Ana = 1 Ropani, 4 Paisa = 1 Ana, 4 Dam = 1 Paisa)

## Short answer

The sum function adds corresponding units, carrying from Dam to Paisa (4:1), Paisa to Ana (4:1), and Ana to Ropani (16:1). For inputs 2 10 3 3 and 1 7 2 2, the sum is 4 Ropani, 2 Ana, 2 Paisa, 1 Dam.

## Answer

Conversion rules: 4 Dam = 1 Paisa, 4 Paisa = 1 Ana, 16 Ana = 1 Ropani. In the sum, add each unit and carry from Dam upward: Dam carries to Paisa at 4, Paisa to Ana at 4, Ana to Ropani at 16.

```cpp
#include <iostream>
using namespace std;

class LandMeasure
{
    int ropani, ana, paisa, dam;
public:
    void read()
    {
        cout << "Enter Ropani, Ana, Paisa, Dam: ";
        cin >> ropani >> ana >> paisa >> dam;
    }
    void display()
    {
        cout << ropani << " Ropani " << ana << " Ana "
             << paisa << " Paisa " << dam << " Dam" << endl;
    }
    // takes two objects and returns their sum
    friend LandMeasure sum(LandMeasure, LandMeasure);
};

LandMeasure sum(LandMeasure a, LandMeasure b)
{
    LandMeasure t;
    t.dam = a.dam + b.dam;
    t.paisa = a.paisa + b.paisa + t.dam / 4;
    t.dam = t.dam % 4;
    t.ana = a.ana + b.ana + t.paisa / 4;
    t.paisa = t.paisa % 4;
    t.ropani = a.ropani + b.ropani + t.ana / 16;
    t.ana = t.ana % 16;
    return t;
}

int main()
{
    LandMeasure l1, l2, l3;
    l1.read();
    l2.read();
    l3 = sum(l1, l2);
    cout << "Sum = ";
    l3.display();
    return 0;
}
```

#### Sample run

```text
Enter Ropani, Ana, Paisa, Dam: 2 10 3 3
Enter Ropani, Ana, Paisa, Dam: 1 7 2 2
Sum = 4 Ropani 2 Ana 2 Paisa 1 Dam
```

Check: Dam 3+2 = 5 gives 1 Dam, carry 1. Paisa 3+2+1 = 6 gives 2 Paisa, carry 1. Ana 10+7+1 = 18 gives 2 Ana, carry 1. Ropani 2+1+1 = 4.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. How many Paisa are in one Ana per the question?
   A. 2
   B. 4
   C. 16
   D. 8
   Answer: B. 4 Paisa = 1 Ana. (Key point: Conversion rules)

2. In the sum, in which order are units added with carry?
   A. Ropani to Dam
   B. Dam upward to Paisa, Ana, Ropani
   C. Ana first
   D. Any order
   Answer: B. Carry goes from the smallest unit upward: Dam to Paisa at 4, Paisa to Ana at 4, Ana to Ropani at 16. (Key point: Carry direction)

3. How is Ropani computed in sum()?
   A. a.ropani + b.ropani + t.ana / 16
   B. a.ropani + b.ropani
   C. t.ana % 16
   D. a.ropani * b.ropani
   Answer: A. Ana beyond 16 carries to Ropani using integer division by 16, and Ana keeps the remainder. (Key point: Ana carry)

4. Adding 2 Ropani 10 Ana 3 Paisa 3 Dam and 1 Ropani 7 Ana 2 Paisa 2 Dam gives?
   A. 3 Ropani 17 Ana 5 Paisa 5 Dam
   B. 4 Ropani 2 Ana 2 Paisa 1 Dam
   C. 4 Ropani 1 Ana 2 Paisa 1 Dam
   D. 3 Ropani 2 Ana 2 Paisa 1 Dam
   Answer: B. Dam 5 gives 1 carry 1; Paisa 6 gives 2 carry 1; Ana 18 gives 2 carry 1; Ropani 4. (Key point: Sample sum)

## Related in Object Oriented Programming

- [Time class: add two objects](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Atime-class-add-objects) — Object Oriented Programming, chapter 1
- [Add objects of two different classes](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Afriend-add-two-class-objects) — Object Oriented Programming, chapter 4, asked 2×
- [Access overridden members from derived class](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aaccess-overridden-members) — Object Oriented Programming, chapter 6, asked 2×
- [Abstract Student class program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Astudent-abstract-program) — Object Oriented Programming, chapter 7
- [Effect of derivation types on class members](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aderivation-types-effect) — Object Oriented Programming, chapter 6
- [City class with operator overloading](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Acity-class-operator-overload) — Object Oriented Programming, chapter 5

## Related in other subjects

- [C program: sum of two 8-bit BCD numbers](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-bcd-sum-c) — Embedded System, chapter 9
- [Function definition; sum of two numbers](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afunction-definition-sum-two) — Computer Programming, chapter 6
- [8085 ALP: compare two tables of 16-bit data](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aalp-8085-compare-tables-1ffffh) — Microprocessor, chapter 2
- [Create classes from design class diagrams](https://www.bctengineer.com/question.md?key=semester_6%2Fobject_oriented_analysis_and_design%3Aclasses-from-design-class-diagram) — Object Oriented Analysis and Design, chapter 4, asked 2×
