COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez

Slides:



Advertisements
Similar presentations
FORTRAN Short Course Week 1 Kate T-C February 17, 2008.
Advertisements

Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
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.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
1 Homework Turn in HW2 at start of next class. Starting Chapter 2 K&R. Read ahead. HW3 is on line. –Due: class 9, but a lot to do! –You may want to get.
CS150 Introduction to Computer Science 1
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
assumes basic arithmetic
Unit 3—Part A Computer Memory
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
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.
CREATED BY, MS. JENNIFER DUKE BITS, BYTES, AND UNITS OF MEASUREMENT.
Computer Storage & Representing Numbers CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Input & Output: Console
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
1 Please switch off your mobile phones. 2 Data Representation Instructor: Mainak Chaudhuri
CSC 107 – Programming For Science. Announcements  Textbook available from library’s closed reserve.
Hardware Data Storage.
Fill in the blanks: (1) _________ has only two possible values 0 and 1. (2) There are __________bits in a byte. (3) 1 kilobyte of memory space can store.
C Tokens Identifiers Keywords Constants Operators Special symbols.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
First Program.  The type of all data used in a C program must be specified  A data type is a description of the data being represented ▪ That is, a.
Introduction to Computer Systems and the Java Programming Language.
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Computer Systems Nat 4/5 Computing Science Data Representation Lesson 2: Floating Point Representation.
Numerical Representation Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Unit 2—Part A Computer Memory Computer Technology (S1 Obj 2-3)
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
COP Structures Instructor: Diego Rivera-Gutierrez I’m back baby!
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Introduction to Programming
How We Measure Memory. Learning Goal Today we are going to learn how the computer stores information.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
How We Measure Memory. At the Bottom of things A piece of digital information is always stored as a sequence of binary states. What’s that mean you ask???
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Variables Symbol representing a place to store information
1.2 Primitive Data Types and Variables
CPS120: Introduction to Computer Science Variables and Constants.
Know what a computer is used for Understand the difference between hardware and software Be able to describe the way that data is stored in a computer.
COP 3275 – Character Strings Instructor: Diego Rivera-Gutierrez.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
A Sample Program #include using namespace std; int main(void) { cout
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
Binary a. express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal;
Binary Numbers. Base 10 and Base 2  We normally work with numbers in base 10.  In base 10 we use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.  Everything.
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.
Numerical Representation Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
© OCR 2016 Unit 2.6 Data Representation Lesson 1 ‒ Numbers.
User Interaction and Variables
How Computers Store Variables
Data Representation N4/N5.
Storage Hardware This icon indicates the slide contains activities created in Flash. These activities are not editable. For more detailed instructions,
Computer Memory Digital Literacy.
Numerical Representation
Memory Parts of a computer
ITEC113 Algorithms and Programming Techniques
Unit 2 Computer Memory Computer Technology (S1 Obj 2-3)
Unit 3—Part A Computer Memory
Data Representation Numbers
How do computers work? Storage.
Numerical Representation
Unit 3—Part A Computer Memory
Numerical Representation
LO1 – Understand Computer Hardware
Numerical Representation
Presentation transcript:

COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez

ADMINISTRATIVE STUFF New rule: whenever you participate tell me your name! Homework #1is available for submission via Canvas! Did you guys register for a CISE account? If not, do so soon! You should have heard back already if you registered on Monday. Takes 2-3 business days for them to get back. If you haven’t submitted your registration yet, I’m afraid you won’t be able to test your Homework 1 on the server  If we need to, I’ll cover a few alternatives. (Disclaimer: None of them can guarantee 100% that it would be as effective as trying it directly on the server)

ALTERNATIVES FOR THE PROCRASTINATORS Ask one of your classmates that does have an account to help you test. If you do so, be careful to abide by the Honor code! Please don’t cheat! I’m starting to like you. I won’t teach anything about these, and can’t guarantee it will be the same as the server, but: At the very least test in CodeBlocks (free, good IDE, available for Windows and Mac)CodeBlocks You could potentially use MinGW (Linux simulator for Windows)MinGW

VARIABLES AND TYPES

WHAT IS A VARIABLE? Similar to what a variable is in Algebra/Math. A variable is “something” in my program that stores a value

STORING VALUES Remember computers work in binary: 1 or true (high voltages) 0 or false (low voltages) Potential instruction: Everything we store in a computer is eventually a long binary number. Numbers Text Photos Music Videos

