Bubble Sort Program

Posted: July 22, 2011 in Uncategorized

Here is a program that demostrates a bubble sort:

 

#include <iostream>


using namespace std;

void printArray(int *array, int length);
void bubbleSort(int *array, int length);

int main()
{
  int array[] = {9,6,5,23,2,6,2,7,1,8};
  bubbleSort(array, 10);
  printArray(array, 10);
}

void printArray(int *array, int length)
{
  int i = 0;
  for(i =0; i < length; i++)
    cout << array[i] << endl;
}

void bubbleSort(int *array, int length)
{
  int i, j;
  for(i = 0; i < length; i++)
    {
      for(j = 0; j < i; j++)
	{
	  if(array[i] > array[j])
	    {
	      int temp = array[i];
	      array[i] = array[j];
	      array[j] = temp;
	    }
	}
    }
}

Questions

Posted: July 16, 2011 in Uncategorized

If there are any functions or algorithms you would like to see here…either comment or send us an email.

Simple I/O Example

Posted: November 13, 2010 in Uncategorized

Here is a program to output a text file out one word per line.  NOTE:   you must put your text file in the same directory as your .cpp files for this to work.

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main(void)
{
string fileName;
string wordBuffer;
ifstream file;

cout << “Please enter the file name to read: ” << endl;
cin >> fileName;

cout << “Start of file” << endl;

file.open(fileName.c_str());
if(! file.is_open()) {
cerr << “Error opening file: ” << fileName << endl;
exit(1);
}

while(! file.eof() )
{
file >> wordBuffer;
cout << wordBuffer << endl;
}

cout << “End of file” << endl;

system(“pause”);

return 0;

}

Recursive Sum Example

Posted: November 1, 2010 in Uncategorized

Here is a recursive function that takes a number inputted by the user and find the sum of all numbers from 1 to that number:

#include <iostream>
using namespace std;

int recursion(int num);

int main(){

int num = 0;
int sumNum;

cout << “Enter any integer greater than 0: ” << endl;
cin >> num;

sumNum = recursion(num);
cout << “The sum is: ” << sumNum << endl;
cin.ignore();
cin.get();

return 0;
}

int recursion(int num)
{
int sum = 0;
if(num == 1){
return 1;
}
else{
sum = recursion(num-1) + num;
return sum;
}

}

Happy coding!

Hello World Code

Posted: October 31, 2010 in Uncategorized

How’s it going.  I figured with the introduction of our blog…I’d throw in some simple code for the coveted “Hello World Program“:

#include <iostream>
using namespace std;
int main(void){
 cout << "Hello World" << endl;
 return 0;
}

If anyone wants to throw down the java, C#, perl, or any other languages code for a simple Hello World please feel free!

Welcome to the Beginner Developer’s Blog.  This is a blog where we will share programming types, code, and tutorials with those who are just starting out in programming.

I had a rough time with some of my professors when first in college so I thought I would create something that allowed other people to get going quickly.  Many of the tricks in programming has to be shown to you (unless your some kind of genius) and it sucks when professors or whomever doesn’t wanna share the knowledge.

So stay tuned I will throw up some links and possible some youTube vids soon.

Please subscribe and share with everyone!