C++ branching - Lecture notes ch3,ch2 PDF

Title C++ branching - Lecture notes ch3,ch2
Course C++ Programming 1
Institution Orange Coast College
Pages 2
File Size 68.2 KB
File Type PDF
Total Downloads 115
Total Views 168

Summary

Notes focus on strings, references and conditional operators and statements...


Description

C++ Notes CS150 ● Branching is a conditional execution (some steps may be performed depending on the conditions) ● Relational operators include: =(greater than or equal to) ● Boolean or logical operator: !(not), | | (or), && (and) Five types of statements ● Independent statements do not affect another. ● Sequential statements go in an order and ignores some decisions ● Nested statements make a decision inside another decision( a condition inside another condition) ● Numbered statements (example a switch statement, which a variable can be tested against different values) ● Conditional statements consists of if else if else ( they can be executed or not depending on the condition)

● Relational operators tell us the order of two variables ● If else if else (can be used to test multiple possible outputs) ● Never use == with floating point numbers (they are not precise) Ex) if (sum == 1.0) C++ library strings ● String are not included in C++, you have to include is by writing #include at the top of the program ● “hello world” is and array ● Explicitly declaring a string is declared by including {} Ex) string s {“Hello}

String raw = R”(“\hello\”)”; // “\hello\” (you can avoid escape characters with this method of string raw. ● Member functions = size ( ) , returns the length of the string , string::size_type (gets size type in the string. C++ string operations ● C++ library types act like built-in types (a difference between C++ and java) ● C++ supports copy assignment Ex) string a = “hey” , b= a // 2 string objects ● The characters inside a string can be modified unlike java ● To select individual characters of a string use : [] , at(), front(), back() At() checks the range , it can crash and tell you if your out of bounds , [] does not Front() and back() do not throw exceptions. Substrings ● Substring is a portion of an existing string . you write it like this : subst(position, length) ● You can get an error if the position > str.size() Reference ● A reference acts like a nickname for an existing variable ● A reference is not a creation of a new variable ● Indicating a reference done by adding an & between parameter’s name and type Constant references ● References refer to l-values ● References parameter can be more useful but can be a disadvantage (they don’t make a copy) . if you change the reference parameter the output parameters changes....


Similar Free PDFs