USER INTERACTION AND VARIABLES Tarik Booker CS 290 California State University, Los Angeles.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Data Types and Expressions
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 CSE1301 Computer Programming Lecture 6 C Primitives 3.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Structure of a C program
1 9/8/08CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
How Create a C++ Program. #include using namespace std; void main() { cout
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
CS150 Introduction to Computer Science 1
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Data Types.
1 CSE1301 Computer Programming Lecture 6: Components of a C Program (Part 2)
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Variables and Data Types
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
C programming for Engineers Lcc compiler – a free C compiler available on the web. Some instructions.
C Tokens Identifiers Keywords Constants Operators Special symbols.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
UniMAP Sem1-07/08EKT120: Computer Programming1 Week2.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Variables.
PHY 107 – Programming For Science. Announcements  Slides, activities, & solutions always posted to D2L  Note-taking versions before class, for those.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Computer Engineering 1 st Semester Dr. Rabie A. Ramadan 3.
Chapter 3 – Variables and Arithmetic Operations. Variable Rules u Must declare all variable names –List name and type u Keep length to 31 characters –Older.
Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
Variables Symbol representing a place to store information
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
A Sample Program #include using namespace std; int main(void) { cout
Tarik Booker CS 290 California State University, Los Angeles.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
CS 201 Lecture 2: Elementary Programming Tarik Booker CS 201 California State University, Los Angeles.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals 2.
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
User Interaction and Variables
Exercise 1 – Datentypen & Variablen
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Revision Lecture
By: Syed Shahrukh Haider
DATA HANDLING.
IDENTIFIERS CSC 111.
Unit-2 Objects and Classes
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Variables in C Topics Naming Variables Declaring Variables
Chapter 2: Java Fundamentals
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2: Java Fundamentals
C Data Types and Variable
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables in C Topics Naming Variables Declaring Variables
Variables and Constants
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

USER INTERACTION AND VARIABLES Tarik Booker CS 290 California State University, Los Angeles

What we will cover… Review Data Types Standard Input

Variables Can store values to be used (later) in a program Values can be changed Remember algebra: x + y = 34 y = 5 x =? Similar Concept in Programming

Variables (2) You must declare a variable in a program before you use it Format: datatype variableName; A variable can be of any name Follow identifier rules (later…) Descriptive names are best

Variables (3) Datatype variableName; Datatype variableName1, variableName2, …,variableName3; Datatype Specific classification of variables Different types / different memory sizes int, double (main ones) Discuss later

Variables (4) Variables are Case-Sensitive in C Uppercase and Lowercase Not the Same “Variable1” is not the same as “variable1”

Identifiers To name variables or functions Called identifiers Should obey rules: Consists of letters (upper/lower), digits, underscores Must start with a letter (alphabetic character) Must NOT start with a digit!!! Cannot be a reserved word (int, return, main, etc.) Can be up to 31 characters

Identifiers (2) Which are legal? helloworld aadzxvcna thjke456hftg3sd HappyHappy 34joy56 $Dollarsand return mains #love Why / Why not?

Char There is another type of variable other than integers or floating-point Char Allows you to store a single character Uses ASCII American Standard Code for Information Interchange Each character is assigned to a particular number ASCII Table ‘A’ is 65 ‘a’ is 97 Lowercase is higher than Uppercase Add 32 to change an uppercase letter to lowercase Subtract 32 to change a lowercase letter to uppercase

ASCII Table

Reading in a Value from Standard In Before, we used a function to send information to Standard out What was it? Now we can get information from Standard in Let’s get a character from standard in Use the getchar() function Stores the result as an integer (the value of the character in ASCII)

getchar() How do we use getchar()? Declare a variable of character type Set the value of the character to the result of getchar() Ex: # include int main () { char c; printf("Enter character: "); c = getchar(); }

getchar() How do we display the character back? Use putchar() Ex: #include int main () { char c; printf("Enter character: "); c = getchar(); printf("Character entered: "); putchar(c); return(0); }

Data Types Char is considered a data type A data type is just the way information is stored in the program char, int, float, double, void (will discuss) are called primitive data types or primitives Other types of primitive data types

Data Types CharCharacter IntInteger DoubleDouble Precision Floating-Point Voidno type (or empty) Void Use this data type when no type is expected Primarily used for functions to specify not a return type Look at main

Data Types (2) C has many many different types of basic (or primitive) data types Different versions of char, int, long, double Char Signed charuses signed version of char Unsigned charuses unsigned version of char

Data Types (3) Short16-bit integer type Short int Signed short Signed short int Unsigned short Unsigned short int

Data types (4) Int Signed int Unsigned Unsigned int Longlong integer (at least 32 bits) Long int Signed long Signed long int Unsigned long Unsigned long int

Data types (5) Long long64-bit integer Long long int Signed long long Signed long long int

Data Types (6) Float Double Long double There are also other types: Boolean (next week) True/False

We will do in class work today! Let’s do some problems!