Simple C++ Bean machine program @KTSI

This is a simple Bean machine program done in C++ for KTSI.

This is how it works, you drop 100 balls and they fall in 6 different boxes.

Bean MachineAnd this is how the C++ output should look like:

Bean Machine outputAnd here is how its done:

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main (int argc, char * const argv[]) {

	// initial
	int ballCount = 100;
	int box[6] = { 0, 0, 0, 0, 0 };
	string line = " +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-->";
	string numbers = " 0     5     10     15     20     25     30     35     40     45     50";
	int leftorright = 0;

	// Need for Random Numbers
	srand ( time(NULL) );

	// Rund ballCount (100) zahl = rand() % 2;
	for (int i=0; i<ballCount; i++) {
			int counter = 0;

		for (int j=0; j<5; j++) {
			// left or right
			leftorright = rand() % 2;
			counter = counter + leftorright;
		}
		box[counter] = box[counter]++;

	}	

	// Output
	cout << numbers << endl << line << endl;
	for (int t=0; t<6; t++) {
		cout << t << " |";
		for (int u=0; u < box[t]; u++) {
			cout << "#";
		}
		cout << " " << box[t] << endl << line << endl;
	}
	return 0;
}

I also did this program in Powershell

Simple C++ rect2polar program @KTSI

This is another simple C++ program done for KTSI. This one converts rectangular to polar coordinates.

#include <iostream>
#include <cmath>

using namespace std;

void rect2polar(double &value, double &angle, double x, double y) {
    value = sqrt(pow(x, 2) + pow(y, 2));
    angle = 180 / M_PI * atan2(y,x);
}

int main(){
    double value;
    double angle;
    double x = 4;
    double y = 3;

    rect2polar(value, angle, x, y);

    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
    cout << "value = " << value << endl;
    cout << "angle = " << angle << endl;
    //system("PAUSE");
    return 0;
}

How to create a Windows 7 & Windows Server 2008 R2 Install USB Stick

Its very simple to create a Windows 7 or Windows Server 2008 R2 bootable USB Stick. Microsoft provides a tool called Windows 7 USB/DVD Tool. This tool also works for Windows Server 2008 R2.

  1. Download Windows 7 USB/DVD Tool and install it
  2. Start the programm and choose the .iso Image (Windows 7 or Windows Server 2008 R2)
    Windows 7 USB/DVD Tool
  3. Choose which media you want to create (USB)
    Windows 7 USB/DVD Tool
  4. Choose USB device
    Windows 7 USB/DVD Tool
  5. Begin Copying and after some minutes your USB Stick is ready to use