Jul 07

Lesson 1: Short Notes on C++

This short note is for those who already know C++ and want to refresh their memory. Starters can still take a look to get an overall idea.

  • Three pillars of object-oriented development: encapsulation, inheritance, and polymorphism.
  • C++ supports encapsulation through (user-defined) classes. Class properties and internal workings can be hidden from outside world.
  • C++ supports polymorphism through overloading, overriding
  • C++ supports inheritance by allowing classes to share (extend) the properties and workings of other classes
  • Managed C++ is an extension of the C++ language. Managed C++ allows the use of Microsoft's new platform (.Net) and libraries
  • How to include header files: #include <iostream> or #include <iostream.h>
  • Print in the console: std::cout <<"Hello World!\n"; or cout <<"Hello World!\n"; std::cout << "Number and String together:\t" << 70000;
  • Read from the console: std::cin >> response; where response is a variable
  • If you do not want to use 'std::' in the previous examples, you can use the statement 'using namespace std;' before
  • How to comment: use // to comment single line or use /*c++ code*/ to comment a block
  • [ Code commenting is a good practice only when you describe why is the code block than what the block does.]
  • C++ is case sensitive
  • Keywords, Reserved words: Some words are reserved in C++. You can not use them as variable names.
  • Keywords:
    asm else new this auto enum operator throw bool explicit private true break export protected try case extern public typedef catch false register typeid char float reinterpret_cast typename class for return union const friend short unsigned const_cast goto signed using continue if sizeof virtual default inline static void delete int static_cast volatile do long struct wchar_t double mutable switch while dynamic_cast namespace template
  • Reserved words: And bitor not_eq xor and_eq compl or xor_eq bitand not or_eq
  • Variable declaration: unsigned int age;
  • How to create aliases: typedef unsigned short int USHORT;
  • C++ Escape characters:
    \a Bell (alert)
    \b Backspace
    \f Form feed
    \n New line
    \r Carriage return
    \t Tab
    \v Vertical tab
    \' Single quote
    \" Double quote
    \? Question mark
    \\ Backslash
    \000 Octal notation
    \xhhh Hexadecimal notation
  • Define constants:
    #define numberOfContinents 7
  • Enumerated constants:
    enum WeekDays { Monday, Tuesday, Wednesday, Thursday, Friday};
    WeekDays day;
Skip to toolbar