// file: lecture_19/myprog.cc // // revision history: // 20180724 (JP): initial version // // usage: // example.exe // // compilation: // g++ -o example.exe example.cc myfuncts_00.cc myfuncts_01.cc // // expected output: // nedc_000_[1]: myprog.exe // program name: myprog.exe // sum of 27 and 27.272699 is 54.272697 // // This is a simple C program where the code exists in multiple files. // This version was designed to demonstrate how to browse files in the // the Amazon AWS IDE. // // local include files // #include "example.h" // main: example // // This is a driver program that does some very simple things. // int main(int argc, const char** argv) { // declare a variable for status // int status = (int)0; // call the first function - call by value // /* float value_alex = (float)1.0; fprintf(stdout, "call by value:\n"); fprintf(stdout, "before: value_alex = %f\n", value_alex); fprintf(stdout, "return value = %f\n", set_value(value_alex)); fprintf(stdout, "after: value_alex = %f\n", value_alex); // call the second function - call by reference // float* ptr_value_alex = new float; *ptr_value_alex = (float)1.0; fprintf(stdout, "\ncall by reference:\n"); fprintf(stdout, "before: value_alex = %f\n", *ptr_value_alex); fprintf(stdout, "return value = %f\n", set_value(ptr_value_alex)); fprintf(stdout, "after: value_alex = %f\n", *ptr_value_alex); */ // demonstrate variable scope // /* for(long jordan = 0; jordan < 99; jordan++) { long sum = 99; fprintf(stdout, "jordan = %ld\n", jordan); } */ /* // with great power comes great responsibility // char* buf = (char*)NULL; fprintf(stdout, "before: buf = %u\n", buf); mymemory(buf); fprintf(stdout, "after: buf = %u\n", buf); */ // more power... // /* char* buf = new char[10]; fprintf(stdout, "before: buf = %u\n", buf); mymemory(buf); fprintf(stdout, "after: buf = %u\n", buf); fprintf(stdout, "after: buf = %s\n", buf); */ // call a recursive function // /* fprintf(stdout, "the factorial of %d = %d\n", 9999, fact(9999)); */ // matrices // float x[2][3]; float *y = (float*)x; mymatrix(y, 2, 3); fprintf(stdout, "mymatrix = %f %f %f\n", x[0][0], x[0][1], x[0][2]); float** mm; mm = float*[3]; mm[0] = float[6]; mm[1] = float[99]; mm[2] = float[27]; mymatrix(mm); // exit gracefully // return(status); }