// ------------------------------------------------------------ // hello.cpp // ------------------------------------------------------------ #include // Stream library #include // Console i/o library #include // Math library // -------------------------------------------------------- char QUIT = 0; // global variable void wait(); // declaration of two functions double sqr(double x); // -------------------------------------------------------- // Main progam void main () { cout << " ------------------------- \n"; cout << " Welcome to hello.cpp\n"; cout << " ------------------------- \n\n"; int i; // declare i = 1; // assign a value int j = 3; // one step int k(5); // by casting cout << " i = " << i << " j = " << j << " k = " << k <<"\n\n"; double x,y; x = y = 0; x = 3; y = sqr(x); cout << " sqr(" << x << ") = " << y << "\n\n"; x = 3.14159/4; y = sin(x); cout << " sin(" << x << ") = " << y << "\n\n"; wait(); if (QUIT) cout << " QUIT = 1"; else cout << " QUIT = 0"; } // --------------------------------------------------------- // definitions (implementations) double sqr(double x) { return x*x; } void wait() { QUIT = 0; char q = getch(); if (q == 'q') QUIT = 1; } // --------------------------------------------------------- /* output ------------------------- Welcome to hello.cpp ------------------------- i = 1 j = 3 k = 5 sqr(3) = 9 sin(0.785397) = 0.707106 */