You are on page 1of 3

//Book to reference: C++ for Everyone by Cay Horstmann...

#include <iostream>
#include <string>
using namespace std;
//start
int main()
{
int VariableCans=6;
cout << "My variable is " << VariableCans << endl << endl;
VariableCans++;
cout << "My variable is now " << VariableCans << endl << "Type in your own: ";
int VariableCans;
cin >> VariableCans;
cout << endl << endl << "My variable is now " << VariableCans << endl << endl <<
"While Test" << endl;
while(VariableCans > 0)
{
cout << "My variable is now " << VariableCans << endl;
VariableCans--;
}
cout << endl << "Arrays:" << endl;
const int ARRAYSIZE = 5;
int ArrayCans[ARRAYSIZE] = { 32, 54, 67, 98, 102 };
for(int ArrayIndex = 0; ArrayIndex < ARRAYSIZE; ArrayIndex++)
{
cout << ArrayCans[ArrayIndex] << endl;
}
cout << endl << "Vectors: Type your vector size..." << endl;
int VectorArraySize;
cin >> VectorArraySize;
vector<int> VectorArray(VectorArraySize);
int VectorArrayIndex = 0;
while(VectorArrayIndex < VectorArraySize)
{
VectorArray[VectorArrayIndex] = (rand() % 6)+1; //random number between 1 and 6
cout << VectorArray[VectorArrayIndex] << endl;
VectorArrayIndex+=1;
}
cout << endl << "Input pushback number" << endl;
int Pushback;
cin >> Pushback;
VectorArrayIndex = 0;
while(VectorArrayIndex < VectorArraySize)
{
cout << VectorArray[VectorArrayIndex];
VectorArrayIndex+=1;
}
VectorArrayIndex = 0;
while(VectorArrayIndex < Pushback)
{
VectorArray.push_back(rand() % 6)+1;
cout << VectorArray[VectorArrayIndex + VectorArraySize] << endl;
Pushback+=1;
}
cout << endl << "Input popback number" << endl;
int Popback;
cin >> Popback;
VectorArrayIndex = 0;
while(VectorArrayIndex < Popback)
{
VectorArray.pop_back();
VectorArrayIndex+=1;
}
VectorArrayIndex = 0;
while(VectorArrayIndex < VectorArray.size())
{
cout << VectorArray[VectorArrayIndex] << endl;
VectorArrayIndex++;
}
cout << endl << "Cool, bra. Now type in a position to swap..." << endl;
int FirstSwap;
cin >> FirstSwap;
cout << "Cool, cool. Now a second position..." << endl;
int SecondSwap;
cin >> SecondSwap;
cout << "Cool, swapsing..." << endl;
VectorArray.swap(FirstSwap, SecondSwap);
VectorArrayIndex = 0;
while(VectorArrayIndex < VectorArray.size())
{
cout << VectorArray[VectorArrayIndex] << endl;
VectorArrayIndex += 1;
}
cout << endl << "Now then, sorting..."
sort(VectorArray.begin(), VectorArray.end());
while(VectorArrayIndex < VectorArray.size())
{
cout << VectorArray[VectorArrayIndex] << endl;
VectorArrayIndex += 1;
}
cout << endl << "Pointers..." << endl;
int PointerLoc1 = 10;
int PointerLoc2 = 20;
int* Pointer = &PointerLoc1;
cout << "Pointer is " << *Pointer << "!!!!111" << endl;
Pointer = &PointerLoc2; //sets the pointer's address to the addres of the second
location
cout << "Pointer at second address is " << *Pointer << "!!!!!11" << endl;
cout << endl << "Streams write and read files... look them up... Cool bra, done
for now." << endl;
}

You might also like