CSE Module 1 A Programming Primer

Slides:



Advertisements
Similar presentations
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Advertisements

Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Programming is instructing a computer to perform a task for you with the help of a programming language.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Methods (Functions) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 4: Continuing with C++ I/O Basics.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
C++ Programming: Basic Elements of C++.
Fundamental Programming: Fundamental Programming Introduction to C++
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
First steps Jordi Cortadella Department of Computer Science.
1 C++ Programming Basics Chapter 1 Lecture CSIS 10A.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Objective: Students will be able to: Declare and use variables Input integers.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
COIT29222 Structured Programming 1 COIT29222-Structured Programming Lecture Week 02  Reading: Textbook(4 th Ed.), Chapter 2 Textbook (6 th Ed.), Chapters.
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
CompSci 230 S Programming Techniques
Basic concepts of C++ Presented by Prof. Satyajit De
Chapter Topics The Basics of a C++ Program Data Types
CSC111 Quick Revision.
TemperatureConversion
Introduction to Computer Science / Procedural – 67130
Basic Elements of C++.
Introduction to C++ October 2, 2017.
Introduction to Methods in java
Basic Elements of C++ Chapter 2.
BIT115: Introduction to Programming
Function Basics.
One-Dimensional Array Introduction Lesson xx
Introduction to Classes and Methods
Variables & Data Types Java.
Wednesday 09/23/13.
Building Java Programs
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
Lecture 1 Review of 1301/1321 CSE /26/2018.
Building Java Programs
CSE Module 1 A Programming Primer
Engineering Problem Solving with C++ An Object Based Approach
Building Java Programs
Life is Full of Alternatives
CSE Module 1 A Programming Primer
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Building Java Programs
CSE Module 1 A Programming Primer
Building Java Programs
Arithmetic Operations
Building Java Programs
Using string type variables
Building Java Programs
Chapter 1 c++ structure C++ Input / Output
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Lecture 1 Review of 1301/1321 CSE /26/2018.
CSE Module 1 A Programming Primer
Object-Oriented Programming and class Design
Presentation transcript:

CSE 1321 - Module 1 A Programming Primer 7/5/2019 CSE 1321 Module 1

Motivation You’re going to learn: The “skeleton” Printing Declaring variables Reading user input Doing basic calculations You’ll have lectures covering these topics 7/5/2019 CSE 1321 Module 1

Before we begin... You’re going to see things in 4 different languages Pseudocode Java C# C++ (not for everything, just parts) Ps 7/5/2019 CSE 1321 Module 1

Skeletons Skeleton programs: Are the smallest program you can write Are the minimal amount of code that compiles Do NOTHING Define the entry/starting point of the program Are something you should memorize You probably won’t understand what you’re about to see… and it’s OK! 7/5/2019 CSE 1321 Module 1

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

