C++ Info and Projects

C++ Info
General
C++ is a programming language, used for computers. C++ is created by a Bjarne Stroustrup, from denmark. C++ is a better version of C (C programming language). C++ have classes which C dosen't have.

Variables

NameDescriptionSize*Range*
charCharacter or small integer.1bytesigned: -128 to 127
unsigned: 0 to 255
short int (short)Short Integer.2bytessigned: -32768 to 32767
unsigned: 0 to 65535
intInteger.4bytessigned: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long)Long integer.4bytessigned: -2147483648 to 2147483647
unsigned: 0 to 4294967295
boolBoolean value. It can take one of two values: true or false.1bytetrue or false
floatFloating point number.4bytes+/- 3.4e +/- 38 (~7 digits)
doubleDouble precision floating point number.8bytes+/- 1.7e +/- 308 (~15 digits)
long doubleLong double precision floating point number.8bytes+/- 1.7e +/- 308 (~15 digits)
wchar_tWide character.or 4 bytes1 wide character

Strings
Variables that can store non-numerical values that are longer than one single character are known as strings.

The C++ language library provides support for strings through the standard string class. This is not a fundamental type, but it behaves in a similar way as fundamental types do in its most basic usage.

A first difference with fundamental data types is that in order to declare and use objects (variables) of this type we need to include an additional header file in our source code: <string> and have access to the std namespace.

If, Else


If, Else
The if statement says that if that equals true then do something, if not then do something else. Like this:

#include <iostream>
#include "conio.h"
using namespace std;
int main() {
  // define two integers
  int x = 3;
  int y = 4;
//print out a message telling which is bigger
  if (x > y) {
    cout << "x is bigger than y" << endl;
_getch();
  }
  else {
    cout << "x is smaller than y" << endl;
_getch();
  }
}

Here we decleares that if X is bigger than why then print: X is bigger than Y, else if Y is bigger that x then print: X is smaller than y.


Projects
Hello World

#include <iostream>
#include "conio.h"
using namespace std;


void main(){
cout << "Hello World" << endl;
getch();
}





Hello World more lines

#include <iostream>
#include "conio.h"
using namespace std;


void main(){
cout << "Hello World" << endl;
cout << "Hello World" << endl;
cout << "Hello World" << endl;
cout << "Hello World" << endl;
cout << "Hello World" << endl;
getch();
}