Chapter 1 Dr. Ali Al-Hamdi 1
Chapter 1
Introduction to C++
Chapter 1 Dr. Ali Al-Hamdi 2
Chapter Topics
 About C++
 Input/Output and Operators
 Introduction to Classes, Objects and Strings
Chapter 1 Dr. Ali Al-Hamdi 3
1.1 About C++
(chapter 1 in textbook)
Chapter 1 Dr. Ali Al-Hamdi 4
1.1.1 Data Hierarchy
(sections: 1.4 in the textbook )
 Bit
 Byte
 Field
 Record
 File
 Database
 Big data
Chapter 1 Dr. Ali Al-Hamdi 5
1.1.2 Programming Languages levels
(sections: 1.5 in the textbook )
 Programming Languages Types
 Machine language
 Assembly language
 High-level languages
 Translator types
 Assemblers
 Compilers
 Interpreters
Chapter 1 Dr. Ali Al-Hamdi 6
1.1.3 C and C++: Historical Facts
(section 1.6 in textbook )
 Developed from C, which was developed by Dennis
Ritchie at Bell Labs in 1972.
 C is available for most computers and is H/W
independent (portable language).
 C was standardized by ANSI/ISO. So, ANSI/ISO 9899:
1990 was published in 1990.
 C11 was developed to evolve C to keep pace with
increasingly powerful H/W and ever more demanding
user requirements. C11 also makes C more consistent
with C++.
Chapter 1 Dr. Ali Al-Hamdi 7
 C++, an extension of C, was developed by Bjarne
Stroustrup in 1979 at Bell Labs. Originally called “C with
class”, it was renamed C++ in the early 1980s.
 C++ provides a number of features that “spruce up” C,
most importantly it provides capabilities for OOP.
 C++ versions
 C++11: was published by ISO/IEC in 2011. It extends C++
