1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
aalyn [17]
3 years ago
14

Create a class HugeInteger which uses a vector of digits to store huge integers. A HugeInteger object has a sign that indicates

if the represented integer is non-negative (0) or negative (1). Provide methods parse, toString, add and subtract. Method parse should receive a String, extract each digit using method charAt and place the integer equivalent of each digit into the integer vector. For comparing HugeInteger objects, provide the following methods: isEqualTo, isNotEqualTo, isGreaterThan, isLessThan, isGreaterThanOrEqualTo, and isLessThanOrEqualTo. Each of these is a predicate method that returns true if the relationship holds between the two HugeInteger objects and returns false if the relationship does not hold. Provide a rpedicate method isZero.
Computers and Technology
1 answer:
Elan Coil [88]3 years ago
3 0

Answer:

#include "hugeint1.h"

#include

using namespace std;

int main()

{

HugeInteger n1( 7654321 );

HugeInteger n2( 7891234 );

HugeInteger n3;

HugeInteger n4( 5 );

HugeInteger n5;

n5 = n1.add( n2 );

n1.output();

cout << " + "; n2.output();

cout << " = "; n5.output();

cout << "\n\n";

n5 = n2.subtract( n4 );

n2.output();

cout<< " - "; n4.output();

cout << " = "; n5.output();

cout << "\n\n";

if ( n1.isEqualTo( n1 ) == true )

{

 n1.output();cout << " is equal "; n1.output(); cout << "\n\n";

}

if ( n1.isNotEqualTo( n2 ) == true )

{

 n1.output();cout << " is not equal to ";n2.output();cout << "\n\n";

}

if ( n2.isGreaterThan( n1 ) == true )

{

 n2.output();cout << " is greater than ";n1.output();cout <<"\n\n";

}

if ( n2.isLessThan( n4 ) == true )

{

 n4.output();cout << " is less than ";n2.output();cout << "\n\n";

}

if( n4.isLessThanOrEqualTo( n4 ) == true )

{

 n4.output();cout << " is less than or equal to ";n4.output();

 cout << "\n\n";

}

if ( n3.isGreaterThanOrEqualTo( n3 ) == true )

{

 n3.output();cout << " is greater than or equal to ";n3.output();

 cout << "\n\n";

}

if ( n3.isZero() != true )

{

 cout << "n3 contains value ";n3.output();cout << "\n\n";

}

return 0;

}

//class definitions

#ifndef HUGEINT1_H

#define HUGEINT1_H

class HugeInteger {

public:

HugeInteger( long = 0 );  

HugeInteger add( const HugeInteger & );//addition operator; HugeInt + HugeInt

HugeInteger subtract( const HugeInteger & );//subtraction operator; HugeInt - HugeInt

bool isEqualTo( HugeInteger & );

bool isNotEqualTo( HugeInteger & );

bool isGreaterThan(HugeInteger & );

bool isLessThan( HugeInteger & );

bool isGreaterThanOrEqualTo( HugeInteger & );

bool isLessThanOrEqualTo( HugeInteger & );

bool isZero();

void output();

short* getInteger()

{

return integer;

}

private:

short integer[ 40 ];

};

#endif

//implemetations

#include using std::cout;

#include "hugeint1.h"

HugeInteger::HugeInteger( long value )

{

for ( int i = 0; i < 40; i++ )

integer[ i ] = 0;

 for ( int j = 39; value != 0 && j >= 0; j-- )

{

integer[ j ] = value % 10;

value /= 10;

}

}

HugeInteger HugeInteger::add( const HugeInteger &op2 )