Skeletons using System; class MainClass { public static void Main (string[] args) { } Point out the beginning and end Note: The opening “{“ means BEGIN and the closing “}” means END 7/5/2019 CSE 1321 Module 1

Skeletons #include <iostream> int main () { return 0; } Point out the beginning and end Again note: The opening “{“ means BEGIN and the closing “}” means END 7/5/2019 CSE 1321 Module 1

Skeletons class MainClass { public static void main (String[] args) { } Note: Capitalization matters! 7/5/2019 CSE 1321 Module 1

Lesson #1: Learned All of them defined main, which is the entry/starting point of the program They have a BEGINNING and END 7/5/2019 CSE 1321 Module 1

Ps Printing to the Screen BEGIN MAIN PRINTLINE “Hello, World!” PRINTLINE “Bob” + “ was” + “ here” END MAIN Ps 7/5/2019 CSE 1321 Module 1

Printing to the Screen using System; class MainClass { public static void Main (string[] args) { Console.WriteLine ("Hello, World!"); Console.WriteLine ("Bob"+" was"+" here"); } Note: There’s also a Console.Write() 7/5/2019 CSE 1321 Module 1

Printing to the Screen #include <iostream> using namespace std; int main () { cout << " Hello, World!" << endl; cout << " Bob " << " was " << " here " << endl; return 0; } Point out the beginning and end The “using namespace” saves us from typing std::cout 7/5/2019 CSE 1321 Module 1

Printing to the Screen class MainClass { public static void main (String[] args) { System.out.println("Hello, World!"); System.out.println("Bob"+" was"+" here"); } Note: There’s also a System.out.print() 7/5/2019 CSE 1321 Module 1

Lesson #2: Learned All (decent) languages have the ability to print to the console/screen 7/5/2019 CSE 1321 Module 1

Variables A variable: Is a chunk of the computer’s memory Can hold a value Is of a particular “type” Integer Floating point number Character String – which is just text Usually, it’s two steps: “Declare” the variable – tell the computer what it is (do this only once) Assign values to the variable 7/5/2019 CSE 1321 Module 1

Declaring/Assigning Variables BEGIN MAIN END MAIN Ps 7/5/2019 CSE 1321 Module 1

Declaring/Assigning Variables BEGIN MAIN CREATE userName END MAIN userName ? Ps 7/5/2019 CSE 1321 Module 1

Declaring/Assigning Variables BEGIN MAIN CREATE userName CREATE studentGPA END MAIN userName ? studentGPA ? Ps 7/5/2019 CSE 1321 Module 1

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

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

Declaring/Assigning Variables using System; class MainClass { public static void Main (string[] args) { string userName; float gpa; userName = "Bob"; gpa = 1.2f; } 7/5/2019 CSE 1321 Module 1

Declaring/Assigning Variables #include <iostream> #include <string> using namespace std; int main () { string userName = "Bob"; float gpa = 1.2f; return 0; } Point out the beginning and end The “using namespace” saves us from typing std::cout 7/5/2019 CSE 1321 Module 1

Declaring/Assigning Variables class MainClass { public static void main (String[] args) { String userName; float gpa; userName = "Bob"; gpa = 1.2f; } 7/5/2019 CSE 1321 Module 1

Lesson #3: Learned All languages have the variables and the ability to assign values to them 7/5/2019 CSE 1321 Module 1

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

Reading Text from the User using System; class MainClass { public static void Main (string[] args) { string userInput; Console.Write("Please enter your name: "); userInput = Console.ReadLine(); Console.WriteLine("Hello, "+userInput); } 7/5/2019 CSE 1321 Module 1

Reading Text from the User #include <iostream> #include <string> using namespace std; int main () { string userName; cout << "Enter your name: "; getline(cin, userName); cout << "Hi, " << userName << "!" << endl; return 0; } Point out the beginning and end The “using namespace” saves us from typing std::cout 7/5/2019 CSE 1321 Module 1

Reading Text from the User import java.util.Scanner; class MainClass { public static void main (String[] args) { String userInput; System.out.print("Please enter your name: "); Scanner sc = new Scanner (System.in); userInput = sc.nextLine(); System.out.println("Hello, "+userInput); } 7/5/2019 CSE 1321 Module 1

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

Reading Numbers from the User using System; class MainClass { public static void Main (string[] args) { string userInput; Console.Write("Please enter your age: "); userInput = Console.ReadLine(); int age = Convert.ToInt32(userInput); Console.WriteLine("You are "+age+" years old."); } 7/5/2019 CSE 1321 Module 1

Reading Numbers from the User #include <iostream> using namespace std; int main () { int age = 0; cout << "Enter your age: "; cin >> age; cout << "You are " << age << " years old" << endl; return 0; } Point out the beginning and end Note: if we don’t need strings, don’t #include them! 7/5/2019 CSE 1321 Module 1

Reading Numbers from the User import java.util.Scanner; class MainClass { public static void main (String[] args) { int age; System.out.print("Please enter your age: "); Scanner sc = new Scanner (System.in); age = sc.nextInt(); System.out.println("You are "+age+" years old."); } 7/5/2019 CSE 1321 Module 1

We can read numbers (easy) and text (a little harder) from the user Lesson #4: Learned We can read numbers (easy) and text (a little harder) from the user 7/5/2019 CSE 1321 Module 1

Basic Operators Math operators Addition (+) Subtraction (-) Multiplication (*) Division (/) 7/5/2019 CSE 1321 Module 1

In-class Problem #0 Write a program that asks the users weight (in pounds) and prints out how much she/he weighs on the moon. Note: your moon weight is 16.5% of your Earth weight 7/5/2019 CSE 1321 Module 1

In-class Problem #1 Write a program that asks the user for a temperature in Fahrenheit and prints out that temperature in Kelvin. Formula: Kelvin = (Farh – 32) x 5/9 + 273.15 7/5/2019 CSE 1321 Module 1

In-class Problem #2 Assume: The average person burns 2500 calories per day. There are 3500 calories in one pound of fat. There are 365 days in a year Write a program that asks the user how many calories they consume in a day, and also asks how many years they will consume that many calories. Print out the number of pounds the person will gain/lose in that time. 7/5/2019 CSE 1321 Module 1

From now on, you should look for patterns in languages Summary All programs have an entry point (a BEGIN and END) If you don’t know where to begin, start with the skeleton All languages can print to the screen All languages have variables All languages can read text/numbers from the user All languages have basic operators From now on, you should look for patterns in languages 7/5/2019 CSE 1321 Module 1