Friday, May 31, 2013

C++ a history and overview

C++
C++ actually stands for Classes plus plus. C which stands for classes did not provide enough for the growing needs of programmers. Thus C++ was born. It was created by the same person who created C. His name was Bjarne Stroustrup. He was a danish computer scientist. C++ is good for userspace applications. However, C is far better for kernels. C++ hides many of the many memory routines that a kernel would use. C++ is also very simple compared to C. C and C++ are both compiled languages. They can be directly run by the systems CPU. Common compilers for these languages include MS visual studio and personal favorite, albeit a toolchain, GCC. C++ files end in ".cpp" or ".h". IDE's are used to make the development of programs more efficient IDE stands for integrated development environment.
Below I offer some example code that wrote:


Setting up your build environment:
On Ubuntu: $ sudo apt-get install build-essential codeblocks
On redhat: $ sudo yum install codeblocks gcc
On Archlinux: $ sudo pacman -S codeblocks gcc
On Windows: Download and install: Code::Blocks
Resources, references and tutorials:
Reference: http://www.cplusplus.com/reference/
Articles: http://www.cplusplus.com/articles/
File IO: http://www.eecs.umich.edu/eecs/courses/eecs380/HANDOUTS/cppBinaryFileIO-2.html
Reference: en.cppreference.com/
Tutorials:http://www.cplusplus.com/doc/tutorial/
Online Compiler: http://ideone.com/
Learn C++: http://www.learncpp.com/
Creator of C++ HomePage: http://www.stroustrup.com/


Code snippets:

My program for solving the quadratic formula:
#include <iostream>
//main.cpp
#include "Quad.h"
double x,y,z; // variable x = 'a', variable y = 'b' and variable z = 'c'.
int main()
{
    std::cout << ("Enter the value for 'a': ");
    std::cin >> x;
    std::cout << ("Enter the value for 'b': ");
    std::cin >> y;
    std::cout << ("Enter the value for 'c': ");
    std::cin >> z;
    std::cout << ('\n') << (Quad(x,y,z).first) << ('|') << (Quad(x,y,z).second) << std::endl;
    return 0;
}
//Quad.h
#include 
inline std::pair< std::complex, std::complex > Quad(double a, double b, double c)
{
    std::complex  square = (b*b * -4*(a*c));
    return {(-b + std::sqrt(square)/(2*a)), (-b - std::sqrt(square)/(2*a))};
}