Yeah, finally bothered with a sizeof program. short is 2 bytes, int is 4 and long is 8 on my computer.
In other news, segfault has finally caught up with me, what do you know! Now I'm looking for a way to store a string of characters so that I could write it together with the rest of an object to a binary file. If I make it a char array with fixed length, it just doesn't compile, because sometimes it's apparently still just a pointer whatever I do.
For anybody curious or incredulous:
#include <iostream>
using namespace std;
class Element
{
public:
Element() {}
~Element() {}
Element(char[], short, double , short[] , short );
void DisplayName() const;
short GetNumber() const { return itsNumber; }
double GetElectronegativity() const { return itsElectronegativity; }
short GetValnumber() const { return itsValnumber; }
void DisplayValencies() const;
void AssignValues(char[], short, double , short[] , short );
private:
char itsName[20];
short itsNumber;
double itsElectronegativity;
short itsValency[7];
short itsValnumber;
};
Element::Element(char name[20], short number, double electronegativity, short valency[7], short valnumber)
{
itsName = name;
itsNumber = number;
itsElectronegativity = electronegativity;
itsValnumber = valnumber;
for(int i=0; i<valnumber; i++)
{
itsValency[i] = valency[i];
}
cout << "*Element constructor called*\n";
}
void Element::DisplayName() const
{
cout << itsName;
}
void Element::AssignValues(char name[20], short number, double electronegativity, short valency[7], short valnumber)
{
itsName = name;
itsNumber = number;
itsElectronegativity = electronegativity;
itsValnumber = valnumber;
for(int i=0; i<valnumber; i++)
{
itsValency[i] = valency[i];
}
cout << "*Values assigned*\n";
}
void Element::DisplayValencies() const
{
for(int i=0; i<itsValnumber; i++)
{
cout << itsValency[i];
if( i==(itsValnumber-1) )
cout << "." << endl;
else
cout << ", ";
}
}
Assign values is a copy of Element constructor, because I've decided to separate the program into reading and writing, and don't want to create two different objects, yet.