954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

big integer calculator

I need help with my big integer calculator program. The program should receive two large integers using vectors and calculate the sum, difference, product, and quotient o the two integers.

The main file is:

#include <iostream>		// cout, <<, >>
#include <fstream>		// istream, ofstream
#include <string>		// string
#include <cassert>		// assert ()
#include <vector>		// vector<T>
#include "Test5Q20.h"	// read(), add(), subtract(), multiply(), divide()

int main()
{
	cout << "Enter First Operand:  ";
	vector<double> numOperand1;
	cin >> numOperand1;					// place first number in vector num1
	cout << "Enter Second Operand:  ";
	vector<double> numOperand2;
	cin >> num2;					// place second number in vector num2

	add(vector<double> numOperand1, vector<double> numOperand2);	// determine the sum of the two operands 
	cout << "The sum of operand1 and operand2 is: " << sum << "\n";

	subtract(vector<double> numOperand1, vector<double> numOperand2);	// determine the difference of the two operands 
	cout << "The difference of operand1 and operand2 is: " << sum << "\n";

	multiply(vector<double> numOperand1, vector<double> numOperand2);	// determine the sum of the two operands 
	cout << "The product of operand1 and operand2 is: " << sum << "\n";

	divide(vector<double> numOperand1, vector<double> numOperand2);	// determine the quotient of the two operands 
	cout << "The quotient of operand1 and operand2 is: " << sum << "\n";
}


The header file is:

#include <iostream>		// istream, ostream
#include <vector>		// vector
#include <cmath>		// pow
using namespace std; 

/*add() finds the sum of operand1 and operand2.
 *
 * Receive:      numOperand1 & numOperand2, a vector<double>
 * Precondition: numOperand1 & numOperand2 is not empty
 * Return:       the sum of the operand1 & operand2
 ***************************************************************/
 
double add(vector<double>& numOperand1, vector<double>& numoperand2)
{
   if (numOperand1.empty()) || (numOperand2.empty());
   {
      cerr << "\n***ADD: empty vector received!\n" << endl;
      return 0.0;
   }
   else
         return add(numOperand1 + numOperand2);
}

/*subtract() finds the difference of operand1 and operand2.
 *
 * Receive:      numOperand1 & numOperand2, a vector<double>
 * Precondition: numOperand1 & numOperand2 is not empty
 * Return:       the difference of the operand1 & operand2
 ***************************************************************/
 
double subtact(vector<double>& numOperand1, vector<double>& numoperand2)
{
   if (numOperand1.empty()) || (numOperand2.empty());
   {
      cerr << "\n***SUBTRACT: empty vector received!\n" << endl;
      return 0.0;
   }
   else
         return add(numOperand1 - numOperand2);
}

/*multiply() finds the sum of operand1 and operand2.
 *
 * Receive:      numOperand1 & numOperand2, a vector<double>
 * Precondition: numOperand1 & numOperand2 is not empty
 * Return:       the product of the operand1 & operand2
 ***************************************************************/
 
double multiply(vector<double>& numOperand1, vector<double>& numoperand2)
{
   if (numOperand1.empty()) || (numOperand2.empty());
   {
      cerr << "\n***MULTIPLY: empty vector received!\n" << endl;
      return 0.0;
   }
   else
         return multiply(numOperand1 * numOperand2);
}

/*divide() finds the sum of operand1 and operand2.
 *
 * Receive:      numOperand1 & numOperand2, a vector<double>
 * Precondition: numOperand1 & numOperand2 is not empty
 * Return:       the quotient of the operand1 & operand2
 ***************************************************************/
 
double divide(vector<double>& numOperand1, vector<double>& numoperand2)
{
   if (numOperand1.empty()) || (numOperand2.empty());
   {
      cerr << "\n***DIVIDE: empty vector received!\n" << endl;
      return 0.0;
   }
   else
         return quotient(numOperand1 / numOperand2);
}
POW
Newbie Poster
2 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 
I need help with my big integer calculator program.

Okay.The program should receive two large integers using vectors and calculate the sum, difference, product, and quotient o the two integers.

Okay.The main file is:

Okay.The header file is:

Okay.

What do you want?

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

Wow Pow,
You have made many errors in your header file.

1. Too many braces in your if conditions.
2. C++ is case sensitive.
3. If an if condition is followed by a semi-colon, then the if condition terminates at the semi-colon, hence the else is illegal because it follows a scoped code block, not an if block.
3. Vector does not overload the mathematical operators (+, -, *, /)
4. You have not declared any operators to actually handle the addition of the values in the vectors (you will need to iterate through the vectors in the else clause).

Try and resolve these errors, they should be raised by compiler errors when you compile. And think about how you will add the values in the vector and what you will return from the function.

alpha_foobar
Junior Poster
182 posts since May 2005
Reputation Points: 20
Solved Threads: 5
 

Hm I need to solve the same task can someone help us more about this code?

Flixter
Newbie Poster
8 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

Please check the date that this thread was created...

William Hemsworth
Posting Virtuoso
1,591 posts since Mar 2008
Reputation Points: 1,429
Solved Threads: 129
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You