Standard Library added several language features and
enhancements to improve performance and security.
1.1.3 C and C++: Historical Facts
(section 1.6 and 1.14 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 8
 C++ versions
 The current C++ standard, C++14, was published by ISO/IEC in
2014. It added several language features and C++ Standard
Library enhancements, and fixed bugs from C++11.
 The next version of the C++ standard, C++17, is currently under
development. For a list of proposed features, see:
https://en.wikipedia.org/wiki/C%2B%2B17
 Some C++ compilers
 Visual Studio 2015 Community Edition (Microsoft Windows)
 GNU C++ (Linux)
 Clang/LLVM in Xcode (Mac OS X)
1.1.3 C and C++: Historical Facts
(section 1.6 and 1.14 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 9
 Two approaches of programming (development
perspective)
 Creating from scratch,
 Reusing available classes and functions.
 Avalable reused classes and functions deals
with:
 Commonly used algorithms,
 Data structure,
1.1.3 C++ Standard Library
(section 1.6 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 10
 C++ Standard library has a rich of collection
of classes and functions.
 Software Engineering observations


1.1.3 C++ Standard Library
(section 1.6 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 11
 Performance
 Portability
 The advantage of creating your own functions and classes is that you’ll know exactly how
they work.
 The disadvantage is the time-consuming and complex effort that goes into designing,
developing and maintaining new functions and classes that are correct and operate efficiently.
1.1.3 C++ Standard Library
(section 1.6 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 12
1.1.4 Popular Programing Languages
(section 1.7 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 13
1.1.4 Popular Programing Languages
(section 1.7 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 14
1.1.4 Popular Programing Languages
(section 1.7 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 15
1.1.4 Popular Programing Languages
(section 1.7 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 16
 Earlier technology (S/W nature perspective)
 Motivation
 Goals
 Concept
 Advantages
 Objects examples: automobile, bank account
 Hiding mechanisms: examples
1.1.5 Introduction to Object Technology
(section 1.8 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 17
 Member functions and classes
 Example
 Instantiation, instance
 Example
 Reuse concept and advantages
 Example
 Messages and member class calls
 Example
1.1.5 Introduction to Object Technology
(section 1.8 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 18
 Attributes and data members
 Example
 Encapsulation
 Example
 Inheritance
 Examples
 Polymorphism
 Example
1.1.5 Introduction to Object Technology
(section 1.8 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 19
 Programming in SDLC
Program size and relation
with SDLC
 Small
 Large
1.1.5 Introduction to Object Technology
(section 1.8 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 20
 Object-Oriented Analysis and Design (OOAD)
 Analysis (what?)
 Design (How?)
 OOAD
 OOPL
 Unified Modeling Language (UML)
 Used in?
 Used for?
1.1.5 Introduction to Object Technology
(section 1.8 in textbook )
Chapter 1 Dr. Ali Al-Hamdi 21
 C++ system programming parts:
 A program development environment,
 The language, and
 The C++ Standard Library.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 22
 A C++ program typically go through six
phases:
 Edit,
 Preprocess,
 Compile,
 Link,
 Load, and
 Execute.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 23
 Phase 1: Editing a C++ program
 A source file is created with .cpp, .cxx, .cc, or .C
extension.
 C++ Editors examples
 2 editors on Linux: vi and emacs.
 Microsoft Windows: Microsoft visual C++.
 Simple text editors: notepad in Windows.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 24
 Phase 1: Editing a C++ program
 Integrated Development Environment (IDE)
 Function: supports the software-development process,
including editors for writing and editing programs and
debuggers for locating logic errors.
 Popular IDEs include Microsoft® Visual Studio 2012
Express Edition, Dev C++, NetBeans, Eclipse, Apple’s
Xcode and CodeLite.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 25
 Phase 2: Preprocessing a C++ programs
 The C++ preprocessor obeys commands called
preprocessing directives, which indicate that certain
manipulations are to be performed on the program
before compilation.
 These manipulations usually include other text files
to be compiled, and perform various text
replacements.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 26
 Phase 3: Compiling a C++ program
 The compiler translates the C++ program into
machine-language code—also referred to as object
code.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 27
 Phase 4: Linking a C++ program
 C++ programs typically contain references to
functions and data defined elsewhere, such as in the
standard libraries or in the private libraries of groups
of programmers working on a particular project.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 28
 Phase 4: Linking a C++ program
 The object code produced by the C++ compiler
typically contains “holes” due to these missing parts.
 A linker links the object code with the code for the
missing functions to produce an executable program
(with no missing pieces).
 If the program compiles and links correctly, an
executable image is produced.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 29
 Phase 5: Loading a C++ program
 Before a program can be executed, it must first be
placed in memory by the loader, which takes the
executable image and components from shared
libraries from disk and transfers it to memory.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 30
 Phase 6: Executing a C++ program
 Finally, the computer’s CPU, executes the program
one instruction or several instructions in parallel at a
time.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 31
 Problems that may occur during time
execution:
 Programs might not work successfully on the first
try of execution due to any type of errors that may
exist in any of 6 phases discussed so far.
 Type of errors?
 Test-Driving C++ Application: read section 1.10 for Lab. tutorials.
1.1.6 Typical C++ development
environment (section 1.9)
Chapter 1 Dr. Ali Al-Hamdi 32
1.2 Input/Output and Operators
(chapter 2 in textbook)
Chapter 1 Dr. Ali Al-Hamdi 33
 Example (1): Printing a line of text
 Remarks?
 Questions?
1.2.1 First program in C++
(section 2.2)
Chapter 1 Dr. Ali Al-Hamdi 34
 Programming tips
 Comments
 Including program u
updating
 Compiler error
 Syntax errors
 Good practices
1.2.1 First program in C++
Chapter 1 Dr. Ali Al-Hamdi 35
 The Stream Insertion Operator
 Espace Sequences
1.2.1 First program in C++
Chapter 1 Dr. Ali Al-Hamdi 36
1.2.2 Modifying first program
(Section 2.3)
 Example (2)
 Remarks?
 Questions?
 Example (3)
 Remarks?
 Questions?
Chapter 1 Dr. Ali Al-Hamdi 37
1.2.3 Another C++ programs
(Section 2.4)
 Example (4)

Chapter 1 Dr. Ali Al-Hamdi 38
 Programming Notes
and Tips
 Variables declaration
 Identifiers writing
 Placement of variables
declaration
 Placement of binary
operators
 Cascading stream
insertion operations
 Stream manipulator
1.2.3 Another C++ programs
Chapter 1 Dr. Ali Al-Hamdi 39
 C++ Operators
1.2.4 Arithmetic
(section 2.6)
Chapter 1 Dr. Ali Al-Hamdi 40
 Rules of operator precedence
1.2.4 Arithmetic
(section 2.6)
Chapter 1 Dr. Ali Al-Hamdi 41
1.2.5 Decision Making (sections 2.8)
(section 2.8)
Chapter 1 Dr. Ali Al-Hamdi 42
 Example (6)
 Remarks?
 Questions?
1.2.5 Decision Making (sections 2.8)
(section 2.8)
Chapter 1 Dr. Ali Al-Hamdi 43
 Programming notes and tips
 Using declarations
 Using directive namespace
 Statement indentation
 Logic error
 Statement splitting
1.2.5 Decision Making
(section 2.8)
Chapter 1 Dr. Ali Al-Hamdi 44
 Operator prececdence
1.2.6 Decision Making
(section 2.8)
Chapter 1 Dr. Ali Al-Hamdi 45
1.3 Introduction to Classes, Objects
Member Functions, and Strings
(chapter 3 in textbook)
Chapter 1 Dr. Ali Al-Hamdi 46
 Structure
 Definition
 Structure Syntax (Definition)
struct struct_name {
DataType member1_name;
DataType member2_name;
DataType member3_name;
…
};
1.3.1 Structure and class: syntax
C and C++ comparison
Chapter 1 Dr. Ali Al-Hamdi 47
 Structure
 Declaration
struct struct_name var_name;
 Assigning value
 Accessing
var_name.memeber_name = value;
1.3.1 Structure and class: syntax
C and C++ comparison
Chapter 1 Dr. Ali Al-Hamdi 48
#include <stdio.h>
/* Created a structure here. The name of the structure is StudentData.*/
struct StudentData{
char *stu_name;
int stu_id;
int stu_age;
};
int main()
{
/* student is the variable of structure StudentData*/
struct StudentData student;
/*Assigning the values of each struct member here*/
student.stu_name = "Sami";
student.stu_id = 1234;
student.stu_age = 22;
/* Displaying the values of struct members */
printf("Student Name is: %s", student.stu_name);
printf("nStudent Id is: %d", student.stu_id);
printf("nStudent Age is: %d", student.stu_age);
return 0;
 Structure
 Example
Output:
Student Name is: Sami
Student Id is: 1234
Student Age is: 22
1.3.1 Structure and class: example
C and C++ comparison
Chapter 1 Dr. Ali Al-Hamdi 49
 Class
 Definition
 Calss Syntax (Creation or Definition)
1.3.1 Structure and class: syntax
Chapter 1 Dr. Ali Al-Hamdi 50
 Class
 Declaration
 Assigning value
 Accessing
ClassName ObjectName;
ObjectName. MemberFunction;
ObjectName. DataMember;
ObjectName. DataMember=Value or string;
1.3.1 Structure and class
Chapter 1 Dr. Ali Al-Hamdi 51
1.3.2 Test-Driving an Account
Object
Chapter 1 Dr. Ali Al-Hamdi 52
1.3.3 Account Class with a Data Member
and Set and Get Member Functions
Chapter 1 Dr. Ali Al-Hamdi 53
1.3.3 Account Class with a Data Member
and Set and Get Member Functions
Chapter 1 Dr. Ali Al-Hamdi 54
1.3.3 Account Class with a Data Member
and Set and Get Member Functions
Chapter 1 Dr. Ali Al-Hamdi 55
1.3.4 Account Class: Initializing Object
with Constructor
Chapter 1 Dr. Ali Al-Hamdi 56
1.3.4 Account Class: Initializing Object
with Constructor
Chapter 1 Dr. Ali Al-Hamdi 57
1.3.4 Account Class: Initializing Object
with Constructor
Chapter 1 Dr. Ali Al-Hamdi 58
1.3.5 Software Engineering with Set and
Get Member Functions
Chapter 1 Dr. Ali Al-Hamdi 59
1.3.6 Account Class with a Balance; Data
Validation
Chapter 1 Dr. Ali Al-Hamdi 60
1.3.6 Account Class with a Balance; Data
Validation
Chapter 1 Dr. Ali Al-Hamdi 61
1.3.6 Account Class with a Balance; Data
Validation
Chapter 1 Dr. Ali Al-Hamdi 62
1.3.6 Account Class with a Balance; Data
Validation
Chapter 1 Dr. Ali Al-Hamdi 63
1.3.6 Account Class with a Balance; Data
Validation

C++ how to program 10 edition Harvey Deitel

  • 1.
    Chapter 1 Dr.Ali Al-Hamdi 1 Chapter 1 Introduction to C++
  • 2.
    Chapter 1 Dr.Ali Al-Hamdi 2 Chapter Topics  About C++  Input/Output and Operators  Introduction to Classes, Objects and Strings
  • 3.
    Chapter 1 Dr.Ali Al-Hamdi 3 1.1 About C++ (chapter 1 in textbook)
  • 4.
    Chapter 1 Dr.Ali Al-Hamdi 4 1.1.1 Data Hierarchy (sections: 1.4 in the textbook )  Bit  Byte  Field  Record  File  Database  Big data
  • 5.
    Chapter 1 Dr.Ali Al-Hamdi 5 1.1.2 Programming Languages levels (sections: 1.5 in the textbook )  Programming Languages Types  Machine language  Assembly language  High-level languages  Translator types  Assemblers  Compilers  Interpreters
  • 6.
    Chapter 1 Dr.Ali Al-Hamdi 6 1.1.3 C and C++: Historical Facts (section 1.6 in textbook )  Developed from C, which was developed by Dennis Ritchie at Bell Labs in 1972.  C is available for most computers and is H/W independent (portable language).  C was standardized by ANSI/ISO. So, ANSI/ISO 9899: 1990 was published in 1990.  C11 was developed to evolve C to keep pace with increasingly powerful H/W and ever more demanding user requirements. C11 also makes C more consistent with C++.
  • 7.
    Chapter 1 Dr.Ali Al-Hamdi 7  C++, an extension of C, was developed by Bjarne Stroustrup in 1979 at Bell Labs. Originally called “C with class”, it was renamed C++ in the early 1980s.  C++ provides a number of features that “spruce up” C, most importantly it provides capabilities for OOP.  C++ versions  C++11: was published by ISO/IEC in 2011. It extends C++ Standard Library added several language features and enhancements to improve performance and security. 1.1.3 C and C++: Historical Facts (section 1.6 and 1.14 in textbook )
  • 8.
    Chapter 1 Dr.Ali Al-Hamdi 8  C++ versions  The current C++ standard, C++14, was published by ISO/IEC in 2014. It added several language features and C++ Standard Library enhancements, and fixed bugs from C++11.  The next version of the C++ standard, C++17, is currently under development. For a list of proposed features, see: https://en.wikipedia.org/wiki/C%2B%2B17  Some C++ compilers  Visual Studio 2015 Community Edition (Microsoft Windows)  GNU C++ (Linux)  Clang/LLVM in Xcode (Mac OS X) 1.1.3 C and C++: Historical Facts (section 1.6 and 1.14 in textbook )
  • 9.
    Chapter 1 Dr.Ali Al-Hamdi 9  Two approaches of programming (development perspective)  Creating from scratch,  Reusing available classes and functions.  Avalable reused classes and functions deals with:  Commonly used algorithms,  Data structure, 1.1.3 C++ Standard Library (section 1.6 in textbook )
  • 10.
    Chapter 1 Dr.Ali Al-Hamdi 10  C++ Standard library has a rich of collection of classes and functions.  Software Engineering observations   1.1.3 C++ Standard Library (section 1.6 in textbook )
  • 11.
    Chapter 1 Dr.Ali Al-Hamdi 11  Performance  Portability  The advantage of creating your own functions and classes is that you’ll know exactly how they work.  The disadvantage is the time-consuming and complex effort that goes into designing, developing and maintaining new functions and classes that are correct and operate efficiently. 1.1.3 C++ Standard Library (section 1.6 in textbook )
  • 12.
    Chapter 1 Dr.Ali Al-Hamdi 12 1.1.4 Popular Programing Languages (section 1.7 in textbook )
  • 13.
    Chapter 1 Dr.Ali Al-Hamdi 13 1.1.4 Popular Programing Languages (section 1.7 in textbook )
  • 14.
    Chapter 1 Dr.Ali Al-Hamdi 14 1.1.4 Popular Programing Languages (section 1.7 in textbook )
  • 15.
    Chapter 1 Dr.Ali Al-Hamdi 15 1.1.4 Popular Programing Languages (section 1.7 in textbook )
  • 16.
    Chapter 1 Dr.Ali Al-Hamdi 16  Earlier technology (S/W nature perspective)  Motivation  Goals  Concept  Advantages  Objects examples: automobile, bank account  Hiding mechanisms: examples 1.1.5 Introduction to Object Technology (section 1.8 in textbook )
  • 17.
    Chapter 1 Dr.Ali Al-Hamdi 17  Member functions and classes  Example  Instantiation, instance  Example  Reuse concept and advantages  Example  Messages and member class calls  Example 1.1.5 Introduction to Object Technology (section 1.8 in textbook )
  • 18.
    Chapter 1 Dr.Ali Al-Hamdi 18  Attributes and data members  Example  Encapsulation  Example  Inheritance  Examples  Polymorphism  Example 1.1.5 Introduction to Object Technology (section 1.8 in textbook )
  • 19.
    Chapter 1 Dr.Ali Al-Hamdi 19  Programming in SDLC Program size and relation with SDLC  Small  Large 1.1.5 Introduction to Object Technology (section 1.8 in textbook )
  • 20.
    Chapter 1 Dr.Ali Al-Hamdi 20  Object-Oriented Analysis and Design (OOAD)  Analysis (what?)  Design (How?)  OOAD  OOPL  Unified Modeling Language (UML)  Used in?  Used for? 1.1.5 Introduction to Object Technology (section 1.8 in textbook )
  • 21.
    Chapter 1 Dr.Ali Al-Hamdi 21  C++ system programming parts:  A program development environment,  The language, and  The C++ Standard Library. 1.1.6 Typical C++ development environment (section 1.9)
  • 22.
    Chapter 1 Dr.Ali Al-Hamdi 22  A C++ program typically go through six phases:  Edit,  Preprocess,  Compile,  Link,  Load, and  Execute. 1.1.6 Typical C++ development environment (section 1.9)
  • 23.
    Chapter 1 Dr.Ali Al-Hamdi 23  Phase 1: Editing a C++ program  A source file is created with .cpp, .cxx, .cc, or .C extension.  C++ Editors examples  2 editors on Linux: vi and emacs.  Microsoft Windows: Microsoft visual C++.  Simple text editors: notepad in Windows. 1.1.6 Typical C++ development environment (section 1.9)
  • 24.
    Chapter 1 Dr.Ali Al-Hamdi 24  Phase 1: Editing a C++ program  Integrated Development Environment (IDE)  Function: supports the software-development process, including editors for writing and editing programs and debuggers for locating logic errors.  Popular IDEs include Microsoft® Visual Studio 2012 Express Edition, Dev C++, NetBeans, Eclipse, Apple’s Xcode and CodeLite. 1.1.6 Typical C++ development environment (section 1.9)
  • 25.
    Chapter 1 Dr.Ali Al-Hamdi 25  Phase 2: Preprocessing a C++ programs  The C++ preprocessor obeys commands called preprocessing directives, which indicate that certain manipulations are to be performed on the program before compilation.  These manipulations usually include other text files to be compiled, and perform various text replacements. 1.1.6 Typical C++ development environment (section 1.9)
  • 26.
    Chapter 1 Dr.Ali Al-Hamdi 26  Phase 3: Compiling a C++ program  The compiler translates the C++ program into machine-language code—also referred to as object code. 1.1.6 Typical C++ development environment (section 1.9)
  • 27.
    Chapter 1 Dr.Ali Al-Hamdi 27  Phase 4: Linking a C++ program  C++ programs typically contain references to functions and data defined elsewhere, such as in the standard libraries or in the private libraries of groups of programmers working on a particular project. 1.1.6 Typical C++ development environment (section 1.9)
  • 28.
    Chapter 1 Dr.Ali Al-Hamdi 28  Phase 4: Linking a C++ program  The object code produced by the C++ compiler typically contains “holes” due to these missing parts.  A linker links the object code with the code for the missing functions to produce an executable program (with no missing pieces).  If the program compiles and links correctly, an executable image is produced. 1.1.6 Typical C++ development environment (section 1.9)
  • 29.
    Chapter 1 Dr.Ali Al-Hamdi 29  Phase 5: Loading a C++ program  Before a program can be executed, it must first be placed in memory by the loader, which takes the executable image and components from shared libraries from disk and transfers it to memory. 1.1.6 Typical C++ development environment (section 1.9)
  • 30.
    Chapter 1 Dr.Ali Al-Hamdi 30  Phase 6: Executing a C++ program  Finally, the computer’s CPU, executes the program one instruction or several instructions in parallel at a time. 1.1.6 Typical C++ development environment (section 1.9)
  • 31.
    Chapter 1 Dr.Ali Al-Hamdi 31  Problems that may occur during time execution:  Programs might not work successfully on the first try of execution due to any type of errors that may exist in any of 6 phases discussed so far.  Type of errors?  Test-Driving C++ Application: read section 1.10 for Lab. tutorials. 1.1.6 Typical C++ development environment (section 1.9)
  • 32.
    Chapter 1 Dr.Ali Al-Hamdi 32 1.2 Input/Output and Operators (chapter 2 in textbook)
  • 33.
    Chapter 1 Dr.Ali Al-Hamdi 33  Example (1): Printing a line of text  Remarks?  Questions? 1.2.1 First program in C++ (section 2.2)
  • 34.
    Chapter 1 Dr.Ali Al-Hamdi 34  Programming tips  Comments  Including program u updating  Compiler error  Syntax errors  Good practices 1.2.1 First program in C++
  • 35.
    Chapter 1 Dr.Ali Al-Hamdi 35  The Stream Insertion Operator  Espace Sequences 1.2.1 First program in C++
  • 36.
    Chapter 1 Dr.Ali Al-Hamdi 36 1.2.2 Modifying first program (Section 2.3)  Example (2)  Remarks?  Questions?  Example (3)  Remarks?  Questions?
  • 37.
    Chapter 1 Dr.Ali Al-Hamdi 37 1.2.3 Another C++ programs (Section 2.4)  Example (4) 
  • 38.
    Chapter 1 Dr.Ali Al-Hamdi 38  Programming Notes and Tips  Variables declaration  Identifiers writing  Placement of variables declaration  Placement of binary operators  Cascading stream insertion operations  Stream manipulator 1.2.3 Another C++ programs
  • 39.
    Chapter 1 Dr.Ali Al-Hamdi 39  C++ Operators 1.2.4 Arithmetic (section 2.6)
  • 40.
    Chapter 1 Dr.Ali Al-Hamdi 40  Rules of operator precedence 1.2.4 Arithmetic (section 2.6)
  • 41.
    Chapter 1 Dr.Ali Al-Hamdi 41 1.2.5 Decision Making (sections 2.8) (section 2.8)
  • 42.
    Chapter 1 Dr.Ali Al-Hamdi 42  Example (6)  Remarks?  Questions? 1.2.5 Decision Making (sections 2.8) (section 2.8)
  • 43.
    Chapter 1 Dr.Ali Al-Hamdi 43  Programming notes and tips  Using declarations  Using directive namespace  Statement indentation  Logic error  Statement splitting 1.2.5 Decision Making (section 2.8)
  • 44.
    Chapter 1 Dr.Ali Al-Hamdi 44  Operator prececdence 1.2.6 Decision Making (section 2.8)
  • 45.
    Chapter 1 Dr.Ali Al-Hamdi 45 1.3 Introduction to Classes, Objects Member Functions, and Strings (chapter 3 in textbook)
  • 46.
    Chapter 1 Dr.Ali Al-Hamdi 46  Structure  Definition  Structure Syntax (Definition) struct struct_name { DataType member1_name; DataType member2_name; DataType member3_name; … }; 1.3.1 Structure and class: syntax C and C++ comparison
  • 47.
    Chapter 1 Dr.Ali Al-Hamdi 47  Structure  Declaration struct struct_name var_name;  Assigning value  Accessing var_name.memeber_name = value; 1.3.1 Structure and class: syntax C and C++ comparison
  • 48.
    Chapter 1 Dr.Ali Al-Hamdi 48 #include <stdio.h> /* Created a structure here. The name of the structure is StudentData.*/ struct StudentData{ char *stu_name; int stu_id; int stu_age; }; int main() { /* student is the variable of structure StudentData*/ struct StudentData student; /*Assigning the values of each struct member here*/ student.stu_name = "Sami"; student.stu_id = 1234; student.stu_age = 22; /* Displaying the values of struct members */ printf("Student Name is: %s", student.stu_name); printf("nStudent Id is: %d", student.stu_id); printf("nStudent Age is: %d", student.stu_age); return 0;  Structure  Example Output: Student Name is: Sami Student Id is: 1234 Student Age is: 22 1.3.1 Structure and class: example C and C++ comparison
  • 49.
    Chapter 1 Dr.Ali Al-Hamdi 49  Class  Definition  Calss Syntax (Creation or Definition) 1.3.1 Structure and class: syntax
  • 50.
    Chapter 1 Dr.Ali Al-Hamdi 50  Class  Declaration  Assigning value  Accessing ClassName ObjectName; ObjectName. MemberFunction; ObjectName. DataMember; ObjectName. DataMember=Value or string; 1.3.1 Structure and class
  • 51.
    Chapter 1 Dr.Ali Al-Hamdi 51 1.3.2 Test-Driving an Account Object
  • 52.
    Chapter 1 Dr.Ali Al-Hamdi 52 1.3.3 Account Class with a Data Member and Set and Get Member Functions
  • 53.
    Chapter 1 Dr.Ali Al-Hamdi 53 1.3.3 Account Class with a Data Member and Set and Get Member Functions
  • 54.
    Chapter 1 Dr.Ali Al-Hamdi 54 1.3.3 Account Class with a Data Member and Set and Get Member Functions
  • 55.
    Chapter 1 Dr.Ali Al-Hamdi 55 1.3.4 Account Class: Initializing Object with Constructor
  • 56.
    Chapter 1 Dr.Ali Al-Hamdi 56 1.3.4 Account Class: Initializing Object with Constructor
  • 57.
    Chapter 1 Dr.Ali Al-Hamdi 57 1.3.4 Account Class: Initializing Object with Constructor
  • 58.
    Chapter 1 Dr.Ali Al-Hamdi 58 1.3.5 Software Engineering with Set and Get Member Functions
  • 59.
    Chapter 1 Dr.Ali Al-Hamdi 59 1.3.6 Account Class with a Balance; Data Validation
  • 60.
    Chapter 1 Dr.Ali Al-Hamdi 60 1.3.6 Account Class with a Balance; Data Validation
  • 61.
    Chapter 1 Dr.Ali Al-Hamdi 61 1.3.6 Account Class with a Balance; Data Validation
  • 62.
    Chapter 1 Dr.Ali Al-Hamdi 62 1.3.6 Account Class with a Balance; Data Validation
  • 63.
    Chapter 1 Dr.Ali Al-Hamdi 63 1.3.6 Account Class with a Balance; Data Validation