Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSE Module 1 A Programming Primer

Similar presentations


Presentation on theme: "CSE Module 1 A Programming Primer"— Presentation transcript:

1 CSE 1321 - Module 1 A Programming Primer
10/4/2019 CSE 1321 Module 1

2 Ps Skeletons BEGIN MAIN END MAIN
Note: every time you BEGIN something, you must END it! Write them as pairs! 10/4/2019 CSE 1321 Module 1

3 Skeletons #include <iostream> int main() {
std::cout << "Hello World!\n"; } Note: Capitalization matters! 10/4/2019 CSE 1321 Module 1

4 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! 10/4/2019 CSE 1321 Module 1

5 Ps Printing BEGIN MAIN PRINT “Hello, World!”
PRINT “Bob” + “ was” + “ here” END MAIN Ps 10/4/2019 CSE 1321 Module 1

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

7 Declaring/Assigning Variables
BEGIN MAIN CREATE userName CREATE studentGPA userName ← “Bob” studentGPA ← 1.2 END MAIN userName “Bob” studentGPA 1.2 Ps 10/4/2019 CSE 1321 Module 1

8 Declaring/Assigning Variables
#include <iostream> #include <string> using namespace std; int main() { string username; float gpa; username = "Bob"; gpa = 1.2f; } 10/4/2019 CSE 1321 Module 1

9 Reading Text from the User
BEGIN MAIN CREATE userInput PRINT “Please enter your name” READ userInput PRINT “Hello, ” + userInput END MAIN Ps 10/4/2019 CSE 1321 Module 1

10 Reading Text from the User
#include <iostream> #include <string> using namespace std; int main() { string userInput; cout << "Please enter your name: "; getline (cin, userInput); cout << "Hello, " << userInput << "!" << endl; } 10/4/2019 CSE 1321 Module 1

11 Reading Numbers from the User
BEGIN MAIN CREATE userInput PRINT “Please enter your age: ” READ userInput PRINT “You are ” + userInput + “ years old.” END MAIN Ps 10/4/2019 CSE 1321 Module 1

12 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; } 10/4/2019 CSE 1321 Module 1

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


Download ppt "CSE Module 1 A Programming Primer"

Similar presentations


Ads by Google