Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a comment
- // Win32Project1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream> // use cout and other things...
- #include <vector>
- #include <string>
- #include <fstream> // use file i/o
- using namespace std;
- int main() // main container
- {
- cout << "Hello World!" << endl;
- const double PI = 3.14159; // constant vars cannot be changed and are typically in all caps
- char myGrade = 'A'; // char is for single characters (consumes 1 byte in memory)
- bool isHappy = true; // 1 (true) 0 (false)
- int myAge = 22;
- float favNum = 666.666; // accurate up to 6 decimal places
- double otherFavNum = 7777.484394843839; // accurate up to 15 decimal places
- cout << "Favorite Number: " << favNum << endl;
- // other data types include
- // short int: At least 16 bits
- // long int: At least 32 bits
- // long long int: At least 64 bits
- // unsigned int: Same size as signed version
- // long double: No less then double
- cout << "Size of int (bytes): " << sizeof(myAge) << endl; // size of int in bytes
- int largestInt = 2147483647; // largest integer we could possible have
- int five = 5;
- cout << "5++ = " << five++ << endl; // outputs 5 first because increment occurs after value fetch
- cout << "++5 = " << ++five << endl; // output 7 because of above as well as inrement occuring prior to value fetch
- cout << "5-- = " << five-- << endl; // output 7 value is really 6
- cout << "--5 = " << --five << endl; // output 5
- // Order of Operations states * and / before + and -
- cout << "1 + 2 - 3 * 2 = " << 1 + 2 - 3 * 2 << endl; // -3
- cout << "(1 + 2 - 3) * 2 = " << (1 + 2 - 3) * 2 << endl; // 0
- // type casting
- cout << "4/5 = " << (float)4 / 5 << endl;
- // Comparison Operators: ==, !=, >, <, >=, <=
- // Logical Operators: &&, ||, !
- int age = 70;
- int ageAtLastExam = 16;
- bool isNotIntoxicated = true;
- if ((age >= 1) && (age < 16)) {
- cout << "You are not old enough to drive" << endl;
- }
- else if(!isNotIntoxicated) { cout << "You can drive if your blazed just not drunk dick" << endl; }
- else if(age >= 80 && ((age > 100) || ((age - ageAtLastExam) > 5))) {
- cout << "You can't drive old fuck" << endl;
- }
- else { cout << "You can drive!" << endl; }
- // switch cases
- int greetingOption = 2;
- switch (greetingOption) {
- case 1:
- cout << "bonjour" << endl;
- break;
- case 2:
- cout << "Hola" << endl;
- break;
- case 3:
- cout << "Hallo" << endl;
- break;
- default :
- cout << "Hello" << endl;
- }
- // Ternary operator
- // variable = (condition) ? true : false
- int largestNum = (5 > 2) ? 5 : 2;
- // Arrays
- int myFavNums[5]; // specify how many element containers you need
- int badNums[5] = { 4, 13, 14, 24, 34 };
- cout << "Bad Number 1: " << badNums[0] << endl;
- // multidimensional arrays
- char myName[3][9] = { {'N', 'e', 'y'},
- {'H', 'e', 'r', 'n', 'a', 'n', 'd', 'e', 'z'} };
- cout << "2nd letter in 2nd array" << myName[1][1] << endl;
- myName[0][2] = 'o';
- cout << "New Value " << myName[0][2] << endl;
- for (int i = 0; i <= 10; i++) {
- cout << i << endl;
- }
- for (int j = 0; j < 3; j++) {
- for (int k = 0; k < 9; k++) {
- cout << myName[j][k] << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement