The United SpongeBob Forums
Off Topic => The Waste Land => Topic started by: DoomBringer316 on December 20, 2006, 09:42:55 am
-
#include<iostream>
#define NULL 0
using namespace std;
template<typename T>class Vector
{
T* Data;
void Swap(int pos1, int pos2)
{
if ( pos1 < Size && pos2 < Size )
{
T temp = Data[pos1];
Data[pos1] = Data[pos2];
Data[pos2] = temp;
}
else
throw "ERROR::VECTOR::SWAP invalid index";
}
public:
int Size;
Vector()
{
Size = 0;
Data = NULL;
}
~Vector()
{
delete Data;
Data = NULL;
Size = 0;
}
T operator [] (int index)
{
if ( index < Size )
return Data[index];
else
throw "ERROR::VECTOR::[] invalid index";
}
void Insert(T data)
{
T* NewData = new T[Size + 1];
for ( int i = 0; i < Size; i++ )
{
NewData = Data;
}
NewData[Size] = data;
Data = NewData;
Size++;
}
//sorts descending for UpDown = 0 and ascending otherwise
void Sort(int DownUp = 0)
{
if ( DownUp == 0 )
{
for ( int i = 0; i < Size; i++ )
{
for ( int j = i + 1; j < Size; j++ )
{
if ( Data > Data[j] )
{
Swap(i,j);
}
}
}
}
else
{
for ( int i = 0; i < Size; i++ )
{
for ( int j = i + 1; j < Size; j++ )
{
if ( Data < Data[j] )
{
Swap(i,j);
}
}
}
}
}
};
void main()
{
Vector<int> MyVector;
int temp;
try
{
for ( int i = 0; i < 10; i++ )
{
cout << "Enter number " << i << ": ";
cin >> temp;
MyVector.Insert(temp);
}
MyVector.Sort();
cout << endl;
for ( int i = 0; i < MyVector.Size; i++ )
{
cout << MyVector << endl;
}
}
catch( char* ex )
{
cout << ex << endl;
}
}
-
#include<iostream>
#include<string>
using namespace std;
template<typename T> class Complex
{
public:
Complex(T real, T imaginary)
{
Real = real;
Imaginary = imaginary;
};
~Complex()
{
};
friend ostream& operator << (ostream& os, const Complex& object)
{
os << object.Real << " + " << object.Imaginary << "i";
return os;
};
Complex operator + (Complex& op2)
{
return Complex(Real + op2.Real, Imaginary + op2.Imaginary);
};
Complex operator - (Complex& op2)
{
return Complex(Real - op2.Real, Imaginary - op2.Imaginary);
};
T Real, Imaginary;
};
void main()
{
Complex<double> MyComplex(10.0, 20.0);
Complex<double> MyComplex2(10.0, 20.0);
cout << MyComplex - MyComplex2 << endl;
}
-
#include<iostream>
#include<string>
using namespace std;
class PhoneNumber
{
bool Parse()
{
string numbers = "1234567890x";
string temp = "";
for ( int i = 0; i < Full.length(); i++ )
{
for ( int j = 0; j < numbers.length(); j++ )
{
if ( Full == numbers[j] )
{
temp += Full;
j = -1;
i++;
if ( i == Full.length() )
break;
}
}
}
Full = temp;
int xLoc = Full.find('x');
int acLoc = 0;
switch ( xLoc )
{
case 10:
acLoc = 3;
break;
case 7:
acLoc = 0;
break;
case -1:
xLoc = Full.length();
acLoc = 3;
if ( Full.length() == 7 )
acLoc = 0;
else if ( Full.length() == 10 )
acLoc = 3;
else
{
cout << "too long" << endl;
return false;
}
break;
default:
cout << "something else" << endl;
return false;
}
for ( int i = 0; i < Full.length(); i++ )
{
if ( i < acLoc )
AreaCode += Full;
else if ( i < xLoc )
{
Number += Full;
if ( Number.length() == 3 )
Number += '-';
}
else if ( i != xLoc )
Extension += Full;
}
return true;
}
public:
string Full, AreaCode, Number, Extension;
PhoneNumber()
{
Full = "";
AreaCode = "";
Number = "";
Extension = "";
}
PhoneNumber(string buffer)
{
Full = buffer;
AreaCode = "";
Number = "";
Extension = "";
}
bool IsValid()
{
return Parse();
}
};
void main()
{
PhoneNumber MyNumber;
string input;
cin >> input;
MyNumber.Full = input;
cout << MyNumber.IsValid() << endl;
cout << "(" << MyNumber.AreaCode << ")" << " " << MyNumber.Number << "x" << MyNumber.Extension << endl;
cout << MyNumber.Full << endl;
}
-
you never fail to amaze :P
it looks pretty from my java and vb background, and i understand a good bit of it, but ur silly :P
-
No wonder you got a C+! You can't even read it! :)
-
I think you just gave my computer AIDS
-
NOO WHY IS THIS NOT IN TEH BOX!?!?!?!?!
-
What is this gibberish?
-
NOO IT NEEDS TO BE IN TEH BOX!!!