This was a silly little program I made to get a handle on classes, but I think I've really butchered some part of this, can anyone spot my mistake?
*by the by, it's not entirely finished, but certain things SHOULD work already* I'm not desiring nor asking anyone to finish it, but I've just spent like 4 hours trying to figure out why it's not working. Feel free to call me a fool, I probably did something ridiculously stupid
"main.cpp" FILE:
Code:
#include "myheaders.h"
int main (void)
{
lchairs *program = new lchairs;
delete program;
return 0;
}
"core.h" FILE:
Code:
class lchairs
{
private:
int *elechairs;
void flagset( int &target, const int, const char *op_type );
bool flagcheck ( int target, const int bit );
void elecmain();
public:
lchairs(void);
~lchairs(void) { delete elechairs; }
};
void lchairs::elecmain()
{
char menuchoice;
while ( *elechairs > 0 )
{
cout<<"\nMenu\n\n1)Rollcall\n2 Execute\n3Replacement\n4)Exit\n";
cin>>menuchoice;
switch ( menuchoice )
{
case '1':
{
for ( int x = 1 ; x >=8 ; x++ )
{
if ( flagcheck(*elechairs, x) == true)
{
cout<<"Number "<<x<<" is alive\n\n";
}
}
}
break ;
case 2:
case 3:
case 4:
default:
break;
}
}
}
lchairs::lchairs()
{
int *elechairs = new int;
*elechairs = 0;
for ( int x = 1 ; x <=8 ; x++ )
flagset ( *elechairs, x, "raise" );
elecmain();
}
void lchairs::flagset( int &target, const int bit, const char*op_type )
{
if (!strcmp(op_type, "lower"))
target = target & (int)(!(pow(2, bit - 1)));
else if (!strcmp(op_type, "raise"))
target = target | (int)(pow(2, bit - 1));
}
bool lchairs::flagcheck ( int target, const int bit )
{
if ((target & (int)pow(2, bit - 1)) >= 1)
return true;
else
return false;
}
"myheaders.h" FILE:
Code:
#include <iostream.h>
#include <cmath>
#include <cstring>
#include "core.h"