CSCI 161: Introduction to Programming

Slides:



Advertisements
Similar presentations
Senem Kumova Metin Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.
Advertisements

COSC 120 Computer Programming
1 Hardware - devices for Input. 2 Hardware - devices for Input Processing.
Main Memory Lecture 2 CSCI 1405, CSCI 1301 Introduction to Computer Science Fall 2009.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Introduction to Computers
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition by Tony Gaddis, Judy Walters,
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Chapter 3 – Computer Hardware Computer Components – Hardware (cont.) Lecture 3.
Bits and Data Storage. Basic Hardware Units of a Computer.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Why Program? Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer.
Chapter Introduction to Computers and Programming 1.
CSC 125 Introduction to C++ Programming Chapter 1 Introduction to Computers and Programming.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Computer Hardware and Software Jinchang Wang. Hardware vs. Software Hardware is something tangible. Computer hardware includes electronic circuitry and.
CSCI 125 & 161 Lecture 2 Martin van Bommel. Hardware vs Software Hardware - physical components you can see and touch –e.g. processor, keyboard, disk.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Introduction to Computers
Introduction to Computers
1 Introduction to Computers Prof. Sokol Computer and Information Science Brooklyn College.
1 Introduction to Computers Lect 1 Won’t tell you much you don’t know. (Misleading– the course gets more conceptual as we create webpages.) Will go into.
Chapter 1 Overview of Computers and Programming J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Intro to Computers Computer Apps 1.
Introduction to Computer Systems and the Java Programming Language.
IT Groundwork ICS3UC - Unit 1 Hardware. Overview of Computer System.
CSCI-100 Introduction to Computing Hardware Part I.
Data Storage © 2007 Pearson Addison-Wesley. All rights reserved.
COMPUTER MEMORY & DATA STORAGE. ROM ROM is short for Read Only Memory. –I–It is permanent, long-term memory which cannot be erased or changed in any way;
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Quiz 2 Results. What Is Wrong? #include using namespace std int Main() { // Say Hello 4 times for(i == 0; i < 3; i++) { cout >> "Hello World!"
Data Storage © 2007 Pearson Addison-Wesley. All rights reserved.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Brief Version of Starting Out with C++ Chapter 1 Introduction to Computers and Programming.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction to Programming. Key terms  CPU  I/O Devices  Main memory  Secondary memory  Operating system  User interface  Application  GUI 
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming
BASIC PROGRAMMING C SCP1103 (02)
Chapter 1: An Overview of Computers and Programming Languages
Engineering Problem Solving With C An Object Based Approach
Microsoft Imagine All KU students currently enrolled in a CS class are eligible to receive Microsoft software, including Operating Systems development.
BASIC PROGRAMMING C SCP1103 (02)
Overview of Computers and Programming Chapter 1
Storage Hardware This icon indicates the slide contains activities created in Flash. These activities are not editable. For more detailed instructions,
Chapter 2 Assignment and Interactive Input
Introduction to Computer Architecture
Chapter 1: An Overview of Computers and Programming Languages
C++ Programming: From Problem Analysis to Program Design
Introduction to Computers
COMPUTER MEMORY & DATA STORAGE
Introduction to Computers
COMPUTER MEMORY & DATA STORAGE
Chapter 1: Introduction to Computers and Programming
Chapter 2 Elementary Programming
Introduction to Computers
AS Level ICT Selection and use of storage requirements, media, and devices: storage and storage capacity Unit 1 Topic a - Selection and use of storage.
ICS103 Programming in C 1: Overview of Computers And Programming
Chapter 1: Introduction to Computers and Programming
Chapter 1: Introduction to Computers and Programming
Presentation transcript:

CSCI 161: Introduction to Programming Lecture 3: First Program Data representation

First Program //library inclusion //function “main” //display string #include <iostream> using namespace std; int main() { cout << ”Hello world.”; return 0; } //library inclusion //function “main” //display string

Programming Errors Vocabulary and grammar - syntax Rules determine if statement legally constructed - syntax rules Compiler checks rules - gives syntax errors Programs also contain errors in logic - bugs Debugging - finding & fixing logic errors

A program to output the sum of two numbers

A more flexible program: read the two numbers from console #include <iostream> using namespace std; int main() { int num1, num2; //two int variables to hold the two numbers int sum; //variable sum to hold the result of the sum of the two numbers //input the two numbers, first print message to the users on what they need to input cout << "please input two numbers:" << endl; cout << "num1 = "; cin >> num1; cout << "num2 = "; cin >> num2; //calculate the sum, store the result in variable sum sum = num1 + num2; //output the result cout << "the sum is " << sum << endl; return 0; }

Variable A variable should be declare as with a type: Examples: int num1, num2; //two int variables to hold the two numbers int sum; Type example int, char, string

Running the program Wrong result! What happen? A run: please input two numbers: num1 = 2 num2 = 3 the sum is 5 Another run: num1 = 450 num2 = 300 the sum is 750 One more time please input two numbers: num1 = 2000000034 num2 = 9999999999 the sum is -147483615 Wrong result! What happen?

Data Representation

Components of a Computer Start with components of a computer again to talk about memory and data representation. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Memory © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Memory Cells memory cell an individual storage location in memory address of a memory cell the relative position of a memory cell in the computer’s main memory contents of a memory cell the information stored in a memory cell, either a program instruction or data stored program concept a computer’s ability to store program instructions in main memory for execution 10001100 ….. Memory cells contain a bunch of 0 and 1s. © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Figure 1.5 Relationship Between a Byte and a Bit 00101100 Byte Bit © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Memory data storage setting the individual bits of a memory cell to 0 or 1, destroying its previous contents data retrieval copying the contents of a particular memory cell to another storage area random access memory (RAM) the part of main memory that temporarily stores programs, data, and results © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Memory read-only memory (ROM) the part of main memory that permanently stores programs or data volatile memory memory whose contents disappear when the computer is switched off © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. Memory secondary storage units such as disks or flash drives that retain data even when the power to the drive is off disk thin platter of metal or plastic on which data are represented by magnetized spots arranged in tracks optical drive device that uses a laser to access or store data on a CD or DVD or Blu-ray Disk © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

© 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved. File System file named collection of data stored on a disk directory a list of the names of files stored on a disk subdirectory a list of the names of files that relate to a particular topic © 2016 Pearson Education, Inc., Hoboken, NJ. All rights reserved.

Internal Representation Each unit of memory a two-state device off or on, 0 or 1 represent in Binary, two Binary Digits (bits) Organized into groups of 8 bits - bytes represents single keyboard character Larger grouping of 16 or 32 bits - word represents single integer value identified by address for access

Memory Sizes Kilobyte (K) = 210 = 1,024 bytes Megabyte (Mb) = 220 = 1,048,576 bytes Gigabyte (Gb) = 230 = 1,073,741,824 bytes

Decimal Number Systems Base 10 Digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 e.g. 34210 = = 3 x 102 + 4 x 101 + 2 x100 = 3 x 100 + 4 x 10 + 2 x 1 = 300 + 40 + 2

Binary Number System Base 2 Digits 0, 1 e.g. 1102 = = 1 x 22 + 1 x 21 + 0 x 20 = 1 x 4 + 1 x 2 + 0 x 1 = 4 + 2 + 0 = 6

Counting in Binary Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 Decimal Binary 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

How many symbols can N digit represent? 3 digit allows representing 8 numbers (symbols): 0-7 4 16: 0 – 15 N 2N