Is there any free alternative to AMPL?
(Edit: I spoke too soon; thanks to mlubin for pointing this out.) If you don't care too much about convenience, there are open-source formats for specifying nonlinear programs (the SIF and NOP formats), but then you have to translate that format into a form your solver can actually use. Since the CUTEr/CUTEst test sets use the SIF format, you might be able to leverage any interface a given solver has with those test sets and adapt it to reading whatever SIF files you want to produce.
As far as popular modeling frameworks go, GAMS has a free trial version, but the number of decision variables allowed in a formulation is capped. NEOS has GAMS and AMPL interfaces, so you could submit jobs on NEOS and then retrieve the results via, for instance, e-mail.
There are free modeling frameworks out there, like PuLP (lightweight, used for LPs; I used it in my thesis) and Pyomo, so you might be able to use those. Miles (mlubin) talks about a Julia-based framework in his answer. A partial list of frameworks can be found in this preprint.
You can also write solver-specific code. Couenne, for instance, is freely available, and you can use its native API to solve problems. Of course, repeating this process for every solver you might want to use is inconvenient.
If I write C++ code which uses open source optimizers like Couenne, can I use that software to make money?
IANAL, and it depends on the license. Couenne, for instance, is licensed under the Eclipse Public License (EPL). It doesn't prohibit you from using the software for commercial purpose (for instance, in designing a device). A quick read of the license (again, I should emphasize, IANAL) suggests that you can sell commercial software based on Couenne, and that if you include the Couenne source code as part of that software, then you must also provide the Couenne source code or tell people how they can obtain it.
Similarly, BSD- and GPL-licensed software may be sold commercially, provided you comply with the terms of the respective licenses. In the case of the GPL, you must also provide the source code freely.