Tag: c++

Check NTFS Version

If you need to know which version of NTFS you are using you can do that with the fsutil.exe and the following command.

In my case I am testing my C:\ drive:

fsutil fsinfo ntfsinfo c:

fsutil

More on NTFS Versions on wikipedia.



Simple Bean Machine program done in Powershell

Powershell Header

In the last article I posted the C++ Code for a simple Bean Machine output. Now I did the same in Powershell. I know this is not really a fantastic Powershell script, but its good to show others how things get done in Powershell.

Like in the C++ bean machine it works like this:

Bean MachineAnd the Output should look like this:

Bean Machine outputAnd here is how you do this in Powershell:

#Config
[int]$ballCount = 100
[array]$box = @(0, 1, 2, 3, 4, 5)
[string]$line = " +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-->"
[string]$numbers = " 0 5 10 15 20 25 30 35 40 45 50"
[object]$random = New-Object System.Random
 
#count
for([int]$i = 0; $i -lt $ballCount; $i++){
[int]$counter = 0
 
for([int]$j = 0; $j -lt 5; $j++){
$leftorright = $random.next(0,2)
$counter = $counter + $leftorright
}
$box[$counter] = $box[$counter] + 1
}
 
#Output
Write-Host $numbers
Write-Host $line
for ([int]$t = 0; $t -lt 6; $t++){
[string]$Statusline = ""
for ([int]$u = 0; $u -lt $box[$t]; $u++){
[string]$Statusline += "#"
}
Write-Host $t "|" $Statusline $box[$t]
Write-Host $line
}


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 
#include 
 
using namespace std;
 
void rect2polar(double &amp;value, double &amp;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 &lt;&lt; "x = " &lt;&lt; x &lt;&lt; endl;
    cout &lt;&lt; "y = " &lt;&lt; y &lt;&lt; endl;
    cout &lt;&lt; "value = " &lt;&lt; value &lt;&lt; endl;
    cout &lt;&lt; "angle = " &lt;&lt; angle &lt;&lt; endl;
    //system("PAUSE");
    return 0;
}


Simple C++ dec2bin program @KTSI

This is a very simple dec2bin program done for KTSI.

#include 
#include 
#include 
 
using namespace std;
 
string dec2bin (int v) {
	if (v &gt; 255) {
		return "";
	}
	else { 
		string bin;
		int oneorzero;
		for(int i=8;i&gt;0;i--) {
			oneorzero = v % 2;
			if (oneorzero == 1) {
				bin = "1" + bin;
			}
			else {
				bin = "0" + bin;
			}
			v /= 2;
 
		}
 
	return bin;
 
	}
}
 
int main(){
    int v;
    do {
        cout &lt;&lt; "Wert(ende = -1) = "; if (!(cin &gt;&gt; v)) {
            return 0;
        }
        if (v &lt; 0) break;
        string s = dec2bin(v);
        cout &lt;&lt; s &lt;&lt; endl; //system("PAUSE"); } while(v &gt;= 0);
    cout &lt;&lt; "bye" &lt;&lt; endl;
    //system("PAUSE");
    return 0;
}


Simple C++ Takeway Game @KTSI

This is a simple C++ Takeway Game done for KTSI.

#include 
using namespace std;
 
int main (int argc, char * const argv[]) {
 
	// Init
	int coinCount = 1;
 
	// Welcome Message
    cout &lt;&lt; "Welcome to the TakeAway Game" &lt;&lt; endl &lt;&lt; "====================================" &lt;&lt; endl;
 
	// Input for coinCount
	while (coinCount &lt;= 15) {
		cout &lt;&lt; "Please enter how many coins you wanna use (&gt;15): ";
		cin &gt;&gt; coinCount;
	}
	cout &lt;&lt; "We start with " &lt;&lt; coinCount &lt;&lt; " coins" &lt;&lt; endl; while (coinCount &gt; 0) {
		// Human takes Coins
		int takenCoins = 0;
		while (takenCoins &lt; 1 || takenCoins &gt; 3) {
			cout &lt;&lt; "Please take 1,2 or 3 coins: "; cin &gt;&gt; takenCoins;
		}
		cout &lt;&lt; "You toke " &lt;&lt; takenCoins &lt;&lt; " coins" &lt;&lt; endl;
 
		coinCount -= takenCoins;
		if (coinCount == 0) {
            cout &lt;&lt; "D'OH! you won..." &lt;&lt; endl;
            break;
        }
		cout &lt;&lt; "there are still " &lt;&lt; coinCount &lt;&lt; " coins left" &lt;&lt; endl;
 
		int itakeCoins;
		int tempModu = coinCount % 4;
		if (tempModu == 0) {
			itakeCoins = 1;
		}
		else {
			itakeCoins = tempModu;
		}
		cout &lt;&lt; "I take " &lt;&lt; itakeCoins &lt;&lt; " coins" &lt;&lt; endl;
 
		coinCount -= itakeCoins;
		if (coinCount == 0) {
            cout &lt;&lt; "Ha! I won" &lt;&lt; endl;
            break;
        }
		cout &lt;&lt; "there are still " &lt;&lt; coinCount &lt;&lt; " coins left" &lt;&lt; endl;
	}
    return 0;
}


Simple C++ lottery program @KTSI

Here is a simple C++ lottery program done for the KTSI.

#include <iostream>
#include <cstdlib>
 
using namespace std;
 
int main (int argc, char * const argv[]) {
 
	int numberCount;
	int maxNumbers;
 
	cout << "Lottery Game" << endl << "=================================" << endl;
	cout << "How many Lottery Numbers = ";
	cin >> numberCount;
	cout << "from 1 to ? ";
	cin >> maxNumbers;
	cout << "You have chosen " << numberCount << " Lottery Numbers from 1 to " << maxNumbers << endl;
 
	int lotteryNumbers[numberCount];
	int i, j;
	bool newNumber;
 
	srand(0);
	for(i=0; i<numberCount; i++) // get numbers
	{
		do  
		{   // Check Random
			lotteryNumbers[i] = rand() % maxNumbers + 1;
			newNumber = true;
			for (j=0; j<i; j++)
			{  
				if (lotteryNumbers[j]==lotteryNumbers[i])
				{ // Check for existing numbers
					newNumber = false;
				}
			}
		} while (!newNumber);
	}
	for (i=0; i<numberCount; i++)
	{
		cout << lotteryNumbers[i] << " ";
	}
	cout << endl;
}