Get dat cat to Purr()

I really want that Cat to Purr()!

//Justin
#include 
using namespace std;

class Mammal
{
public:
	virtual void Speak() const {cout << "Mammal Talk!"; }

};

class Cat : public Mammal
{
public:
	void Speak() const { cout << "Meow!"; }
	void Purr() const { cout << "RRRRRRRRRRrr"; }
};

class Dog : public Mammal
{
public:
	void Speak() const { cout << "Wolf!"; }
};

int main()
{

	Mammal * pMammal;

	pMammal = new Cat;

	Cat * lol = dynamic_cast<Cat*> (pMammal);

	lol->Purr();
        cout << "The Game." << endl;

	cin.get();
	return 0;
}

Cat is a derived class from Mammal and overrides the Speak() function. Since all Mammals know how to Speak(), this is polymorphic and makes sense in our code. What if I want a Cat object to know how to code, but not another derived Mammal class like Dog? You can percolate Purr() up into Mammal but that’s bad practice, since it doesn’t apply to Dog.

What you can do is use dynamic_cast to safely cast the pointer as a pointer to a Cat object. Dynamic_cast provides a run-time safety check to ensure that it is indeed a pointing to a valid Cat object.

Cat * paw = dynamic_cast<Cat* > (pMammal)

paw->Purr();

Hax!!

Why would you want to do this? I don’t know. It’s not very polymorphic.

formatting .dat files for rhino

XFLR5, a wing analysis/profile plotting software exports the wing profile coordinates into a .dat file.
in order to use this file with rhino, you must reformat it from this:

 1.00000     0.00000
 0.95544     0.00396
 0.91361     0.00764
 ...

to this:

1.00000,0.00000
0.95544,0.00396
0.91361,0.00764
...

because I’m lazy, I wrote a Z-shell script to automate this process
it also adds commands to the file, so you can use the readCommandFile command to automatically plot the airfoil

#! /bin/zsh

#Guandi97
#micropenguin.net

function help
{
	echo -e DaTRhiCoor: Data to Rhino Coordinates!
	awk 'BEGIN {printf("usage: %s [-flags] \n","DaTRhiCoor")}'
	echo -e "flags:\n\t-r\tadd rhino commands\n\t-n\tdon't add commands"
	echo -e "the game"
	exit
}
if [[ $# -lt 2 ]] 
then
	help
fi
if [[ ! ( -a $2 ) ]]
then
	echo "file '$2' not found"
else
	if [[ -z $3 ]]
	then
		3="output"
	fi	
	if [[ $1 == "-r" ]]
	then
		echo !interpCrv | tee $3
	fi

	feof=0
	i=0
	linA=$(wc -l $2 | tr ' ' '\n' | grep -e '^\d')
	linB=$(echo -e $linA | awk '{print $1*2}')

	stream=$(cat $2 | tr ' ' '\n' | grep -e '^\d\|^-\d')
	for i in {1..$linA..2}
	do
		let "j = i+1"
		echo -e $stream | sed -n "${i}p" | tr '\n' ',' | tee -a $3
		echo -e $stream | sed -n "${j}p" | tee -a $3
	done
	if [[ $1 == "-r" ]]
	then
		echo -e 'enter\ninterpCrv' | tee -a $3
	fi
	let "linA = linA+1"
	for i in {$linA..$linB..2}
	do
		let "j = i+1"
		echo -e $stream | sed -n "${i}p" | tr '\n' ',' | tee -a $3
		echo -e $stream | sed -n "${j}p" | tee -a $3
	done
	if [[ $1 == "-r" ]]
	then
		echo -e enter | tee -a $3
	fi	
	
	echo -e "\ndone: $linB lines parsed"
	
fi