The object of this assignment is to convert decimal to binary. I must follow the pseudo code for the algorithm to do the process of conversion but the rest is up to us in regards how to structure the program. However, we must use classes and have at least a single inheritance. I have the code mostly finished, but I can't seem to test it more than likely due to something super simple that I simply just can't see. I've been trying various things but it seems I'm just chopping at the code with no real idea of what is actually wrong. Here's my source code, any help is appreciated.
When you run the code, i get a LNK2019: unresolved external symbol error.
#include <iostream>
#include <vector>
using namespace std;
class binaryConverter
{
public:
void print();
binaryConverter();
binaryConverter(int);
void addBit(int);
private:
vector<int> binary;
};
class decimalToBinary : public binaryConverter {
public:
void print();
void process(int);
decimalToBinary();
private:
};
void binaryConverter::addBit(int d){
binary.push_back(d);
}
void decimalToBinary::process(int num)
{
if (num >= 128){
num = 128 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 64 && num < 128){
num = 64 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 32 && num < 64){
num = 32 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 16 && num < 32){
num = 16 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 8 && num < 16){
num = 8 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 4 && num < 8){
num = 4 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 2 && num < 4){
num = 2 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
if (num >= 1 && num < 2){
num = 1 - num;
decimalToBinary::addBit(1);
}
else{
decimalToBinary::addBit(0);
}
}
void binaryConverter::print(){
for (vector<int>::iterator it = binary.begin(); it != binary.end(); it++){
cout << *it << endl;
}
}
int main(){
decimalToBinary test;
test.process(150);
test.print();
return 0;
}