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
_____________ describes the abstraction of web-based computers, resources, and services that system developers can utilize to im
Vika [28.1K]

Answer:

c. Cloud computing

Explanation:

Cloud computing -

It refers to the on - time need of the computer resource , in order to store data , computing power by the user , is referred to as cloud computing.

It refers to the availability of the data centers to the user .

This method enables the sharing of resources .

Hence, from the information of the question,

The correct option is c. Cloud computing .

6 0
4 years ago
Task 5: Create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer whose ID currently is sto
lidiya [134]

The SQL statement that would create the GET_CREDIT_LIMIT procedure to obtain the full name and credit limit of the customer is:

GET_CREDIT_LIMIT

SELECT CUST_ID 125

FROM FIRST_NAME, LAST_NAME, CREDIT_LIMIT

WHERE LAST_NAME ="Smith"

<h3>What is SQL?</h3>

This is an acronym that means Structured Query Language that is used in handling data in a database.

Hence, we can see that from the attached image, there is a table that contains the details of customers and their various data such as their first and last names, credit limits, address, etc, and the  GET_CREDIT_LIMIT procedure is shown above.

Read more about SQL here:

brainly.com/question/25694408

#SPJ1

3 0
2 years ago
Using Amdahl’s Law, calculate the speedup gain of an application that has a 60 percent parallel component for (a) two processing
Nina [5.8K]

Answer:

a) Speedup gain is 1.428 times.

b) Speedup gain is 1.81 times.

Explanation:

in order to calculate the speedup again of an application that has a 60 percent parallel component using Anklahls Law is speedup which state that:

t=\frac{1 }{(S + (1- S)/N) }

Where S is the portion of the application that must be performed serially, and N is the number of processing cores.

(a) For N = 2 processing cores, and a 60%, then S = 40% or 0.4

Thus, the speedup is:

t = \frac{1}{(0.4 + (1-0.4)/2)} =1428671

Speedup gain is 1.428 times.

(b) For N = 4 processing cores and a 60%, then S = 40% or 0.4

Thus, the speedup is:

t=\frac{1}{(0.4 + (1-0.4)/4)} = 1.8181

Speedup gain is 1.81 times.

8 0
4 years ago
During which part of an examination are various body parts and organs touched and felt?
scoray [572]

The correct answer is B. Palpation

Explanation:

In a medical exam or similar, the palpation involves touching different parts of the body to feel the organs and structures in this. This process is essential in diagnosis because palpation can reveal inflammation, pain in certain areas, or abnormalities. Additionally, palpation requires a broad knowledge of anatomy that allows health professionals to understand the structures of the body when they touch these and how to determine abnormalities. Thus, the part of an examination in which body parts are touched and felt is palpation.

8 0
3 years ago
ANSWER QUICKLIY
lidiya [134]

Answer:

Explanation:

Allow you to view the document in different ways. Sorry if I am wrong. I am dumb

God bless, stay safe, and good luck! :)

4 0
3 years ago
Read 2 more answers
Other questions:
  • Please draw a diagram of a complete graph with 5 vertices (K5), its adjacency matrix and adjacency list representations.
    5·1 answer
  • Which statement describes borders and shading ?
    13·1 answer
  • Which one of these tasks is part of the pre-production phase of game development?
    11·2 answers
  • Which of the following is not a type of Internet Job Board? Options Resume Blaster Professional Association Target Applicants We
    8·1 answer
  • When sketching out your Web site you create a clear and straightforward site map that divides the Web site content into a logica
    9·1 answer
  • What is a Software that interprets commands drom the keyboard and mouse
    13·1 answer
  • What type of error results from an error in the formatting of the program code?
    13·1 answer
  • Vpn stands for _____. very precise settings virtual private network virtual public network vice prestigious setup
    5·1 answer
  • Please Help ASAP. Marking Brainliest For Correct Answer.
    5·1 answer
  • _____ provides the best video resolution. *<br><br> VGA<br> HDMI<br> USB<br> DVI
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!