UNITS OF MEASURE IN BINARY Name (abbreviation) Size Bit (b)1 single binary digit (0 or 1) Byte (B)8 bits Kilobyte (KB)1024 bytes Megabyte (MB)1024 KB Gigabyte (GB)1024 MB Terabyte (TB)1024 GB Petabyte (PB)1024 TB Notice how elegant: everything is a power of 2! 2 0 = 12 3 = = 1024

MEMORY (RAM) VS. HARD DRIVE Disclamer: I’m oversimplifying a bit of this content to make it easier to understand. Who has ever carefully selected a computer? By looking at the tech specs, not how shinny it looked. What do “ memory ” and “ hard disk drives ” have in common? Devices (parts of a computer) that store information Units in which we measure their size Gigabytes (GB) or Terabytes (TB)

MEMORY VS. HARD DRIVE UsuallyMemoryHard Drive More storage? Faster access? More expensive? More relevant to today’s class? Where do programs usually “live”? Does not require power to keep information During executionAt any other time

SO WHAT, DIEGO? WHY DO WE CARE? Because “something” A variable is “something” in my program that stores a value So “something” is actually a space in memory! A variable is a space in memory where my program will store a value Each variable is associated with a type that tells us how to interpret the binary number stored at that location

DEFINING AND ASSIGNING VARIABLES The basic definition for a variable is going to look like this: ; is like a “name”. It can be almost anything! Rules: Starts with an alphabetic character (a-z or A-z) or an underscore (‘_’) – That’s not an emoticon… Can contain alphabetic characters (a-z and/or A-z), numbers (1-9) and underscores (‘_’) No spaces, no other weird characters. Good practices tell us it should be something meaningful. Choosing good identifiers for our variables is important. "Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - Rick Osborne

EXAMPLES OF VARIABLE IDENTIFIERS Valid sum Flag myFirstResult Variable_1 adorable_penguin_1002 _this6thVariableIHaveNoIdeaWhatToName Please notice that “being valid” and “being meaningful” are very different.

EXAMPLES OF VARIABLE IDENTIFIERS Invalid 101Dalmatians $money #why_does_C_hates_hashtags May_I_ask_you_a_question? my variable

WHAT TYPES ARE AVAILABLE TypeValues intInteger numbers (no decimals) floatNumbers, including those with decimals doubleA float with more “precision” charA single character. ‘A’ for example. _BoolEither a 1 or a 0 (true or false)

EXAMPLES OF VARIABLE DEFINITIONS int sum; _Bool Flag; float myFirstResult; char Variable_1; double adorable_penguin_1002; int _this6thVariableIHaveNoIdeaWhatToName; Do I have to define all variables separately? What if I want to define 3 integers quickly?

DEFINING MULTIPLE VARIABLES IN A SINGLE LINE int sumA, sumB; _Bool Flag1, Flag2, Flag3; float myFirstResult, mySecondResult; char Variable_1, Variable_2; double adorable_penguin_1002, adorable_penguin_1003; Separate identifiers with commas. In this case both sumA And sumB would have type integer.

ASSIGNING VALUES TO A VARIABLE The basic assignment structure is: = ; could be a constant or some calculation. For now let’s talk about constants. Examples: TypeExamples (separated by commas) int0, 100, -200, -1717, float0.100, , f, 90.84F double0.100L, l, char‘a’, ‘b’, ‘#’, ‘_’, ‘\n’. ‘\’’, ‘\\’ _Bool1, 0

EXAMPLES! int sum; sum = 100; float myFirstResult; myFirstResult = 0.01f; Ugh! Two lines to define and assign my variable… that is so tedious.. Is there a more efficient way?

EXAMPLES int sum = 100; float myFirstResult = 0.01f; char Variable_1 = ‘D’; /*Why ‘D’ you ask? Well… it starts my name after all… */ So much theory… Let’s test it!

PRINTING A VARIABLE We will use, surprise surprise printf How? By using a special character in the string… Each type uses a different character, we will need to learn them… TypePrintf characters int%i, %x, %o float%f, %e, %g, %a double%f, %e, %g, %a char%c _Bool%i, %u

PRINTING A VARIABLE #include int main(void) { int grade = 100; printf("I will get a %i in my first C HW\n", grade); return 0; }

PRINTING A VARIABLE #include int main(void) { char letter = 100; printf("I will get a %i in my first C HW\n“, sum); return 0; }

PRINTING TWO OR MORE VARIABLES #include int main(void) { char letter = 100; printf("I will get a %i in my first C HW\n“, sum); return 0; } #include int main(void) { char letter = 'D'; int grade = 100; printf(“With a %i in my HW I won't get a %c in my C programming class\n", grade, letter); return 0; }

TYPE SPECIFIERS Specifier long short unsigned signed So, can I have a infinitely large number stored in a variable of type int?