How do you mark the beginning and end of classes
class Name
{
...inside the class
}; // match brace to start of class.
Is there a way of keeping classes together in compilation
You can put them all in the same file... or you can write special commands for the
compiler to assemble the files. You can automate this process using a "Makefile" and the "make"
command in UNIX. Something similar is possible for IDEs and MS Visual Studio...
When to use a function or a class
Use a class to model real world objects. Use a function when you have a simple task
with all its data provided at that time and no memory. Use a function is class
if there is any data that must be stored between calls.
When to use function overloading
When you have two similar calculations with different types of data. For example adding
to ints, adding to doubles, and adding two string.... are all shown with "+".
The compiler will match the right (usually) function definition with each call for you.
Why function overloading
Few different names to worry about.
How does a program use an identifiers scope
Inside the scope the variable has a meaning. The compiler keeps a list
of variable declarations as it reads the program and looks up each variable when
it used in the list.
What is the difference between global and static local
The global has a scope equal to the whole file and any other file that decalres an "extern" variable
of the same name. The static variable is private to the function/block
in which it is declared. Both have a life time equal to the program. They are just accessible in different parts of the program.
What is the difference between static global and global
A global variable that is declared static has a scope equal to the file in which is declared.
It can not be accessed form another file of data.
Is there a limited time for information to be stored in an identifier
The data is stored for the while life time of the variable. Global and static
variables keep their values and meaning for the whole life of the program. Local variables
and parameters in functions keep their values until the end of the function or block in which they are declared. Data members (variables in objects/classes) keep their values until their object is destroyed -- and the object follows the rules of its declaration.
Do static local variable keep their value when the function returns
Yes.
When to use enum
When you need a variable to have one of a fix number of values, and you have
a ready made set of names for them. Examples might include
- Colors of the rainbow
- Days of the week
- Months
- Gears in an automobile
Notice the two requirements: a fixed set + known names. Otherwise "enum" may act as a problem not
a solution.
In arrays and vectors -- what if I start my indexes at 1 not 0
It works, you waste a little storage. I've done this.
Can vectors store strings etc
Yes. You can have a vector of any kind of object: int, double, char, string, even vector!
What do lables do to a program
Case labels are ok. Other labels are confusing.
What is Randomization
Any process that gives unpredictable results -- result that are unlikely to
be correlated with other things that are going on.
What are pseudo-random numbers
These are numbers that appear to be chosen at random. Their function is
to simulate real random processes like throwing dice, tossing coins, and
shuffling cards. Very useful in games, statistics, and so-called Monte Carlo
numerical methods.
Whats with srand and rand!
You always have two functions when generating random numbers. One gives you the next number.
In C++ this is called "rand" and it has no parameters. The other function sets the random
number generator to a particular internal number. In C++ this is "srand". It must have an parameter to generate the starting point. In C++ this is always done like this
srand(time(0));
at the start of any program that needs random numbers.
Unless you want to spend time studying random number generators... its best to treat them
as magic -- learn the spells and recite them correctly (See the Harry Potter series).
What does an enumeration do in a program
It saves you remembering what a set of integers mean by giving them names.
Can enumerations skip numbers
Yes:
enum Example(START=17; MEANING=42};
Can you increment by other than 1 an enumeration variable
Yes.
If there is a gap in the enumeration what does ++ do
It gives a value that you did not list in your constants!
- . What is scaling
Scaling is multiplying a set of related numbers by a constant to change their
range of values while preserving the relative sizes. Like zooming in and out.
What is unsigned for, why not use int
Unsigned is used for compilers, operating systems, and working close to the hardware.
Other than that you might as well use signed numbers.
How much memory is assigned to registers.
Registers are inside the CPU. Memory is outside the CPU. So: zero.
But the size of the registers in the CPU depends on the chip.