1. Introduction to C++ (Great Courses)
// Program 1_13 // Printing an address #include <iostream> using namespace std; int main() { cout << "John Keyser" << endl; cout << "123 Any Street" << endl; cout << "Somewhere, TX 77777" << endl; }
Program 1_13 Printing an address Use 3 cout statements Output: John Keyser 123 Any Street Somewhere, TX 77777
// Program 1_14 // Printing an address #include <iostream> using namespace std; int main() { cout << "John Keyser" << endl << "123 Any Street" << endl << "Somewhere, TX 77777" << endl; }
Program 1_14 Printing an address Use 1 cout statement Output: John Keyser 123 Any Street Somewhere, TX 77777
// Program 1_2 // Our first program! using Visual Studio 2017 or earlier #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl;}
Program 1_2 Our first program! using Visual Studio 2017 or earlier * multiple instructions of code on one line of text* Ouput: Hello, World!
// Program 1_3 // Our first program! #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl ; }
Program 1_4 Our first program! *a single instruction of code spread over multiple lines of text* Output: Hello, World!
// Program 1_5 // Our first program! // Last edited by JK on 1/1/2020 #include <iostream> using namespace std; int main() { //Print a greeting cout << "Hello, World!" << endl; //Need more output here }
Program 1_5 Our first program! (with comments) Last edited by JK on 1/1/2020 (comment) *Header information* Print a greeting (comment) *Program* Need more output here (comment) Output: Hello, World!
// Program 1_6 // Our first program! #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; //Outputting text }
Program 1_6 Our first program! (with comment "Outputting text" in the middle of the program at the end of the line) Output: Hello, World!
// Program 1_7 // Our first program! #include <iostream> using namespace std; int main() { /* This is a multi-line comment. It continues until the comment is "closed" */ cout << "Hello, World!" << endl; }
Program 1_7 Our first program! (with comment "This is a multi-line comment. It continues until the comment is "closed" " at the beginning of the program) Output: Hello, World!
// Program 1_8 /* Our first Program! */ #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; }
Program 1_8 Our first Program! (without using // for the comment "Our first Program!") Output: Hello, World!
// Program 1_9 /***********************************/ /* Our First Program! */ /***********************************/ #include <iostream> using namespace std; /* About to start the main program */ int main() { cout << "Hello, World!" << endl; // This is a single line comment }
Program 1_9 Our First Program! (using comments to create a block for visual separation. Put lines of asterisks around "Our First Program", and insert the comment "About to start the main program" into its logical place.) Output: Hello, World!
// Program 1_12 // Putting multiple endl's in one cout statement #include <iostream> using namespace std; int main() { cout << "Howdy, John!" << endl << "Are you ready to learn C++?" << endl << "Let's get started..." << endl; } Output: Howdy, John! Are you ready to learn C++? Let's get started...
A longer program, giving a greeting: "Howdy, John!", "Are you ready to learn C++?", and "Let's get started..." with comment "Putting multiple endl's in one cout statement"
// Program 1_1 // Our first program! #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; }
Program 1_1 Our first program! Output: Hello, World!
// Program 1_10 // A longer program, giving a greeting #include <iostream> using namespace std; int main() { cout << "Howdy, John!" << endl; cout << "Are you ready to learn C++?" << endl; cout << "Let's get started..." << endl; }
Program 1_10 A longer program, giving a greeting Output: Howdy, John! Are you ready to learn C++? Let's get started...
// Program 1_11 // endl's removed #include <iostream> using namespace std; int main() { cout << "Howdy, John!"; cout << "Are you ready to learn C++?"; cout << "Let's get started..."; } Output: Howdy, John!Are you ready to learn C++?Let's get started...
Program 1_11 endl's removed Output: Howdy, John!Are you ready to learn C++?Let's get started...
// Program 1_4 // A modified first program #include <iostream> using namespace std; int main() { cout << "Howdy, John!" << endl; }
Program 1_4 A modified first program Output: Howdy, John!