CSE 1321 Module 1 A Programming Primer 1182022

  • Slides: 13
Download presentation
CSE 1321 - Module 1 A Programming Primer 1/18/2022 CSE 1321 MODULE 1 1

CSE 1321 - Module 1 A Programming Primer 1/18/2022 CSE 1321 MODULE 1 1

Skeletons BEGIN MAIN END MAIN Note: every time you BEGIN something, you must END

Skeletons BEGIN MAIN END MAIN Note: every time you BEGIN something, you must END it! Write them as pairs! 1/18/2022 CSE 1321 MODULE 1 Ps 2

Skeletons #include <iostream> int main() { std: : cout << "Hello World!n"; } Note:

Skeletons #include <iostream> int main() { std: : cout << "Hello World!n"; } Note: Capitalization matters! 1/18/2022 CSE 1321 MODULE 1 3

Skeletons #2 – Same thing! #include <iostream> using namespace std; int main() { cout

Skeletons #2 – Same thing! #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; } Note: The “namespace” thing keeps you from having to type “std” all the time! 1/18/2022 CSE 1321 MODULE 1 4

Printing BEGIN MAIN PRINTLINE “Hello, World!” PRINT “Bob” + “ was” + “ here”

Printing BEGIN MAIN PRINTLINE “Hello, World!” PRINT “Bob” + “ was” + “ here” END MAIN Ps 1/18/2022 CSE 1321 MODULE 1 5

Printing #include <iostream> using namespace std; int main() { cout << "Hello, World!" <<

Printing #include <iostream> using namespace std; int main() { cout << "Hello, World!" << endl; cout << "Bob" << " was" << " here!"; } 1/18/2022 CSE 1321 MODULE 1 6

Declaring/Assigning Variables user. Name BEGIN MAIN “Bob” CREATE user. Name CREATE student. GPA user.

Declaring/Assigning Variables user. Name BEGIN MAIN “Bob” CREATE user. Name CREATE student. GPA user. Name student. GPA = “Bob” 1. 2 student. GPA = 1. 2 END MAIN Ps 1/18/2022 CSE 1321 MODULE 1 7

Declaring/Assigning Variables #include <iostream> #include <string> using namespace std; int main() { string username;

Declaring/Assigning Variables #include <iostream> #include <string> using namespace std; int main() { string username; float gpa; username = "Bob"; gpa = 1. 2 f; } 1/18/2022 CSE 1321 MODULE 1 8

Reading Text from the User BEGIN MAIN CREATE user. Input PRINT “Please enter your

Reading Text from the User BEGIN MAIN CREATE user. Input PRINT “Please enter your name” READ user. Input PRINT “Hello, ” + user. Input END MAIN Ps 1/18/2022 CSE 1321 MODULE 1 9

Reading Text from the User #include <iostream> #include <string> using namespace std; int main()

Reading Text from the User #include <iostream> #include <string> using namespace std; int main() { string user. Input; cout << "Please enter your name: "; getline (cin, user. Input); cout << "Hello, " << user. Input << "!" << endl; } 1/18/2022 CSE 1321 MODULE 1 10

Reading Numbers from the User BEGIN MAIN CREATE user. Input PRINT “Please enter your

Reading Numbers from the User BEGIN MAIN CREATE user. Input PRINT “Please enter your age: ” READ user. Input PRINT “You are ” + user. Input + “ years old. ” END MAIN Ps 1/18/2022 CSE 1321 MODULE 1 11

Reading Numbers from the User #include <iostream> using namespace std; int main() { int

Reading Numbers from the User #include <iostream> using namespace std; int main() { int age; cout << "Please enter your age: "; cin >> age; cout << "You are " << age << " years old. " << endl; } 1/18/2022 CSE 1321 MODULE 1 12

Note There are times when reading strings and numbers immediately after one another is

Note There are times when reading strings and numbers immediately after one another is problematic. We’ll talk about that later. 1/18/2022 CSE 1321 MODULE 4 13