Exposure C++ Chapter IV Introduction to C++ Programs.

Slides:



Advertisements
Similar presentations
Introduction to C++ Programming. A Simple Program: Print a Line of Text // My First C++ Program #include int main( ) { cout
Advertisements

Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
 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.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
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.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
Chapter 2: Introduction to C++.
Basic Elements of C++ Chapter 2.
CSC103: Introduction to Computer and Programming
Using C Programming Language.  The programs that run on a computer are referred to as software.  You’ll learn key programming methodology that are enhancing.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
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)
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 2 - Welcome Application: Introduction to C++
Hello World 2 What does all that mean?.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Exposure C++ Chapter VII Program Input and Output.
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.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Creating your first C++ program
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Week 1 Algorithmization and Programming Languages.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Course Title: Introduction to C++ Course Instructor: ADEEL ANJUM Chapter No: 01 1 BY ADEEL ANJUM (MCS, CCNA,WEB DEVELOPER)
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.
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++
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?
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Basic Program Construction
C programming language was developed in the seventies by a group of at the Bell Telephone lab. The C language was the outline of two earlier languages.
Chapter 2 part #1 C++ Program Structure
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Chapter 3 Introduction To Java. OBJECTIVES Packages & Libraries Statements Comments Bytecode, compiler, interpreter Outputting print() & println() Formatting.
1 8/31/05CS150 Introduction to Computer Science 1 Hello World!
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.
Introduction to C++.  Computers: CPU, Memory & Input / Output (IO)  Program: Sequence of instructions for the computer.  Operating system: Program.
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Course Title Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
COMPUTER PROGRAMMING. Topic: STRUCTURE OF C PROGRAMMING.
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
Chapter 3 Introducing Java. Objectives and Goals 1. Define terminology associated with object- oriented programming. 2. Explain why Java is a widely used.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
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.
Programming what is C++
Chapter Topics The Basics of a C++ Program Data Types
Computer Terms Review from what language did C++ originate?
Chapter 1.2 Introduction to C++ Programming
CSC201: Computer Programming
Completing the Problem-Solving Process
Chapter 2, Part I Introduction to C Programming
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Hello World 2 What does all that mean?.
Chapter 2 – Getting Started
Chapter 2: Introduction to C++.
A First Program.
Computer Terms Review from what language did C++ originate?
COMS 261 Computer Science I
Introduction to Programming - 1
Chapter 2 part #1 C++ Program Structure
Presentation transcript:

Exposure C++ Chapter IV Introduction to C++ Programs

Some Small Program Examples Four small program examples follow. Every program is numbered starting with 04 for Chapter 04 followed by 01, 02, 03 and 04 to indicate the program sequence within the chapter. Look for features that are shared by all three examples.

//PROG0401.CPP // This demonstrates the absolute minimum program // that does nothing. void main() { } PROG0401.CPP OUTPUT This program has no output

// PROG0402.CPP // This program demonstrates program output. // The library is necessary to use the cout // keyword. #include void main() { cout << "Bewilderment + Exposure = Obvious" << endl; } PROG0402.CPP OUTPUT Bewilderment + Exposure = Obvious

// PROG0403.CPP // This program adds clrscr to clear the screen // and getch to stop program output. #include // necessary for cout #include // necessary for clrscr // and getch void main() { clrscr(); cout << "Bewilderment + Exposure = Obvious" << endl; getch(); } PROG0403.CPP OUTPUT Bewilderment + Exposure = Obvious is not used by many modern compilers and will not be used in later slide chapters.

// PROG0404.CPP /********************************************************************* * This program demonstrates a variety of ways that you can use * * comments in a C++ program. It is possible to make a large * * multi-line comment, like shown in this box. It is also possible * * to make single-line comments with // * *********************************************************************/ #include // contains input/output operations #include // contains console functions like clrscr void main() { clrscr(); // clears the screen cout << "Bewilderment + "; cout << "Exposure = Obvious" << endl; getch(); // stops program execution } PROG0404.CPP OUTPUT Bewilderment + Exposure = Obvious

