File: threecppexamples.txt ( July 1998 Jacob Y. Kazakia) Example 1 ---------- /* Example welcome.cpp - Welcome to Lehigh Use the compiler Visual C++ */ #include // stream i/o library file access // Program to print a single statement void main( ) // function heading { cout<<" Welcome to Lehigh"; //------- Use the following three lines in order to keep the window open cout<<" \n\n enter e(exit) to exit ...." ; char hold; cin>>hold; } Example 2 ----------- /* Example area1.cpp - Area of a circle Use the compiler Visual C++ */ #include // stream i/o library file access // Program to to calculate the area of a circle void main( ) // function heading { float radius, area; // variable declarations (typing) cout << "radius = ?"; // output statement (prompt) cin >> radius; // input statement area=3.1415927*radius*radius; // assignment statement cout << " area =" << area ; // output statement //------- Use the following three lines in order to keep the window open cout<<" \n\n enter e(exit) to exit ...." ; char hold; cin>>hold; } Example 3 ------------- /* example on the sum of 3 numbers entered file: sumof3.cpp FALL 1998 ___________________________________ Jacob Y. Kazakia jyk0 July 1, 1998 Programming assignment 001 Recitation Instructor: J.Y.Kazakia Recitation Section 01 ___________________________________ Purpose: This program calculates the sum of three numbers which are entered through the keyboard. Algorithm: The operation of addition. sum = number-1 + number_2 + number_3 */ #include // header which contains the functions // needed for input and output void main() { // variables are typed and defined float sum; // the value of the sum float number_1, number_2, number_3; // the three numbers to be entered // prompt for and read the first number cout<< endl<<"Enter the first number >>>"; cin>> number_1; // prompt for and read the second number cout<< endl<<"Enter the second number >>>"; cin>> number_2; // prompt for and read the third number cout<>>"; cin>> number_3; sum = number_1 + number_2 + number_3; cout<>hold; }