Syntax and Semantics, and the Program Development Process ROBERT REAVES.

Slides:



Advertisements
Similar presentations
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
Advertisements

1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Chapter 2: Basic Elements of C++
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Chapter 2: Basic Elements of C++
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Basic Elements of C++
Chapter 2: Introduction to C++.
How to Program in C++ CHAPTER 3: INPUT & OUTPUT INSTRUCTOR: MOHAMMAD MOJADDAM.
Chapter 2: Basic Elements of C++
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Basic Elements of C++ Chapter 2.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
CHAPTER 7 arrays I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 2: Basic Elements of C++
Operating System Using setw and setprecision functions Using setiosflags function Using cin function Programming 1 DCT
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
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.
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
Chapter 2: Basic Elements of C++
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Chapter 2: Basic Elements of C++. Introduction Computer program – Sequence of statements whose objective is to accomplish a task Programming – Process.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++. Objectives In this chapter, you will: – Become familiar with the basic components of a C++ program, including functions,
CHAPTER 3 COMPLETING THE PROBLEM- SOLVING PROCESS AND GETTING STARTED WITH C++ An Introduction to Programming with C++ Fifth Edition.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Chapter 3: Input/Output. Objectives In this chapter, you will: – Learn what a stream is and examine input and output streams – Explore how to read data.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output Samples.
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
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Computer Programming BCT 1113
What Actions Do We Have Part 1
Basic Elements of C++.
Introduction to C++.
Chapter 2: Basic Elements of C++
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Chapter 3: Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 3 Input output.
Chapter 2: Introduction to C++.
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
Presentation transcript:

Syntax and Semantics, and the Program Development Process ROBERT REAVES

More About Output  Control vertical spacing by using the endl manipulator in an output statement.  What will the following produce?  cout << “Hi There, “ << endl;  cout << endl;  cout << “Lois Lane.” << endl;

 It is possible to do in one line.  cout << “Hi there, “ << endl << endl << “Lois Lane.” << endl;  Another:  cout << “Hi there, “ << endl << endl << “Lois Lane.” << endl;  This is to show we can spread a single C++ statement onto more than one line of the program.  semicolon

Inserting Blanks Within a Line  To control horizontal spacing of output, one technique is to send extra black characters to the output stream.  cout << “* * * * * *” << endl;  Produces:  * * * * * *  These are enclosed in double quotes so they print literally as they are written in the program.  What about:  cout << ‘*’ << ‘*’;

Special Characters  \” allows for quotes within a string sent to the output stream.  \n is a newline character, can use instead of endl.  \\ allows for the use of a \ within a string sent to the output stream.  What does produce?  cout << ‘”’ << “’”;  cout << “\”” << ‘\’’;

Enter Program Compile Program Compile- time Errors? Run Program Success! Logic errors? Go back to algorithm and fix design. No Yes Figure out errors.

Summary  Syntax of the C++ language is defined by metalanguage.  Identifiers are used in C++ to name things, some are called reserved words.  Have predefined meanings in the language.  Identifiers are restricted to those not reserved by the C++ language.  Identifiers are associated with memory locations by declarations.

Summary  Declarations may give a name to a location whose value doesn’t change, constant, and whose do change, variable.  Every constant and variable has a data type.  Common ones:  int  float  char  string, from the standard library

Summary  Program output is accomplished by means of the output stream variable cout, along with the insertion operator (<<).  Sends to the standard output device.  endl manipulator tells the computer to terminate the current output line and go on to the next.  Output should be clear, understandable, and neatly arranged.

Summary  A C++ program is a collection of one or more function definitions.  One of them must be main.  Execution always begins with the main function.  Functions all cooperate to produce the desired results.