Question

Create a class Hugelnteger that uses a 40-element array of digits to store integers as large as 40 digits each. Overload the equality operator Overload the add (i) operator Overload the multiply operator (extra bonus) please do this C++ question asap
0 0
Add a comment Improve this question Transcribed image text
Answer #1
Code for Operator Overloading :

#include <iostream>

using namespace std;

class HugeInteger {
  
double s;
public:
void getnum(double str)
{
this->s=str;
}
void operator==(HugeInteger); // for ==
void operator+(HugeInteger); // for +
void operator*(HugeInteger); // for *
};

void HugeInteger::operator==(HugeInteger ob)
{
if(s==ob.s)
cout<<"\nIntegers are Equal";
else
cout<<"\nIntegers are not Equal";
}

void HugeInteger::operator+(HugeInteger ob)
{
HugeInteger sum;
sum.s=s+ob.s;

printf("The Sum of Integers is %f",sum.s);
}

void HugeInteger::operator*(HugeInteger ob)
{
HugeInteger mul;
mul.s=s*ob.s;

printf("The MUltiplication of Integers is %f",mul.s);
  
}

int main()
{
  
HugeInteger ob, ob1;
double num1, num2;
  

cout<<"Enter First number:";
cin>>num1;

ob.getnum(num1);

cout<<"\nEnter Second Number:";
cin>>num1;

ob1.getnum(num2);

ob==ob1; // Overloading ==
ob+ob1; //Overloading +

ob*ob1; //Overloading *

return 0;
}

Output:

sh-4.2$ main Enter First number:7 Enter Second Number:8 Integers are not Equal

Add a comment
Know the answer?
Add Answer to:
please do this C++ question asap Create a class Hugelnteger that uses a 40-element array of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...

    3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Your program must, at least, contain a function to read and store a number into an...

  • Write a program in C++ that uses a class template to create a set of items....

    Write a program in C++ that uses a class template to create a set of items. . . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of...

  • REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator...

    REQUIREMENTS: Problem Description: Create a Dynamic 2D Array Class. This class should overload the Call Operator () for the following behaviors: Return (modifiable) Lvalue element for a non-const object Return (read-only) Rvalue element for a const object Return a copy of the data values for row Return a copy of all the data as a 1D vector Create a TestScores Class which uses a Dynamic 2D Array object as an internal data structure. This class should have the following behaviors:...

  • Can anyone please write the code for this.

    Create a class Huge Integer that uses a40-elementarray of digits to Store integers as large as 40 digits each. Provide member functions input, output, add and subtract. For comparing Huge Integer objects, provide functions is Equal To, is Not Equal To, is Greater Than, Is Less Than, is Greater Than Or Equal To and is Less Than Or Equal To—each of these is a “predicate” function that simply returns true if the relationship holds between the two Huge Integers and...

  • How to solve this Problem in C++ . The Problem Write program that uses a class...

    How to solve this Problem in C++ . The Problem Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the set...

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • Create a class for working with complex numbers. Only 2 private float members are needed, the...

    Create a class for working with complex numbers. Only 2 private float members are needed, the real part of the complex number and the imaginary part of the complex number. The following methods should be in your class: a. A default constructor that uses default arguments in case no initializers are included in the main. b. Add two complex numbers and store the sum. c. Subtract two complex numbers and store the difference. d. Multiply two complex numbers and store...

  • Your goal is to create an ‘Array’ class that is able to hold multiple integer values....

    Your goal is to create an ‘Array’ class that is able to hold multiple integer values. The ‘Array’ class will be given functionality through the use of various overloaded operators You will be given the main() function for your program and must add code in order to achieve the desired result. Do not change any code in main(). If something is not working, you must change your own code, not the code in main(). Assignment 5: overloading member functions. Overview:...

  • Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the...

    Write C++ program (studentsGpa.cpp) uses dynamic allocation to create an array of strings. It asks the user to enter a number and based on the entered number it allocates the array size. Then based on that number it asks the user that many times to enter student’s names. What you need to do:  Add another array of doubles to store the gpa of each student as you enter them  You need to display both the student’s name and...

  • In C++, develop a class that supports array rotation. Rotating an array is an operation where...

    In C++, develop a class that supports array rotation. Rotating an array is an operation where you shift all elements of the array some number of positions left or right, and elements that are shifted off of the left or right end of the array "wrap around" to the right or left end, respectively. For example, if we rotate the array [1, 2, 3, 4, 5] to the right by 1, we get the array [5, 1, 2, 3, 4]....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT