Can someone tell me what is wrong with this code? I cannot find an error, but yet the compiler crashes everytime I execute it.
Convert.h
/*Dec to Bin and Hex to Dec*/
/* Example */
/* Convert.h */
/*Define the class*/
class Convert
{
public:
Convert();/*Constructor: default parameters*/
void DecToBin(int); /*Dec to Hex*/
void PrintResult();
~Convert(); /*Destructor*/
private:
int maxSize; /*integer to store the maximum size of p*/
int Result;
int *pBits; /*Pointer to hold the int array of bits*/
int iCount;
};
Conversion.cpp
/*Conversion.cpp, the implementation file*/
#include <iostream>
#include "Conversion.h"
using namespace std;
/*Default parameters of constructor*/
Convert:: Convert()
{
pBits=0; /*Make it point to NULL*/
iCount=0;
Result=0;
maxSize=255; /* This is the maxSize*/
cout<<"Default Constructor was initialized"<<endl;
}
/*Dec to Bin*/
void Convert::DecToBin(int Results)
{
Result=Results;
if((Result>=1 && Result<=maxSize))
{
while(Result>1)
{
*pBits=Result%2; /*Serialise*/
Result=Result/2; /*Divide*/
pBits++; /*Point to the next location*/
iCount++;
cout<<*pBits<<" ";
}
if(Result==1)
{
*pBits=1;
}
}
return;
}
Convert::~Convert()
{
cout<<"Destructor executed"<<endl;
}