Code Monkey home page Code Monkey logo

cpp's Introduction

Programming in C++ Efficiently

If you are a publisher and would like to publish the textbook worldwide, you can contact Prof. Shiqi Yu <[email protected]>.

Course 'CS205 C/C++ Program Design' in 2021 Fall at Southern University of Science and Technology.

Chapter 5: Input and Output

C style input and output

C++ style input and output

Lab:

  • Read from a binary, and print out in tex format
  • How to debug using VS Code.

Chapter 6: Memory and Pointer

Pointer

Allocate memory: C style

Allocate memory: C++ style

const variables

const int * p; int * const p;

Common mistakes of using a pointer

  • null pointer, random pointer
  • out of range
  • memory leak

Lab

  • allocate memory for an array string, modify elements by integer values one by one, then print out the result as a string. Please try to modify the element out of range and see what will happen.

Chapter 7: Basics of Functions

Function arguments (pass by value)

array and pointer arguments

C style array strings

struct arguments (copy data or address)

Reference and const

Lab:

  • an example to test integer arguments, pointer argument and reference arguments

Chapter 8: Advances in Functions

inline function (why inline? Comparison with macro)

Default arguments

Function overloading

Function templates

Recursion

Pointer to functions

Lab:

  • implement a function with default arguments.
  • overload a function which can compute the absolute value for an array, the array can be int, float and double vabs(int * p, int n); //should n be int or size_t, what's the difference, please create an arrary with more than 2^31 elements vabs(float * p, int n); vabs(float * p, int n);

Chapter 9: Speedup Your Program

Compiler options (-O3 for GCC, -Wall, etc…)

SIMD (SSE, AVX, NEON, RISC-V, Universal Intrinsics of OpenCV)

OpenMP

Memory Hierarchies and Speed

Crop ROI from a 2D Matrix

Intel, ARM and RISC-V Architechture

Lab:

Create two 1Mx1K float matrices matA and matB, compute matA + matB.

  • compute the result row by row and col by col, compare the performance difference
  • use -O3 to improve the speed
  • improve the speed using SIMD, will the speed be improved? Why?

Chapter 10: Basics of Classes

Class Definition

  • build-in types and user defined types
  • data componient and method/functions

Using a Class

  • Access control: public and private
  • Create an object and access members
  • const member functions
  • const member variables
  • static member variables

Constructors and Destructors

  • Constructors
  • Default Constructors
  • Destructors
  • Initialization

this pointer

Lab

Create a simple class. Please try to test:

  • access a private member
  • modify a const data member
  • modify a data member in a const function
  • initializate a const data member

Chapter 11: Advances in Classes

operator overloading

Constructor and assignment

Student s2=s1;
Student s3;
s3=s1;

friend Functions

<< operator

Automatic Conversions and Type Casts for Classes

Lab

overload + and << for your own defined class

Chapter 12: Dynamic Memory Management in Classes

Some Default Operations

  • Default constructor
  • Copy constructor
  • Assign operator
  • Default destructor
  • How pointer members work defaultly

An Example with Dynamic Data Allocation

Solution

Matrix Data Management in OpenCV

Lab

Create a class for matrices which elements are in float. The class should support the follow operations and has no memory management problem. When a matrix is assigned to another by =, the two matrices will share the same data. class Matrix{...}; Matrix a(3,4); Matrix b(3,4); Matrix c = a + b; Matrix d = a * 2.0f;

Chapter 13: Class Inheritance

Deriving a Class

  • Constructor
  • Destructor

Static and Dynamic Binding

Vitural Functions

Access Control (protected)

Dynamic Memory Management

Lab

Chapter 14: Class Templates and std Library

Defining a Class Template

Templates in OpenCV

Templates in std

Lab

Create a matrix template class which can handle different data types.

Chapter 15: Exceptions

Chapter 16: Friend Classes and Nested Classes

Reference

  1. Mr. Yitong Wang's repo for the course in Fall 2020. https://github.com/YeeTone/CS205-2020Fall

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.