* reminder:
a C++ program is a collection of one or more functions,
exactly one of which has the name:
main
* reminder:
when you run a compiled-linked-and-loaded
C++ executable program,
it STARTS by running the main function
...or, the action starts with main!
(that main may call other functions,
that themselves call other functions,
and so on!)
* not just any function header can be used
for a main function, however --
these two seem to be the most accepted
at this point (modern/standard C++, I think)
int main() <-- we'll be using this in CS 111
(mostly? completely?)
int main(int argc, char* argv[]) <-- this one has
to do with programs
with command-line
arguments
* according to the C++ standard
(if I understand correctly)
a main DOES return something;
we'll, in CS 111, use the following as our
standard:
we'll return the named constant
EXIT_SUCCESS
...to mean the main is ending normally, and
EXIT_FAILURE
...for a not-so-happy ending
* our beginning skeleton of a basic C++ main function:
int main()
{
// do something;
return EXIT_SUCCESS;
}
* funct_play does NOT work well for creating
main functions
(nor for so-calle void functions, which are
functions that do not return anything)
how can you type in a C++ main function,
or an entire program, for that matter?
* you can use nano
* you can use a CODE EDITOR such as
Notepad++ (Windows) or TextWrangler (Mac)
* you can use an IDE (integrated development environment)
such as Eclipse (Windows and Mac), XCode (Mac),
DevC++ (Windows), Code::Blocks (Window and Mac
but Mac not updated darn it), NetBeans (Windows and Mac),
and more...
...any of these are fine, as long as:
* you follow the class coding standards
* you are using the GNU C++ compiler
* notice the following work-flows:
* you can PuTTY to nrs-labs,
use nano to type C++ files,
and use the command line to compile and run your programs
and use ~st10/111submit your files
* you can use a code editor such as
Notepad++ or TextWrangler or Editra or ...
on a computer that is not nrs-labs,
use WinSCP/FileZilla/sftp to transfer your
files to nrs-labs,
and use the command line to compile and run your programs
and use ~st10/111submit your files
* you can use an IDE such as
Eclipse/Code::Blocks/DevC++/XCode/NetBeans...
on a computer that is not nrs-labs,
use the IDE to compile and run your programs,
use WinSCP/FileZilla/sftp to transfer your
files to nrs-labs,
and use ~st10/111submit your files
* reminder: #include
* this is kind of like require in BSL Racket;
* you can literally include files of stuff
your program needs
* # means this is a precompiler directive,
something done before translation/compiling
* you put:
#include <standard_library_name>
#include "your_funct.h"
...
using namespace std; // we'll use the standard namespace
// in CS 111
* we'll as a class standard include the following
in our main functions:
#include <cstdlib>
#include <iostream>
#include <string>
// any other #includes for libraries or functions you
// are using in THIS main
using namespace std;
int main()
{
// do something;
return EXIT_SUCCESS;
}
* what about signture, purpose, etc.?
of course we'll have those! in an opening comment
block:
/*-----
signature: main: void -> int
purpose: describe the purpose of the program
this main starts, OR
testing program for the function funct_name
examples: describe, in prose, what the effect of
running this program should be
by: your name
last modified: date
-----*/
* how do you compile a C++ program on nrs-labs?
* there is a helper-script called
compile-helper
that you CAN use for this;
* it walks you through the following,
to compile, link, and load a C++ program,
resulting in a C++ executable program:
g++ main_funct.cpp funct1.cpp funct2.cpp ... -o progr_name
* if you JUST want to COMPILE 1 file,
to look for syntax errors,
and NOT get an executable yet,
use:
g++ -c desired_file.cpp
* AND if you are CALLING one of your function my_fun,
INCLUDE #include for EACH function the main calls!!!
#include "my_fun.h"