COSC 215 Class notes 1/8/08 ---------------------------------------------------------------------- For C++ programs: To edit: Run Emacs: Applications -> Programming -> Emacs Text Editor In Emacs, File -> Open File add.C Type in your program To compile: Tools -> Compile Erase "make -k" and type: g++ add.C -o add Type y if asked to save your file To run: M-x shell (where M-x is Escape x) ./add ---------------------------------------------------------------------- For Java programs: ---------------------------------------------------------------------- One time only: Edit your .bashrc file: Run Emacs: Applications -> Programming -> Emacs Text Editor In Emacs, File -> Open File .bashrc Add the following line: export PATH=/programs/java/jdk1.5.0_07/bin:$PATH Save the file: File -> Save (current buffer) Go to a shell buffer: M-x shell Type source .bashrc ---------------------------------------------------------------------- To edit: Run Emacs: Applications -> Programming -> Emacs Text Editor In Emacs, File -> Open File add.java Type in your program To compile: Tools -> Compile erase "make -k" (or whatever is there) and type javac add.java Type y if asked to save your file To run: M-x shell (where M-x is Escape x) java add ---------------------------------------------------------------------- //add.C #include #include using namespace std; // To compile: g++ add.C -o add int main(void) { // This program will prompt the user to type into two numbers and then // will print out the sum. int a,b; cout << "Enter two numbers> "; cin >> a >> b; cout << "The sum of " << a << " and " << b << " is " << a + b << endl; return 0; } ---------------------------------------------------------------------- // add.java class add { public static void main(String args[]) { int a=1, b=2; // Read in two numbers, a and b // this space intentionally left blank // Print out their sum System.out.println("The sum of " + a + " and " + b + " is " + a + b); } } ----------------------------------------------------------------------