// 04cinAndcout.cpp
//       What: Experimenting with the std::cin and std::cout objects
//    Author: Niall Madden
//      Date: 01-Feb-2017
//    Week 4: CS319 - Scientific Computing
// More info: http://www.maths.nuigalway.ie/~niall/CS319/Week04

#include <iostream>
#include <iomanip>
#include <cstdlib> //needed for the rand() function

int main(void)
{
  std::cout << "Output a table of ASCII values\n";
  for (int i=65; i<123; i++)
  {
    std::cout.width(8);
    std::cout << i;
    std::cout.width(3);
    std::cout << (char) i;
    if ( (i%5) == 4)
      std::cout << std::endl;
  }
  std::cout << std::endl << std::endl;

  std::cout << "\n\n Here are some random, 6-digit numbers," <<
    " that include any leading zeros\n";  
  std::cout.fill('0');
  for (int i=0; i<8; i++)
  {
    std::cout.width(6);
    std::cout << rand()%200000 <<std::endl;
  }
  std::cout << std::endl << std::endl;

  std::cout << "Decimal expansions of Pi to various levels of precision\n";
  double Pi=3.1415926535;
  for (int i=1; i<=10; i++)
  {
    std::cout.precision(i);
    std::cout << "Pi (correct to "<< i << " digits) is "
	      << Pi << std::endl;
  }
   
  std::cout << "\n\nSome hexidecimal numbers.\n";
  std::cout.fill(' ');
  for (int i=0; i<20; i++)
  {
    std::cout.width(4);
    std::cout << "i=" << std::dec << i << "=" << std::hex << i;
    std::cout << std::endl;
  }


  std::cout << "\n\nA logic table\n";
  int a,b,c;
  std::cout << "  a     b   | a->b \n";
  std::cout << "------------------\n";
  for (a=0; a<=1; a++)
    for (b=0; b<=1; b++)
    {
      c = (!a)||b;
      std::cout.width(5);
      std::cout << std::boolalpha << (bool) a << " " << std::setw(5)
		<< (bool) b << 	" | " <<  (bool) c << std::endl;
    }
  return(0);
}
