Question #273642

Create a class called 'Octal' that has data members for integer and decimal, a

constructor to initialize the object to some constant value using at least one implicit

and another explicit way of initialization, member function to add three Octal objects

along with also have at least one default argument, suitable member function to

display octal value in interger.decimal format. Write a main function to create three

Octal objects, add them and display the result in interger.decimal format.


Expert's answer

#include <iostream>
#include <iomanip>
using namespace std;


class Octal {        // The class
  public:          // Access specifier
    int a;  // Attribute
    float b;  // Attribute
        // Attribute
    &#39;Octal&#39;(int x, float y) { // Constructor with parameters
      a = x;
      b(y));
    }
    int octal_sum(int a,int b) {
    int sum=0, carry=0, d=0, m = 1;
    while(a || b || carry) {
        d=0;
        d=carry+(a%10)+(b%10);
        a/=10;b/=10;
        if(d>7) {
            carry=1;
            d=d%8;
        } else {
            carry = 0;
        }
        sum += d*m;
        m *= 10;
    }
   return sum;     //returns octal sum of a and b
}
};
int main(){
	Octal obj1;
	Octal obj2;
	
    obj1.octal_sum();
	
	return 0;
}

LATEST TUTORIALS
APPROVED BY CLIENTS