Introduction to C++ September 12, 2007. Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Introduction to C Programming
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Chapter 2: Introduction to C++.
Introduction to C Programming
Basic Elements of C++ Chapter 2.
COMPUTER SCIENCE I C++ INTRODUCTION
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE 1 st semester H 1 King Saud University College of Applied studies and Community Service Csc 1101 By:
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Week 1-2 In this class, you will learn about: Program Structure, Actions and Data Types Data Type: Variables Output and Input action: function cout > Assignment.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
STRUCTURED PROGRAMMING Complete C++ Program. Content 2  Main Function  Preprocessor directives  User comments  Escape characters  cout statement.
Bill Tucker Austin Community College COSC 1315
Chapter 1.2 Introduction to C++ Programming
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
What Actions Do We Have Part 1
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 2 - Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Chapter 2 - Introduction to C Programming
Basic Elements of C++ Chapter 2.
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
2.1 Parts of a C++ Program.
Introduction to C++ Programming
1.13 The Key Software Trend: Object Technology
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Chapter 2: Introduction to C++.
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
Introduction to C Programming
Introduction to C Programming
Presentation transcript:

Introduction to C++ September 12, 2007

Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules for naming variables Classwork/Homework Tomorrow we will work with Arithmetic Expression. Quiz on Friday!

Review! Take out your notebook Comments! Single one line comment begins with //. Multi-line comments begin with /* and end with a */ Comments are used for documentation of the program and improve program readability. Help other people (programmers) read and understand your program. Comments are ignored by the compiler and do not cause any execution.

Example of an comment! //A first program in C++ // John Smith -or- /* John Smith Computer Science Class This program will perform the ……. */

#include ? Is called a preprocessor directive. It tells the processor to include in the program the contents of the input/output stream header file iostream.h. This file must be included for any program that outputs data to the screen or inputs data from the keyboard. Forgetting to include this file will cause and error!

main( ) ? Is a part of every C++ program. The parentheses after main indicate that main is a program building block called a function.

Left/Right braces { and } ? The left brace { must begin the body of the program. The right brace } must end the body of the program.

cout Statements ? Instructs the computer to print on the screen the string of characters contained between the quotation marks. Example: cout<<“Welcome to C++”; Every statement must end with a semi- colon.

Backslash \ ? Is called an escape character. It indicated that a special character it to be output. Escape SequenceDescription \nNewline \tHorizontal tab \aAlert. Sound the system bell \\Used to print a backslash character. \* Used to print a double quote character.

Return 0; ? Indicates that program ended successfully. Exits the function main( )

Check you work! Write a program that prints a box, circle, and a diamond as follows: **** ** * * * * **** ** *

Another Simple Program: Adding Two Integers //This program will add two numbers #include main( ) { int integer1, integer2, sum;//declaration cout<<“Enter first integer\n”;//prompt cin>>integer1; //read an integer

cout<<“Enter second integer\n”; // read an integer cin>>integer2; sum = integer1 + integer2; //calculations cout<<“Sum is “<< sum << endl; //print the sum to the screen return 0; }

Run your program? What happens?

Declaration???? The line int integer1, integer2, sum; is a declaration! The words integer1 and integer2 and sum are the names of variables. A variable is a location in the computer’s memory where a value can be stored for used by a program. int means that these variables will hold integer values (whole numbers). All variables must be declared with a name and a data type before they can be used in a program.

Rules for naming your Variables Is a series of characters consisting of letters, digits, and underscore(_). Cannot begin with a digit. Upper and lower case letters are different. Ex: a1 and A1 is different. Choose meaningful variable names helps a program to be self-documenting. Declaration of a variable must be placed first before you use it. Example: int number;

Classwork/Homework Write a statement(or comment) to accomplish each of the following: 1. State that a program with calculate the product of three integers. 2. Declare the variables x,y,z, and result to be of type int. 3. Prompt the user to enter three integers. 4. Read three integers from the keyboard and store them in the variables x, y, z. 5. Compute the product of the three integers contained in variables x, y,and z, and assign the result to the variable result. 6. Print “The product is” followed by the value of the variable result. 7. Return a value from main indicating that the program terminated successfully.

Classwork/Homework Continued: Using the statements you wrote for the above slide, write a complete program that calculates and prints the product of three integers. Due Date will be Friday! Quiz on Friday! Tomorrow we will start working with Arithmetic Expressions!