13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.130 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 0 1 100001 0 1 0 1 1 0 1 0 00 0 1 1 1 0 1 100001 0 1 1 100001 13:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.1313:05 ET Dow -154.48 at 10309.92, Nasdaq -37.61 at 2138.44, S&P -19.13

.

.

Sunday, March 13, 2011

#2 - Use of a Vector class in C++ : Also, demonstration of Switch, Goto, Cin, Cout, Print, etc - In Progress




#include <iostream>
using namespace std;
#include "Vector.txt"

template <class T>
void Swap(T &a, T &b)
{
T temp = a;
a = b;
b = temp;

}

int main()
{

// which type of object for vector: int, double, float
int typeV;
std::cout << "What type of Vector do you want to act on?" << endl;
cin >> typeV;
switch (typeV)
{
case 1 :
{
Vector<int> Vint(0);
bool added = false;
do
{

int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
cin >> another;
int toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
cin >> toAdd;
Vint.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vint);
// Now Sort it, then prit it
int length = Vint.size();
for(int i=0; i < length; i++)
{
if(Vint[i-1]>Vint[i])
Swap<int>(Vint[i-1],Vint[i]);
}
printList(Vint);
goto pass;
}
case 2 :
{
Vector<double> Vdouble(0);
bool added = false;
do
{

int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
cin >> another;
double toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
std::cin >> toAdd;
Vdouble.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vdouble);
goto pass;
}
case 3 :
{
Vector<float> Vfloat(0);
bool added = false;
do
{

int another;
std::cout << "Do you want to enter a number? Type '0' for 'N' and '1' for 'Y'" << endl;
std::cin >> another;
float toAdd;
if (another ==1)
{std::cout << "Enter an integer and press enter." << endl;
cin >> toAdd;
Vfloat.push_back(toAdd);
added = true;
}
else
added = false;
}
while(added==true);
printList(Vfloat);
goto pass;
}

pass:




Vector<int> V1(0);
for (int i = 0; i < 10; i++)
V1.push_back(i);
printList(V1);

V1.reserve(20);
for (int i = 10; i <20; i++)
V1.push_back(i);
printList(V1);
cout << endl;

Vector<float> V2(0);
for (int i = 0; i < 10; i++)
V2.push_back((float)i + .1f);
printList(V2);
system("PAUSE");
return 0;
}
}