dont spend to much time with optimizations cos mostly compiler does that for you, but if you wanna know some hints:
you function
void SQUARE::populate()
could be writen more efficient using switch statement.
not because that would produce faster code but the code it self will be more readable.
you said:
1 2
|
//Would it be better if each was split into difference functions?
{ //Eg. int area (int a, int b) {return a * b;}
|
no.
because one having one function is better then alot functions in a class but that depends on wether you need more functions or not.
Your code:
1 2 3 4 5 6 7
|
if (choice == 1)
{
SQUARE *s = new SQUARE;
s->populate();
s->print();
delete [] s;
}
|
You are doing a terrible mistake here!
remember:
how many
new
so many
delete
how many
new[]
so many
delete[]
a you just called
delete[]
for
new
which is very wrong.
one more thing about afficient code.
do not alocate small objects dinamicaly like this your class class or POD types(build-in types)
because dinamic alocation and indirection takes alot more time then stack alocation and indirection.
dinamic alloc is used for big objects.
do no perform any optimizatioin on your code until oyu finish your project or until is not large enough.
the time involved in optimization mostly return nothing or few bytes or rew seconds which isn't worth allways.
cheers!