COMS 261 Computer Science I

Slides:



Advertisements
Similar presentations
Chapter 2: Basic Elements of C++
Advertisements

Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
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.
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 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Intro. to Game Programming Want to program a game?
Hello World 2 What does all that mean?.
Instructor: Tina Tian. About me Office: RLC 203A Office Hours: Wednesday 1:30 - 4:30 PM or .
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.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
COMPUTER PROGRAMMING. A Typical C++ Environment Phases of C++ Programs: 1- Edit 2- Preprocess 3- Compile 4- Link 5- Load 6- Execute Loader Primary Memory.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
N from what language did C++ originate? n what’s input, output device? n what’s main memory, memory location, memory address? n what’s a program, data?
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
Basic Program Construction
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
1 A simple C++ program // ======================================================= // File:helloworld.cpp // Author:Vana Doufexi // Date:1/4/2006 // Description:Displays.
Chapter 2 part #1 C++ Program Structure
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 05, 2005 Lecture Number: 4.
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Dayu Zhang 9/10/2014 Lab03. Outline Brief Review of the 4 Steps in Hello.cpp Example Understand endl and \n Understand Comment Programming Exercise -
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 17/4/1435 h Monday Lecture 3 The Parts of a C++ Program.
Lecture 4 Computer Programming // sample C++ program #include using namespace std; int main() { cout
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 23, 2005 Lecture Number: 11.
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
C++ Programming: Presentation 1
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Topic Pre-processor cout To output a message.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
ANNOUNCEMENT The missed lecture will be made up this Monday evening in the Tech PC classroom (MG51). A tentative time interval is 6:30-8:00. The exact.
Chapter 2: Introduction to C++
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Beginning C++ Programming
CS149D Elements of Computer Science
Basic Elements of C++ Chapter 2.
Hello World 2 What does all that mean?.
Chapter 2 – Getting Started
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
CS150 Introduction to Computer Science 1
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Programs written in C and C++ can run on many different computers
Lecture 2 Fall 2011 September 13-15, 2011 Ghufran Ahmed
Capitolo 1 – Introduction C++ Programming
Computer Terms Review from what language did C++ originate?
COMS 261 Computer Science I
Introduction to Programming - 1
The Fundamentals of C++
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

COMS 261 Computer Science I Title: C++ Fundamentals Date: September 7, 2005 Lecture Number: 5

Announcements Homework Assignment Continue reading Chapter 2 Should have read 1.1 – 1.2, 2.1 – 2.5 before lab on Thursday Read/skim the lab for Thursday Bring lab handout to lab (class) on Thursday

Review Assembly Language High-Level Languages Think – Edit – Compile – Execute - Test Cycle Program Organization

Outline Code Warrior First C++ Program Area.cpp Hello, World Implemented in Code Warrior Project Area.cpp

A First Program - Hello.cpp // Author(s): Haul Pemler // Date: 10/07/2005 #include <iostream> #include <string> using namespace std; int main() { cout << "Hello world!" << endl; return 0; } Preprocessor directives Comments Provides simple access Function named main() indicates start of program Insertion statement String Literal Ends executions of main() which ends program Function Definition

A First Program - Hello.cpp Comments Not executed, so use them liberally to document your code Program and programmer name, date, what the program should do, special assumptions, input required, output produced, … // Program: Hello // Author(s): Haul Pemler // Date: 10/07/2005

A First Program - Hello.cpp #include <iostream> #include <string> Preprocessor Directives Program executed before the compiler Program #include means that the contents of the file named in the angle brackets should be input Usually contains common definitions There are other types of preprocessor directives

A First Program - Hello.cpp Includes all the symbols and objects in a package The package name is std Package contains many common objects used by most programs using namespace std;

A First Program - Hello.cpp Defines a special function called main It is the first function called when the program is executed Therefore: All C/C++ programs must have a function call main int main() { cout << "Hello world!" << endl; return 0; }

A First Program - Hello.cpp Functions can return a value when they are finished The int before main () { means the function called main returns an integer Where does the main function return the integer to? Part of the ANSI Standard int main() { cout << "Hello world!" << endl; return 0; }

A First Program - Hello.cpp << the insertion symbol (operator) Insert the string literal “Hello, World” into an object called cout Defined in the namespace called std Called the standard output, stdout cout knows to print the string (and other things) to the console int main() { cout << "Hello world!" << endl; return 0; }

A First Program - Hello.cpp int main() { cout << "Hello world!" << endl; return 0; } endl Manipulator defined in iostream << endl Insert a carriage return into the cout object Flush the output buffer Print all items inserted into the cout object ; statement terminator Identifies the end of the statement

A First Program - Hello.cpp Immediately stops function execution Communicates a value to the caller Returning a zero from the main function means the function terminated normally int main() { cout << "Hello world!" << endl; return 0; }

Hello Output