Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A tutorial introduction to C++ programming language, focusing on object-oriented programming (OOP) concepts. It covers the history of C++, its advantages over other languages, and the basics of OOP, including classes, objects, and access modifiers. The tutorial also introduces the Code::Blocks IDE and provides examples of basic syntax and functions.
Typology: Exams
1 / 57
tutorial version 0.
On the room terminals there is a MobaXterm link on the desktop
module load gcc/5.3. module load hunspell/1.4. module load wxwidgets/2.8. module load gdb/7.11. module load codeblocks mkdir cpp_tutorial && cd !$ unzip /scratch/intro_to_cpp_tutorial_0.1.zip
Go to:
and download the Powerpoint or PDF copy of the unified presentation. Easy way to get there: Google “bu rcs tutorials” and it’s the 1 st or 2 nd link. Also download the “Additional Materials” file and unzip it to a convenient folder on your laptop. Download the Code::Blocks development environment: http://www.codeblocks.org/downloads/
folder. Linux: likely available from your Linux distro’s package management system Mac OSX: get the CodeBlocks-13.12-mac.zip file and unzip it to a convenient folder. Also you will need Apple’s Xcode software with the command line tools installed.
For details more check out A History of C++: 1979 −
Wikipedia lists >40!: https://en.wikipedia.org/wiki/Programming_paradigm Procedural (C, Fortran, Matlab) Dataflow (Simulink, VHDL, Labview) Functional (Excel, Lisp, F#)
Seeks to define a program in terms of the things in the problem (files, molecules, buildings, cars, people, etc.) and what they need and can do.
OOP defines classes to represent these things. Classes can contain data and methods (internal functions). Classes control access to internal data and methods. A public interface is used by external code when using the class. This is a highly effective way of modeling real world problems inside of a computer program. public interface private data and methods “Class Car”
C++ Python Fortran Language Type compiled interpreted compiled Variable type style Strong Strong Strong Variable Safety unsafe safe mostly safe Type checking At compilation and at run-time Run-time Compilation Paradigms OO, procedural, functional, generic, dataflow, and others OO, procedural, functional Procedural C compatibility Nearly 100% Not directly Call C libraries, with many pitfalls Relative speed Fast Slow Fast “Actually I made up the term ‘object-oriented’, and I can tell you I did not have C++ in mind.”
Complex problems and programs can be effectively implemented OOP works in the real world! No other language quite matches C++’s combination of performance, expressiveness, and ability to handle complex programs.
Program performance matters Dealing with large amounts of data, multiple CPUs, complex algorithms, etc. Programmer productivity is less important It is faster to produce working code in Python, R, Matlab or other scripting languages! The programming language itself can help organize your code Not everything is a vector or matrix, right Matlab? Access to libraries that will help with your problem Ex. Nvidia’s CUDA Thrust library for GPUs Your group uses it already! “If you’re not at all interested in performance, shouldn’t you be in the Python room down the hall?” ― Scott Meyers (author of Effective Modern C++)
High (objects) and low (fiddling with memory) level styles are supported
You are in control of memory usage
And your instructor makes no claim to know the entire language!
You are in control of memory usage
“C++: an octopus made by nailing extra legs onto a dog.”
Run it right on the terminal or on the SCC (module load codeblocks)
cross-platform: supported on Mac OSX, Linux, and Windows Oriented towards C, C++, and Fortran, supports others such as Python Short learning curve compared with other IDEs such as Eclipse or Visual Studio
It can convert its build system files to make and Makefiles so you are not tied to C::B
Handles build process for you Syntax highlighting and live error detection Code completion (fills in as you type) Creation of files via templates Built-in debugging Code refactoring (ex. Change a variable name everywhere in your code) Higher productivity IDEs available on the SCC Code::Blocks (used here) geany – a minimalist IDE, simple to use Eclipse – a highly configurable, adaptable IDE. Very powerful but with a long learning curve Spyder – Python only, part of Anaconda Some Others Xcode for Mac OSX Visual Studio for Windows NetBeans (cross platform)
st
Step 2. Choose the Console category and then the Console application and click Go.
Step 3: Click Next on the “Welcome to the new console application wizard!” screen. Step 4: Choose C++! …then click Next.
Step 5. Enter a project title. Let C::B fill in the other fields for you. If you like you can change the default folder to hold the project. Click Next.
Step 6: Choose the compiler. For this tutorial, choose GNU GCC as the compiler. Click Next.
Check off the C++11 option. Click Release on the left and do the same there as well. Do this anytime we create a project in C::B
Step 8: Your project is now created! Click on Sources in the left column, then double-click main.cpp. Click the icon in the toolbar or press F9 to compile and run the program.
The main routine – the start of every C++ program! It returns an integer value to the operating system and takes no arguments (). Statement that returns an integer value to the operating system after completion. 0 means “no error”
loads a header file containing function and class definitions Loads a namespace called std. Namespaces are used to separate sections of code for programmer convenience. To save typing we’ll always use this line in this tutorial. cout is the object that writes to the stdout device, i.e. the console window. It is part of the C++ standard library. Without the “using namespace std;” line this would have been called as std::cout. It is defined in the iostream header file. << is the C++ insertion operator. It is used to pass characters from the right to the object on the left. endl is the C++ newline character.