CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang

Slides:



Advertisements
Similar presentations
C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
1 9/10/07CS150 Introduction to Computer Science 1 Data Types Section 2.7 – 2.12 CS 150 Introduction to Computer Science I.
Your First C++ Program Aug 27, /27/08 CS 150 Introduction to Computer Science I C++  Based on the C programming language  One of today’s most.
CS31: Introduction to Computer Science I Discussion 1A 5/7/2010 Sungwon Yang
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
© 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5/e Starting Out with C++: Early Objects 5 th Edition Chapter 2 Introduction.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
How Create a C++ Program. #include using namespace std; void main() { cout
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
CS150 Introduction to Computer Science 1
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 2: Introduction to C++.
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
COMPUTER SCIENCE I C++ INTRODUCTION
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Input & Output: Console
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Chapter 2 Overview of C++. A Sample Program // This is my first program. It calculates and outputs // how many fingers I have. #include using namespace.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
CS31: Introduction to Computer Science I Discussion 1A 4/9/2010 Sungwon Yang
Instructor - C. BoyleFall Semester
CPS120: Introduction to Computer Science
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Fundamental Programming: Fundamental Programming Introduction to C++
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Structured Programming (4 Credits) HNDIT Week 2 – Learning Outcomes Design an algorithmic solution for simple problem such as computation of a factorial,
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 2 C++ Syntax and Semantics, and the Program Development Process Topics – Programs Composed of Several Functions – Syntax Templates – Legal C++
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Basic concepts of C++ Presented by Prof. Satyajit De
C++ First Steps.
Jie(Jay) Wang Week1 Sept. 30
Chapter 1.2 Introduction to C++ Programming
LESSON 2 Basic of C++.
Chapter 2: Introduction to C++
Computing Fundamentals
Introduction to C++ October 2, 2017.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2: Introduction to C++.
C++ Programming Lecture 3 C++ Basics – Part I
Fundamental Programming
C++ Basics CSci 107. A C++ program //include headers; these are modules that include functions that you may use in your //program; we will almost always.
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang

Programming Language Here are examples: – In English: Hey Computer, say “Hello!” – In a programming language, C++: cout << “Hello!” << endl; – In a machine language: (or something similar to this)

Programing Language Programmers – Translate human language into programing language Writing C++ code Compilers – Translate programing language into machine language Making executable file

Example 1 Print out a text on the screen

Some Basic Rules #include – Contains libraries related to input & output using namespace; – Just write this statement at this point int main() – Your program start from this function Every statement ends with a semicolon – Missing semicolon will cause compile error Case sensitive – C++ distinguishes between upper and lower case Text needed to be double-quoted – Otherwise, C++ will recognize it as something else White spaces

What can we learn from the example cout object – Print out “text” on the screen – Basic syntax cout << “what you like to write”; – endl New line cout << “what you like to write” << endl; – << Careful with the direction Not >> – You can use more “text” cout << “what you like to write” << endl << “more words”;

Quick question What will be displayed on the screen? #include using namespace std; int main() { cout << "Hello!" << "My na"; cout << "me is Sung"; cout << endl << "won. What is" << endl; cout << "your " << "name" << endl << "?" << endl; }

Answer Hello!My name is Sung won. What is your name ?

Quick Question Can you find any mistakes? Hint: 7 mistakes include Using name space std; int main() { cout << "Hello!" << "My na"; cout << 'me is Sung'; cout << endl << "won. What is" << endl cout > "name" << endl << "?" << endl;

Answer include Using name space std; int main() { cout << "Hello!" << "My na"; cout << 'me is Sung'; cout << endl << "won. What is" << endl cout > "name" << endl << "?" << endl; Double quote! Should be lower case No space! ; is missing # is missing Wrong direction } is missing

Example 2 Input from keyboard #include using namespace std; int main() { int age ; age = 0; cout << "How old are you?" << endl; cin >> age; cout << "I am " << age << " years old." << endl; }

What can we learn from the example Variables – “data storage” – int age; Declaration: prepare space for ‘age’ int: integer age: identifier, name of variable – age = 0; Assign 0 to age

Data types int : integer – 4 bytes long – ranging from -2,147,483,647 to 2,147,483,647 double : real numbers – 8 bytes long – ranging from −1.7 × to 1.7 × bool : boolean – 1 byte long – either true or false (IGNORE FOR NOW) char : character, – 1 byte long, holds an ASCII character (IGNORE FOR NOW) string : string – let’s talk about this later

Identifiers – An identifier must begin with an alphabetic character (a-z or A-Z) or an underscore(‘_’), which may be followed by alphabetic/numeric (0-9) characters and underscores. – Cannot use keywords (reserved words) using, int, double, etc… Quick questions!

What can we learn from the example cin >> age; – Get user’s input from keyboard – Assign the input to age – Be careful with the direction Opposite direction of the case of cout cout << "I am " << age << " years old." << endl; – we can use variable in cout – No quotes!!

Quick question age is integer type variable – What if input numbers with a decimal point? The range of int is from -2,147,483,647 to 2,147,483,647 – What if input numbers out of range?

Comment Compiler will ignore comments We can insert comments in a C++ program – Use double-slash: // Comment for single line – Use /* and */ pair Comments for multiple consecutive lines