Programming. Computer. Program. Programming Language. Execute sequence of simple (primitive) instructions What instructions should be provided?

Similar documents
Understanding main() function Input/Output Streams

4. Structure of a C++ program

Your First C++ Program. September 1, 2010

LECTURE 02 INTRODUCTION TO C++

Programming with C++ as a Second Language

Probably the best way to start learning a programming language is with a program. So here is our first program:

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Superior University. Department of Electrical Engineering CS-115. Computing Fundamentals. Experiment No.1

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Lab # 02. Basic Elements of C++ _ Part1

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Your first C++ program

Chapter 1 Introduction to Computers and Programming

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Computer Programming : C++

CHAPTER 3 BASIC INSTRUCTION OF C++

CSc Introduction to Computing

Lecture 2 Tao Wang 1

Programming I Laboratory - lesson 01

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

2 nd Week Lecture Notes

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Objectives. In this chapter, you will:

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++

This watermark does not appear in the registered version - Slide 1

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

C++ Programming: From Problem Analysis to Program Design, Third Edition

Chapter 1 INTRODUCTION

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Introduction to C++ IT 1033: Fundamentals of Programming

PIC 10A Objects/Classes

Computer Science II Lecture 1 Introduction and Background

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

CSI33 Data Structures

Chapter 1 Introduction to Computers and C++ Programming

AN OVERVIEW OF C. CSE 130: Introduction to Programming in C Stony Brook University

CS Exam 2 Study Suggestions

CSCI 1061U Programming Workshop 2. C++ Basics

Getting started with C++ (Part 2)

Some Computer Preliminaries

C++ Programming Basics

A A B U n i v e r s i t y

UEE1302 (1102) F10: Introduction to Computers and Programming

NAMESPACES IN C++ You can refer the Programming with ANSI C++ by Bhushan Trivedi for Understanding Namespaces Better(Chapter 14)

C Syntax Out: 15 September, 1995

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

Starting Out with C++: Early Objects, 9 th ed. (Gaddis, Walters & Muganda) Chapter 2 Introduction to C++ Chapter 2 Test 1 Key

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

BITG 1233: Introduction to C++

Introduction to C++ CS 1: Problem Solving & Program Design Using C++

Engineering Problem Solving with C++, Etter/Ingber

8. Control statements

Scientific Computing

C++ For Science and Engineering Lecture 15

CIS 130 Exam #2 Review Suggestions

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

Object Oriented Design

How to approach a computational problem

Fundamentals of Programming. Lecture 3: Introduction to C Programming

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Computer Programming

Chapter 2 Basic Elements of C++

1. a) What #include statement do you put at the top of a program that does uses cin, cout or endl?

Typescript on LLVM Language Reference Manual

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

The Parts of a C++ Program

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Separate Compilation of Multi-File Programs

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

BTE2313. Chapter 2: Introduction to C++ Programming

Chapter 1: Why Program? Computers and Programming. Why Program?

Extending Classes (contd.) (Chapter 15) Questions:

Chapter 1 - What s in a program?

EC 413 Computer Organization

Programming with C++ Language

Program Organization and Comments

Chapter 2. Outline. Simple C++ Programs

C and C++ I. Spring 2014 Carola Wenk

Chapter 2 C++ Fundamentals

Variables. Data Types.

Implementing an ADT with a Class

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

A SHORT COURSE ON C++

Programming II Lecture 2 Structures and Classes

Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

Creating a C++ Program

Transcription:

C++ Basics

Programming Computer Execute sequence of simple (primitive) instructions What instructions should be provided? Is there a minimum set? (See Turing Machine) Generic Reduce future limitations Program Describe process in the form of a sequence of instructions Think recipe Programming Language Express sequences of instructions Translate to computer instructions

"Hello, World!" #include <iostream> using namespace std; // pre processor directive int main() // start of program { cout << "Hello, World!\n"; // standard output stream return 0; // return value to operating system }

Structure of a C++ Program Computers are good at following instructions, but not at reading your mind. - Donald Knuth https://isocpp.org/std/the-standard Grammar Rules that define the language Describes what is valid and what is not E.g., return: is not valid Ambiguity Statement Smallest standalone unit that expresses an action Many statements end in a semicolon E.g., return 0;

Structure of a C++ Program Block (compound statement) Treated as a single statement Begin with { and end with }(curly braces) No semicolon needed after ending curly brace Can be used where a simple statement is permitted

Structure of a C++ Program Function Section of a program performing a specific task Every function body is defined inside a block Body Statements executed in sequence For a C++ executable, exactly one function named main()

Structure of a C++ Program Library Typically pre-compiled code available to the programmer to perform common tasks Two parts Interface header file, which contains names and declarations of items available for use Implementation pre-compiled definitions, or implementation code. In a separate file, location known to compiler Use the #include directive to use a library in your program (satisfies declare-before-use rule)

Namespaces File1.cpp File2.cpp void hello() { cout << hello\n ; } void hello() { cout << Hello\n ; }

Comments Annotate code Add information useful to humans but not to compiler Comments are ignored by the compiler Examples: Author Citation origin of code Explain code Block style (like C) /* This is a comment. It can span multiple lines */ Line comments -- use the double-slash // int x; x = 3; // This is a comment // This is a comment

More C++ Primitives

Memory 2 Hello, World! 1 3

Variables Stores data Type of data (e.g., string, number) Name Declare Before Use Variables must be declared before they can be used in other statements Examples: int page_number; string title;

Variables Declare and Define int x; Assign value x=5; Arithmetic operations x=x+5;

Identifiers `When I use a word,' Humpty Dumpty said, in rather a scornful tone, `it means just what I choose it to mean -- neither more nor less.' Lewis Carroll, Through the Looking Glass Need a way to refer to variables, functions, etc. Choose names that are descriptive Can use multiple words E.g., FirstName, last_name Function that performs an action use predicate-like E.g., ComputeGrade(...), display_text(...) Be consistent

Programming Strategies How do I go about writing a program? Top-down programming Start with description and divide it into sufficiently small units corresponding to available components Bottom-up programming Start with small components and build from them

In-Class Example

Building and Running a C++ Program Source Code (.cpp,.h) compiler Object code (.o) Executable Program linker Libraries

Building and Running a C++ Program Pre-processing The #include directive is an example of a pre-processor directive (anything starting with #). #include <iostream> tells the preprocessor to copy the standard I/O stream library header file into the program Compiling Syntax checking, translation of source code into object code (i.e. machine language). Not yet an executable program Linking Puts together any object code files that make up a program, as well as attaching precompiled library implementation code (like the standard I/O library implementation, in this example) End result is a final target -- like an executable program Run it!