Lecture 1. Logical operator for AND and OR
1. X=y=z=17 is valid, evaluate from right to left 2. C++ has integer division and floating point division 31/2/2.0 = (31/2)/2.0, integer first
} else {... } Note: compared to python, there is no : and tab requirement
...break; case 4: ...break; Case 5: ...break; ... default: .... (No break) }
}
{ Function code... }
Example: Int computeFactorial( int num ); Name should be descriptive for its purpose
Lecture 3
Lecture 4 Compiling and running
Lecture 5
Lecture 6
--------------------------------------------------------------------------------------------------------------------- Lecture 05: Array
Lecture 7
“true”; Else “false”
OOP: C++ contains OOP capability - Encapsulation - Inheritance - Polymorphism
Group data and functionality together
Lecture 8
Or initClass(int i): intVar(i), floatVar(0) {;}
Lecture 9
#define _INTCLASS_H_ ...class..prototype # endif
Sequence of bytes as input Output is also a sequence of bytes
inFile >> a; (first line in txt file inFile >> b; (second line in txt file inFile.close();
ifstream inFile; // declare an input file object, inFile inFile.open(“a.txt”) // 1. Detect if openning fail if (inFile.fail()) { Cout << “again...” << endl; Exit(1); } validInput = false; While (!validInput) { inFile >> a; If (inFile.eof()) { Cout << “ reached end of file” << endl; Exit(2); } Else if (inFile.fail()) { inFile.clear(); inFile.ignore(200, ‘\n’) } Else { validInput = true; } }
Lecture 11
Lecture 12
iPtr = new int[5]; // this is how you determine the size of the program along the way, instead of statically determining it. One can separate declare an pointer and allocate an pointer..
Lecture 13
int ** = &iPtr;
ColorClass ** pixArys; // this is a array that contains pointer-type-pointers... Each pointer pointing to a column // pointer-type-pointers -> ptp -> need double * // ... Determine numRows pixArys = new ColorClass* [numRows]; // this is explictly saying that pixArys is an array of ColorClass-type-pointers for (r=0, r<numRows, r++;0 pixAry[i] = new ColorClass[numCols]; // each pixAry is an array // Clear memory leaks issue, free the memory space allocated by the pointers // delete all columns corresponding to pixAry For (r=0, r< numRows, r++) Delete [] pixAry[r]; // delete pixAry Delete[] pixAry; // graphically, this is how it works.. // first, a number of memory space is allocated for CC**, which is pointer’s array....each one of them contains the address(i.e., pointer) of/pointing to the address of element of first column, for each row.. // then, each of this pointer pointing to a memory space of certain row, which contains an array, of columns. // therefore, when free the memory, you need free two times.. For rows and for columns.. // note that it is slightly different from purely 1D array...
is equal to int * calloc(num, sizeof(int)), but later one is initialize the array as zero
String getName() const; Lecture 14
|
AuthorShaowu Pan Archives
December 2017
Categories
All
|