Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ that implements the Decimal data type using a class calle

ID: 3667190 • Letter: W

Question

Write a program in C++ that implements the Decimal data type using a class called SmallDecimal. This class will allow users to create positive decimal values ( 0) and perform arithmetic operations on these values. The class should use three integer member variables

- the integer part saved as an integer

- the decimal part saved as an integer

- index: the number of digits after the decimal point

For example, the following instance SmallDecimal d("6.45678"); will store 6 in the first variable, 45678 in the second variable and 5 (the number of digits after the decimal point) in the last variable.

The class should have the following functionalities

Explanation / Answer

Here is the class for you, with just the basic functionality.

#include <iostream>
using namespace std;
class SmallDecimal
{
int integer;
int decimal;
int index;
public:
SmallDecimal()
{
integer = 0;
decimal = 0;
index = 1;
}
SmallDecimal(int i, int dec, int ind)
{
integer = i;
decimal = dec;
index = ind;
}
void setInteger(int i)
{
integer = i;
}
void setDecimal(int dec)
{
decimal = dec;
}
void setIndex(int ind)
{
index = ind;
}
int getInteger()
{
return integer;
}
int getDecimal()
{
return decimal;
}
int getIndex()
{
return index;
}
void displayNumber()
{
cout<<"The decimal number is: "<<integer<<"."<<decimal%(index*10)<<endl;
}
};

If you need any further refinement, just get back to me.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote