Answer to Question #273642 in C++ for Elena

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.


1
Expert's answer
2021-12-01T00:52:29-0500
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS