Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]
  • Table Of Contents Toc
Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]

Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]

By : Dorothy R. Kirk
5 (13)
close
close
Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]

Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]

5 (13)
By: Dorothy R. Kirk

Overview of this book

Even though object-oriented software design enables more easily maintainable code, companies choose C++ as an OO language for its speed. Object-oriented programming in C++ is not automatic – it is crucial to understand OO concepts and how they map to both C++ language features and OOP techniques. Distinguishing your code by utilizing well-tested, creative solutions, which can be found in popular design patterns, is crucial in today’s marketplace. This book will help you to harness OOP in C++ to write better code. Starting with the essential C++ features, which serve as building blocks for the key chapters, this book focuses on explaining fundamental object-oriented concepts and shows you how to implement them in C++. With the help of practical code examples and diagrams, you’ll learn how and why things work. The book’s coverage furthers your C++ repertoire by including templates, exceptions, operator overloading, STL, and OO component testing. You’ll discover popular design patterns with in-depth examples and understand how to use them as effective programming solutions to solve recurring OOP problems. By the end of this book, you’ll be able to employ essential and advanced OOP concepts to create enduring and robust software.
Table of Contents (30 chapters)
close
close
1
Part 1: C++ Building Block Essentials
6
Part 2: Implementing Object-Oriented Concepts in C++
13
Part 3: Expanding Your C++ Programming Repertoire
19
Part 4: Design Patterns and Idioms in C++
25
Part 5: Considerations for Safer Programming in C++

Reviewing C++ operators

Unary, binary, and ternary operators exist in C++. C++ allows operators to have different meanings based on the context of usage. C++ also allows programmers to redefine the meaning of selected operators when used in the context of at least one user defined type. The operators are listed in the following concise list. We’ll see examples of these operators throughout the remainder of this section and throughout the course. Here is a synopsis of the binary, unary, and ternary operators in C++:

Figure 1.1 – C++ operators

Figure 1.1 – C++ operators

In the aforementioned binary operator list, notice how many of the operators have “shortcut” versions when paired with the assignment operator =. For example, a = a * b can be written equivalently using a shortcut operator a *= b. Let’s take a look at an example that incorporates an assortment of operators, including the usage of a shortcut operator:

score += 5;
score++;
if (score == 100)
    cout << "You have a perfect score!" << endl;
else
    cout << "Your score is: " << score << endl;
// equivalent to if - else above, but using ?: operator
(score == 100)? cout << "You have a perfect score" << endl:
                cout << "Your score is: " << score << endl; 

In the previous code fragment, notice the use of the shortcut operator +=. Here, the statement score += 5; is equivalent to score = score + 5;. Next, the unary increment operator ++ is used to increment score by 1. Then we see the equality operator == to compare score with a value of 100. Finally, we see an example of the ternary operator ?: to replace a simple if - else statement. It is instructive to note that ?: is not preferred by some programmers, yet it is always interesting to review an example of its use.

Now that we have very briefly recapped the operators in C++, let’s revisit function basics.

CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Deciphering Object-Oriented Programming with C++ [WARNING: NOT FOR USE IN OTHER MATERIAL/SEE CONTRACT]
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist download Download options font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon