main.cpp

#include <iostream>
#include <cmath>
using namespace std;

int main() {

  //
  // Rather than produce a whole new project for each exercise, we put
  // all the solutions together in one file
  //

  //
  // Exercise1
  //

  cout << "Exercise 1\n";
  cout << (true || false) << "\n";
  cout << ((true && false) || true) << "\n";
  cout << (true && (false || true)) << "\n";
  cout << ((true && false) || true) << "\n"; // we had to put in brackets to prevent compiler warnings
  cout << (3 * 5 == 15 && (7 * 8 == 21 || true != false)) << "\n";

  //
  // Exercise2
  //

  cout << "Exercise 2\n";
  cout << "int\t" << sizeof(int) << "\n";
  cout << "short int\t" << sizeof(short int) << "\n";
  cout << "long int\t" << sizeof(long int) << "\n";
  cout << "long long\t" << sizeof(long long) << "\n";
  cout << "unsigned int\t" << sizeof(unsigned int) << "\n";
  cout << "unsigned short int\t" << sizeof(unsigned short int) << "\n";
  cout << "unsigned long int\t" << sizeof(unsigned long int) << "\n";
  cout << "unsigned long long\t" << sizeof(unsigned long long) << "\n";

  //
  // Exercise3
  //

  cout << "Exercise 3\n";
  cout << 'A' << '\t' << ((int)'A') << '\n';
  cout << 'Z' << '\t' << ((int)'Z') << '\n';
  cout << 'a' << '\t' << ((int)'a') << '\n';
  cout << 'z' << '\t' << ((int)'z') << '\n';
  cout << "Carriage return" << '\t' << ((int)'\r') << '\n';
  cout << "New line" << '\t' << ((int)'\n') << '\n';
  cout << "Tab" << '\t' << ((int)'\t') << '\n';

  //
  // Exercise4
  //

  cout << "Exercise 4\n";
  unsigned int x = 3;
  unsigned int y = 5;
  cout << (x - y) << "\n";
  // In binary 3 is given by 0000...00000011
  //           5 is given by 0000...00000101
  // Subtracting 3 from five gives -2
  //                         1000...00000010
  // Which is a very large unsigned int

  //
  // Exercise5
  //

  cout << "Exercise 5\n";
  cout << "Please type a character:\n";
  char c;
  cin >> c;
  int charCode = (int)c;
  if (charCode >= 'a' && charCode <= 'z') {
    charCode = charCode - 'a' + 'A';
  }
  char ucase = (char)charCode;
  cout << "\nIn upper case that character is ";
  cout << ucase << "\n";

  return 0;
}