C++ Program Statements C++ program statements are written, in sequence, between the opening and closing braces, like: void main() { program statement 1; program statement 2; program statement 3; } Every program statement ends with a semi-colon ( ; )

Using Library Functions The #include preprocessor Libraries of specialized functions are available with the #include preprocesor, like: #include C++ has a large selection of function libraries for many purposes. Each new function library will be explained as it is first introduced.

Making Single-Line Comments Syntax for slash-style comment: cout << endl; // starts a new line Syntax for slash-star style comment: cout << endl; /* starts a new line */ /* starts a new line */ cout << endl; cout << /* starts a new line */ endl;

Making Multi-Line Comments Syntax for slash-style comment: // INTEREST.CPP // This program will compute an amortization // table based on loan amount, yearly interest, // and monthly payment size. Syntax for slash-star style comment: /* INTEREST.CPP This program will compute an amortization table based on loan amount, yearly interest, and monthly payment size. */

PROG0405.CPP OUTPUT Measure today's understanding by yesterday's confusion // PROG0405.CPP // This program uses a single statement to display a single line. #include // contains input/output functions #include // contains console functions like clrscr void main() { clrscr(); cout << "Measure today's understanding by yesterday's confusion"; getch(); } Program Output to the Monitor

cout << output cout << "Program Output Information"; cout does not automatically perform carriage return/line feeds. Use double quotes " " at the start, and end of each string of characters that needs to be displayed on the monitor. cout Syntax

PROG0406.CPP OUTPUT Measure today's understanding by yesterday's confusion // PROG0406.CPP // This program displays a single output line with three // separate statements. This demonstrates that cout // does not automatically generate a carriage return. #include // contains input/output functions #include // contains console functions like clrscr void main() { clrscr(); cout << "Measure "; cout << "today's understanding "; cout << "by yesterday's confusion"; getch(); }

Sending Program Output to a New Line Sending program output to a new line is done with endl. You can think that it means end of line, and anything following will go to the next line. You cannot combine an output string with endl, like: cout << "Thomas Smith" endl; The output string and endl must be separated by the "double chevrons" output-stream-operator << cout << "Thomas Smith" << endl;

PROG0407.CPP OUTPUT Measure today's understanding by yesterday's confusion // PROG0407.CPP // This program introduces endl to generate a carriage return. #include // contains input/output functions #include // contains console functions like clrscr void main() { clrscr(); cout << "Measure " << endl; cout << "today's understanding " << endl; cout << "by yesterday's confusion" << endl; getch(); }

PROG0408.CPP OUTPUT Measure today's understanding by yesterday's confusion // PROG0408.CPP // This program demonstrates how to insert a blank line between // program output statements. #include // contains input/output functions #include // contains console functions like clrscr void main() { clrscr(); cout << "Measure " << endl << endl; cout << "today's understanding " << endl << endl; cout << "by yesterday's confusion" << endl; getch(); }

// PROG0409.CPP // This program is used to explain the difference between the // program listing and the program execution. // Thomas Phillips // Mr. Randy Robertson // Period 3 // September 11, 1997 // Lab Assignment #4 #include // contains input/output functions #include // contains console functions like clrscr void main() { clrscr(); cout << "Thomas Phillips" << endl; cout << "5003 Orleans Court" << endl; cout << "Kensington, Maryland 20795" << endl; getch(); } This is the Program Listing or Program Source Code.

This is the Program Execution or Program Output Thomas Phillips 5003 Orleans Court Kensington, Maryland 20795

Program Listing The program listing is the source of a program. It contains the program statements and comments that a programmer uses to write a program. The listing is the source code that the compiler checks, and translates into an executable machine code file. The file name that prints the listing normally ends in CPP.

Program Execution Output The program execution output is the output generated by the machine code file of a program. The program output will go to the computer monitor, unless specified to go somewhere else. The execution of a program will only generate output if there are statements that produce output like: cout << "This line goes to output";

// PROG0410.CPP // This demonstrates that a program does not necessarily // have output. // Nothing is shown on the monitor without a statement // like cout << "HI"; void main() { // This comment is not an output statement }