{

HugeInteger temp;

int carry = 0;

for ( int i = 39; i >= 0; i-- ) {

temp.integer[ i ]=integer[ i ] + op2.integer[ i ] + carry;

if ( temp.integer[ i ] > 9 ){

temp.integer[ i ] %= 10; // reduce to 0-9

carry = 1;

} else{

carry = 0;

 }

return temp;

}

void HugeInteger::output()

{

int i;

for ( i = 0; ( integer[ i ] == 0 ) && ( i <= 39 ); i++ );

if ( i == 40 )

cout << 0;

else

for ( ; i <= 39; i++ )

cout << integer[ i ];

}

HugeInteger HugeInteger::subtract( const HugeInteger &op2 )

{

HugeInteger temp;

int borrow = 0;

for ( int i = 39; i >= 0; i-- ){

   if ( integer[i] < op2.integer[i] ){

temp.integer[ i ]=(integer[i]+10)-op2.integer[i]- borrow;

borrow = 1;

   } else {

temp.integer[ i ]=integer[i] - op2.integer[ i ] - borrow;

borrow = 0;

}

}

return temp;

}

bool HugeInteger::isEqualTo( HugeInteger &x ){

 return integer == x.getInteger();

}

bool HugeInteger::isNotEqualTo( HugeInteger &x )

{ return !( this->isEqualTo( x ) ); }

bool HugeInteger::isGreaterThan( HugeInteger &x )

{ return integer < x.getInteger(); }

bool HugeInteger::isLessThan( HugeInteger &x )

{ return integer > x.getInteger(); }

bool HugeInteger::isGreaterThanOrEqualTo( HugeInteger &x )

{ return integer <= x.getInteger(); }

bool HugeInteger::isLessThanOrEqualTo( HugeInteger &x )

{ return integer >= x.getInteger(); }

bool HugeInteger::isZero()

{ return ( getInteger() == 0 ); }

//main file

#include

using std::cout; using std::endl;

#include "hugeint1.h"

int main()

{

HugeInteger n1( 7654321 );

HugeInteger n2( 7891234 );

HugeInteger n3;

HugeInteger n4( 5 );

HugeInteger n5;

n5 = n1.add( n2 );

n1.output();

cout << " + "; n2.output();

cout << " = "; n5.output();

cout << "\n\n";

n5 = n2.subtract( n4 );

n2.output();

cout<< " - "; n4.output();

cout << " = "; n5.output();

cout << "\n\n";

if ( n1.isEqualTo( n1 ) == true )

{n1.output();cout << " is equal "; n1.output(); cout << "\n\n";}

if ( n1.isNotEqualTo( n2 ) == true )

{n1.output();cout << " is not equal to ";n2.output();cout << "\n\n";}

if ( n2.isGreaterThan( n1 ) == true )

{n2.output();cout << " is greater than ";n1.output();cout <<"\n\n";}

if ( n2.isLessThan( n4 ) == true )

{n4.output();cout << " is less than ";n2.output();cout << "\n\n";}

if( n4.isLessThanOrEqualTo( n4 ) == true )

{n4.output();cout << " is less than or equal to ";n4.output();

cout << "\n\n";}

if ( n3.isGreaterThanOrEqualTo( n3 ) == true )

{n3.output();cout << " is greater than or equal to ";n3.output();

cout << "\n\n";}

if ( n3.isZero() != true )

{cout << "n3 contains value ";n3.output();cout << "\n\n";}

return 0;

}

Explanation:

The HughInteger class is a C++ class created to instantiate a vector object of both negative and positive integer values. It has the aforementioned methods in the code above that is used to interact with the several vector objects created from the class.

You might be interested in
Now let's create a memo. The memo should include all parts of a memo, and these parts should appear in the correct order. In you
netineya [11]

Answer:

MEMORANDUM

TO: Stacy Shoe, Allen Sock, and Emma Johnson.

FROM: Department of Information

DATE: 20th of December, 2019

SUBJECT: Computer Operations

The following is an illustration of how to start a computer and how to open an existing word processing document. For clarity and ease of understanding, this will be divided into two subheadings. All questions should be directed to the department of information.

START A COMPUTER

Step 1: Press the start button on the CPU tower.

Step 2: Wait while the computer boots. When the computer has finished booting, it will show a dialogue box that will ask for a user name and password.

Step 3: Enter your user name and password, then click

"OK."

Step 4: Your computer is now ready to use.

OPENING A WORD PROCESSING DOCUMENT

To open any word processing documents, you can use any of the options below.

1. Double-click file

In some cases, you can double-click a file to open it in Microsoft Word. However, the file will only open in Microsoft Word if that file type is associated with Microsoft Word. Word documents, like .doc and .docx files, are associated with Microsoft Word by default. However, web page files, text, and rich text format files are often not associated with Word by default, so double-clicking on these files may open in another program.

2. Right-click file and select program

For any file, you can choose the program to open a file with, including Microsoft Word.

Step 1: Right-click the file you want to open.

Step 2: In the pop-up menu, select the Open with option.

Step 3: If available, choose the Microsoft Word program option in the Open with menu. If Microsoft Word is not listed, select the Choose other app or Choose default program option, depending on the

Step 4: In the window that opens, find Microsoft Word in the program list and select that option. Microsoft Word should open and the file opened within Word.

3. Open within Microsoft Word

Follow the steps below to open a file from within Microsoft Word.

Step 1: Open the Microsoft Word program.

Step 2: Click the File tab on the Ribbon and click the Open option.

Step 3: If the Open window does not appear, click the Browse option to open that window.

Step 4: In the Open window, find and select the file you want to open in Microsoft Word. You may need to click the drop-down list next to the File name text field to change the file type to that of the file you want to select and open.

Step 5: Click the Open button at the bottom right of the Open window.

As stated above, all questions are to be directed to the department of information.

Thanks.

Explanation:

5 0
3 years ago
What is a computer briage coures​
Stella [2.4K]

what's your choices for this question

4 0
3 years ago
____________ is used by IM and other applications that provide voice services over lower-speed digital circuits.
zimovet [89]

Answer:

The correct answer is Adaptive differential pulse code modulation

Explanation:

Adaptive differential pulse code modulation (ADPCM) is a variant of differential pulse-code modulation (DPCM) that varies the size of the quantization step, to allow further reduction of the required data bandwidth for a given signal-to-noise ratio. The output data rate can be dynamically adjusted between 16 kbit/s and 64 kbit/s in these applications.

6 0
3 years ago
What is the correct process for selecting an entire row in a spreadsheet?
Valentin [98]
A. Click on any cell in the row
7 0
3 years ago
F he continues to make monthly payments of $100, and makes no new purchases, how many more payments will he have to make before
castortr0y [4]

What is the interest rate?

Divide the total amount due by 100.

8 0
3 years ago
Other questions:
  • The spreadsheet below shows the age, grade level, major, and minor of four students in college. A purple background in the Major
    7·1 answer
  • Driving while wearing headphones or earphones
    12·2 answers
  • Explain why the game of economics has no winner
    8·1 answer
  • What fields of engineering are in Biomedical
    7·1 answer
  • What is the best way to protect computer equipment from damage caused by electrical spikes
    15·1 answer
  • End user needs assessment is a formal procedure to analyze a user's computer needs; it involves a specific set of steps that are
    8·1 answer
  • Which of the following are documents that can help you to review and assess your organization’s status and state of security? Fi
    6·1 answer
  • In general, smartphones do NOT hold as much personal information as tablets.
    11·1 answer
  • What allows users to connect via the Internet to its private network?
    11·2 answers
  • When converting text to a table, which feature should be used?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!