Review of C++ Language Basics

Slides:



Advertisements
Similar presentations
Introduction to Programming in C++ John Galletly.
Advertisements

1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
Chapter 2: Basic Elements of C++
C Programming Language 4 Developed in 1972 by Dennis Ritchie at AT&T Bell Laboratories 4 Used to rewrite the UNIX operating system 4 Widely used on UNIX.
Chapter 2: Basic Elements of C++
Chapter 2: Basic Elements of C++
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
COMPUTER SCIENCE I C++ INTRODUCTION
Chapter 2 Overview of C++ Lecture Notes Prepared By: Blaise W. Liffick, PhD Department of Computer Science Millersville University Millersville, PA
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using.
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.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Object Oriented Programming with C++ Diploma in Computer System Design.
Beginning C++ Through Game Programming, Second Edition
C++ Programming: Basic Elements of C++.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Control Structures (B) Topics to cover here: Sequencing in C++ language.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 2: Basic Elements of C++
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
Recap……Last Time [Variables, Data Types and Constants]
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 2: Basic Elements of C++
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 2: Basic Elements of C++
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
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 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
Bill Tucker Austin Community College COSC 1315
Today Variable declaration Mathematical Operators Input and Output Lab
Chapter 1.2 Introduction to C++ Programming
TK1913 C++ Programming Basic Elements of C++.
Chapter 2: Basic Elements of C++
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
Computer Programming BCT 1113
Chapter 1.2 Introduction to C++ Programming
Chapter 1: Introduction to computers and C++ Programming
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Completing the Problem-Solving Process
Programming Fundamental
Basic Elements of C++.
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Lecture2.
Chapter 2: Basic Elements of C++
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
Programming Funamental slides
Programming Funamental slides
Introduction to C++ Introduced by Bjarne Stroustrup of AT&T’s Bell Laboratories in mid-1980’s Based on C C++ extended C to support object-oriented programming.
Introduction to C++ Programming
Review of Java Language Basics
CS150 Introduction to Computer Science 1
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
C++ Programming Basics
Chapter 2: Overview of C++
Basic Elements of Computer Program
Presentation transcript:

Review of C++ Language Basics B.Ramamurthy CS114B 4/10/2019 B.Ramamurthy

The C++ Language C++ is a complex language designed by Bjarne Stroustup of At&T Bell Labs, Murray Hill, NJ. It evolved from the very popular C language (this was also designed at AT&T) out the need for object-orientation. (Unix is implemented in C) 4/10/2019 B.Ramamurthy

State of C++ In its author’s words, C++ is a better C supports data abstraction supports object-oriented programming Current version of C++ is very robust, ANSI standardized, and widely used. Many large industrial programs are written in C++. 4/10/2019 B.Ramamurthy

“Out of Their Minds” “We did not know what we wanted and how to do it. It just sort of grew. The first struggle was over what the language would look like. Then how to parse the expressions….” John Backus (Inventor of FORTRAN, BNF (Backus-Naur Form) and FP, a functional language) 4/10/2019 B.Ramamurthy

Problem solving Problem solving involves understanding a problem, analyzing the problem and providing a solution to the problem. The solution specifies the overall design (structure chart, class diagrams, flow chart), algorithms and data organization. Phases of software development: problem statement, design solution, code the solution, document, debug, test, and maintain. 4/10/2019 B.Ramamurthy

Elements of C++ Every data (entity) used in an application should have a name (identifier) and type. A data type defines the set of values an object of this type can take and the operations that are allowed on this set. Example : Consider a whole number: Set of values => -32768 to +32767 Operations ==> + , - , * , / 4/10/2019 B.Ramamurthy

Some C++ -defined data types Integer : int Real number : float character : char Boolean /logic : bool (available only in ANSI C++) No type possible? Use void 4/10/2019 B.Ramamurthy

Identifiers To identify the various data objects, programs, functions, and other items referenced by a program. Example : Grade1 , R_2D2 , Salary Rules for choosing an identifier: An identifier should always begin with a letter. This letter can be followed by any combination of {letter, digit, underscore} C++ reserved words cannot used an user-defined identifier. Reserved words are predefined in the language (C++) and cannot be used for anything other than the purpose for which they are reserved. 4/10/2019 B.Ramamurthy

Constants Constant : Refers to an object whose value remains constant throughout the execution of a program. Constant definition : Syntax : const type Constant_identifier = value; Example : const float pi = 3.14159; 4/10/2019 B.Ramamurthy

Operators - Arithmetic and Relational Arithmetic: (integer) + addition - subtraction * multiplication / division (quotient only) % modulus (remainder of integer division) See Fig. 1.15 Relational < less than <= less than or equal to > greater than >= greater than or equal == equal to != not equal to 4/10/2019 B.Ramamurthy

Assignment Statement Syntax: Variable = expression; Semantics: Evaluate the expression on the right hand side (RHS) of the = and assign the result to the variable on the left hand side (LHS). The expression on the RHS should be consistent with the type of the variable on the LHS. Expression represents a formula. It could be a constant, variable or combination of variables, constants and operators. EX: Total = Score1 + Score2; 4/10/2019 B.Ramamurthy

C++ Libraries C++ offers a collection of libraries of commonly used functions. A library is presented to the user/application program in the form of a header file. Example: math.h, iostream.h, thread.h To use the functions offered by a library, the header file is included using #include and functions in the library can be invoked like any other function. 4/10/2019 B.Ramamurthy

Program Input Syntax : cin input_list; input_list consists of variables separated by extraction-operator >> The order of data must correspond to the order of the variables in the input-list. Semantics : Values for the variables specified are input from input device (stream). 4/10/2019 B.Ramamurthy

Program Input Example: int age; char first_initial; cin >> age >> first_initial; Age first_initial 8 7 K ……………….. Input Stream (buffer) 4/10/2019 B.Ramamurthy

Program output Syntax : cout output_list; output_list is a list of any combination of variables, constants, or strings each of which must be preceded by the insertion operator << Semantics: Each value is displayed in the order in which it is specified in the output_list; Example: cout << “My profit and initials are” << Net_Profit << Initial; 4/10/2019 B.Ramamurthy

Program Structure A C++ program is a collection of one or more functions. Every program has one function called main. To start the program execution, the Operating System transfers control to main. A return statement transfers control from a function to the caller of the function. 4/10/2019 B.Ramamurthy

Program Structure (contd.) // Name of file // Author and other program-related information #include directives int main () { constant declarations variable declarations executable statements } 4/10/2019 B.Ramamurthy

Program Structure : Example #include <iostream.h> // inclusion facility int main() { const float PI = 3.14; float Radius; cout << “Enter radius of the sphere \n”; cin >> Radius; float Volume = 4 * PI * Radius * Radius * Radius /3; cout << “The volume of the sphere of radius” << radius << “is” << Volume << endl; return 0; } 4/10/2019 B.Ramamurthy

Generating Executable Code Type in program Editor emacs /vi /pico C++ Source Code sample.cc Compiler g++ -c sample.cc Object Code sample.o External References Libraries Linker g++ -o sample sample.o Executable code sample 4/10/2019

Summary We studied: Elements of C++ : identifiers, variables and constants, assignments, input/output statements Simple application program structure A complete application example 4/10/2019 B.Ramamurthy