Slide 1.26 Introduction to QtCreator. Can show creating a new project, advertise Qt as a cross platform frame- work (with many extension to c++), mobile android/ios... games+applications. /* * hello.cpp * This program prints a welcome message * to the user. */ #include int main() { std::cout << "Hello, world!" << std::endl; return 0; } ---------------------------------------------------------------------- Slide 1.27 cc -c main.cpp cc main.o -o tddd86 ./tddd86 ---------------------------------------------------------------------- Slide 1.28: Show the effect of return value (from terminal with $?) ---------------------------------------------------------------------- Slide 1.34: /* * main.cpp * This program introduces pointers and references. */ #include int main() { int a[100]; int* p= a; a[0]=12; std::cout << a[0] << " " << p[0] << std::endl; return 0; } ---------------------------------------------------------------------- Slide 1.35: Do some pointer arithmetic with p (set some more value in a); ---------------------------------------------------------------------- Slide 1.35: show the similitude between "int* const" and "int& ": // int b = 10; // int& r; // int& r=b; // std::cout << "r= " << r << ", b=" << b << ", p=" << p << std::endl; // b = 12; // std::cout << "r= " << r << ", b=" << b << ", p=" << p << std::endl; ---------------------------------------------------------------------- Slide 1.36: show "using namespace std;" ---------------------------------------------------------------------- Slide 1.37: Show functions: int max( int a , int b ) { return ( a < b ) ? b : a ; } struct point { int x , y ; int max ( ) { return max( x , y ) ; } } ; // Then show p u b l i c / p r i v a t e ---------------------------------------------------------------------- Slide 1.39: int themax(int a, int b) { if(a > b) return a; else return b; } int main() { int bigger= themax(17, 42); cout << "max= " << bigger << endl; return 0; } Switch the declaration between main and max ---------------------------------------------------------------------- Slide 1.40: Add the prototype. ---------------------------------------------------------------------- Slide 1.43: Show the swap function in action. Use debug. ---------------------------------------------------------------------- Slide 1.43: Show returning more than two values void minmax (int a, int b, int& min, int& max) { ... } Large object struct t { int a[100]; }; void this_does_copy(t v) { std::cout << v.a << std::endl; } void this_does_not_copy(t& v) { std::cout << v.a << std::endl; } intmain(int argc, char ∗∗argv) { tt1; std::cout << t1.a << std::endl; this_does_copy(t1); this_does_not_copy(t1); } ---------------------------------------------------------------------- Slide 1.43: Show the compilation error void grow (const int& age) { age = age + 1 ; } int main ( ) { int age = 20 ; grow(age) ; return 0 ; } ----------------------------------------------------------------------