* reminder:
a C++ program is a collection of functions,
exactly one of which has the name:
main
* when you run a compiled-linked-and-loaded
C++ executable program,
it starts by running its main function
...the action starts at the main function!
* you can't use just any function header for
a main function!
it LOOKS like (I think) these are the
most-considered-acceptable modern C++ main
function headers:
int main() <-- we'll be using this MOST (if not all)
of the time in CS 111
int main(int argc, char* argv[]) <-- you use this
for programs with command-line
arguments;
* according to the C++ standard,
main SHOULD return something --
for the CS 111 class coding standard,
our main functions will return either:
EXIT_SUCCESS
or
EXIT_FAILURE
* here, then, is a beginning C++ main function
skeleton:
int main()
{
// do something;
return EXIT_SUCCESS;
}
* funct_play does NOT work well for creating
main functions
(nor for so-called 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/ssh 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 PuTTY to connect to nrs-labs so you
can use ~st10/111submit to submit your files
* SO, before we try one of the above approaches,
we need a few more pieces in our main "skeleton":
* reminder: C++ uses #include KIND of like
Racket uses require,
to literally include file contents that
your function needs;
# - means #include is a pre-compiler directive,
done BEFORE translation/compilation
* for a C++ standard library, you put:
#include <standard_libr_name>
...for EACH standard library you want,
* for a function YOU have written, say
my_funct, you put:
#include "my_funct.h"
...for EACH of your functions that this
main calls;
* for CS 111, for our small programs, we'll
put after the last #include:
using namespace std; // we will use the standard namespace
* for our main "skeleton", we'll use the following
#includes:
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
// #include "my_funct.h"
using namespace std;
int main()
{
// do something;
return EXIT_SUCCESS;
}
* of course we also need an opening comment block!
/*-----
signature: main: void -> int
purpose: describe the program being written,
OR
testing program for the function funct_name
examples: describe, in prose if necessary, what the
effect of running this program will be
by: your name
last modified:
-----*/
* compiling a C++ program from the command line:
* from the week 8 lab, you do have the script
compile-helper
...that walks you through the following;
* BUT to do this yourself:
g++ is the GNU C++ compiler on nrs-labs
to compile, link, and load a C++ program,
resulting in a C++ executable program:
g++ main_funct.cpp funct1.cpp funct2.cpp ... -o main_funct
* CS 111 coding standard: we'll name our C++ program
to be the name of the file our main function is
in EXCEPT with NOOOOO SUFFIX!!!!!!!!!!!!
if you JUST want to compile one of your functions,
you can use (to look for syntax errors, for example):
g++ -c desired_file.cpp