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
11. Describe an algorithm that interchanges the values of the variables x and y, using only assignments. What is the minimum num
Svetlanka [38]

Answer:

Following is the algorithm to interchange the value of two variable x and y.

step 1:Read the two integer x and y.

step 2 :t=x

Step 3: x=y  

step 4: y=t

The minimum number of assignment to do this is 3

Explanation:

After reading two integer x & y, create a variable "t" of integer type.

with the help of variable "t", we can swap the value of variable x and y.

It requires 3 assignment to interchange the value.

6 0
3 years ago
Which type of text may be formatted to print at the bottom of every page?
Tatiana [17]
The answer is header.
3 0
2 years ago
When saving a document or drawing, you determine the destination folder in which the file will be saved by?
bekas [8.4K]

making a selection in the Save in: box.<span>

</span>
8 0
2 years ago
Question Mode Matching Question Match the following description with the appropriate programming language generation. 1GL 1GL dr
erastovalidia [21]

Answer:

1GL: Machine language. Represented by a series of 1s and 0s.

2GL: Assembly language. An assembler converts 2GL into machine language.

3GL: High-level programming language. Uses a compiler to convert into machine language.

4GL: Specifically designed for creating database management programs.

5GL: Extremely advanced. Uses statements (scripts) rather than algorithms.

Explanation:

Programming languages started as a series of binary digits (i.e. 0's and 1'). This generation of language is referred to as the first generation.

However, the machine language were difficult to read by human, so mnemonics were created (i.e. assembly language). This language uses symbolic codes such as ADD for addition, etc. This is the second generation

The third generation are the high level languages that uses languages that can be easily understood by human, e.g. + means plus. However, the language must be translated; hence the need for a compiler or interpreter, as the case may be.

The fourth and fifth generations are extensions of the third generation languages. The fourth were created to connect to DBMS while the fifth are more advanced.

4 0
3 years ago
Jordan has been asked to help his company find a way to allow all the workers to log on to computers securely but without using
lana66690 [7]

Answer:

Webcam

Explanation:

A webcam is mainly used for taking images or videos from the computer. the webcam is a combination of two basic words i.e. web and camera. webcam can be connected to any computer via USB. It can be mounted on the desktop and sometimes it comes inbuilt on the laptops.

A webcam is also used for face recognition function to login to a computer system.

so according to the scenario, the most appropriate answer is a webcam.

6 0
3 years ago
Other questions:
  • suppose you need to verify how to correctly use commas. you pen your English textbook and scan the chapter titles in which one w
    15·1 answer
  • What are three ways you cite evedince
    5·2 answers
  • What connector has 4 pins, is used for older IDE drives and some SATA drives, and can provide +5 V and +12 V power outputs?
    11·1 answer
  • Which turn best describe news one is connected to the government and is used as a political tool more than as a business product
    12·1 answer
  • Which of the following cameras is a high-end digital camera that has interchangeable lenses and uses a mirror to display on its
    13·1 answer
  • Write a program that simulates flipping a coin to make decisions. The input is how many decisions are needed, and the output is
    14·1 answer
  • 2.
    8·1 answer
  • PLEASE ANSWER!! If my pixel has an RGB value of (R - 150, G - 0, B - 100), what is the dominant value? Why?
    14·1 answer
  • VEE Physics 2006 E.C
    7·1 answer
  • (PLEASE HELP)
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!