Hello all,
Firstly let me say yes, i have searched the forums, secondly No! i am not asking for you to do my homework, i realize how much you all hate that =P
I am here for some guidance, i have exhausted my researching capabilities and am at the point of getting nowhere, yes i am a noob to this topic, however, i need to get it done, and i am acing the rest bar this section.
The goal is to build a calculator capable of inputing and outputting large integers (up to 20+ characters) I know there are a lot of different threads on this but they are either extremely complex or do not follow my scope.
I need to use arrays
I need to build a Bigint class
I need to do + / - and *
I need to make my own operators
I need Bigint.cpp and Bigint.h files.
I am only in the process of creating the basic files, not much actual code yet. I have not worked with c++ class code before, which is why i'm having trouble.
Questions i am asking:
1. Is my main method legal? can i create Bigint variables and call to them just as i have in my code? assuming i have created the operators << and >> for them?
2. I am definitely missing something in my class of Bigint, are these array declarations allowed?
3. Can i be pointed in the right direction of creating the Bigint constructor?
4. My main problem is with the << and >> operations, totally stuck here!!!
5. With the << >> operations successful, is it plausible that my getInt function, which is called as part of constructing Bigint, that it will gather the input and place them into an array such that:
a[0 0 0 0 0 0 0 0 0 9 8 7 6 5 4 3 2 1 0]?
Bigint.cpp
using namespace std;
int main(void){
Bigint x, y;
char op;
cout << "Value x, y and operation?: ";
cin >> x >> y >> op; //This will work when I write the code for the >> operator.
switch(op){
case '+':
cout << "Result:\n" << x + y << "\n"; //These should work as I write the operators for + - / *.
break;
case '-':
cout << "Result:\n" << x - y << "\n";
break;
case '/':
cout << "Result:\n" << x / y << "\n";
break;
case '*':
cout << "Result:\n" << x * y << "\n";
break;
}
return(0);
}
Bigint.h file
using namespace std;
//Begin class
class Bigint {
friend ostream& operator>> (std::ostream& in, Bigint& x);
friend ostream& operator<< (std::ostream& out, const Bigint& x);
friend Bigint operator+(const Bigint& x, const Bigint& y);
friend Bigint operator-(const Bigint& x, const Bigint& y);
friend Bigint operator/(const Bigint& x, const Bigint& y);
friend Bigint operator*(const Bigint& x, const Bigint& y);
public:
Bigint(long = 0);
~Bigint();
void setInt(unsigned long long int);
void getInt(unsigned long long int);
private:
Bigint a[256];
Bigint b[256];
Bigint c[256];
//Need some variable array here?
};
//End class
//Begin constructor
Bigint::Bigint(long value) {
getInt(value);
}
Bigint::~Bigint() {
}
void Bigint::getInt(unsigned long long int value){
//How do i do this? do i need the in/out operators done first?
//How would i test the code?
}
//End constructor
//Begin in/out operators
ostream &operator>>(std::ostream &input, const Bigint &x)
{
//How do i do this?
return input;
}
ostream &operator<<(std::ostream &output, const Bigint &x)
{
//How do i do this?
return output;
}
//End in/out operators
//Begin math operators
Bigint operator+(const Bigint &x, const Bigint &y) {
// Make several variables to hold values
// Make a temp array and carry array
// Make a variable for the result
//
// Begin writing psuedo code
}
Bigint operator*(const Bigint &x, const Bigint &y) {
// Make several variables to hold values
// Make a temp array and carry array
// Make a variable for the result
//
// Begin writing psuedo code
}
Bigint operator-(const Bigint &x, const Bigint &y) {
// Make several variables to hold values
// Make a temp array and carry array
// Make a variable for the result
//
// Begin writing psuedo code
}
Bigint operator/(const Bigint &x, const Bigint &y) {
// Make several variables to hold values
// Make a temp array and carry array
// Make a variable for the result
//
// Begin writing psuedo code
}
//End Math operators
#endif /* _BIGINT_H */
Thank you for your replies it is much appreciated. I will be fine writing the calculator itself, its more getting the values into the array that is baffling me!!!
cheers,
Zea