Category Archives: Code samples

Get highest number in a Java array.

/** * Checks for the highest int in an int array. * http://www.victorbyte.net/ * Returns int value */ public static int getMaxInArray(int[] array) { int max = array[0]; for(int i: array) max = max > i ? max : i; … Continue reading

Posted in Code samples | Tagged | Leave a comment

Lower case to upper case

#include using std::cout;using std::endl;#include using std::tolower;using std::toupper;#include using std::vector;void convertToUp(vector &a);void print(vector a);int main(){ char cArray[] = “characters and $32.98″; vector vArray; for(int i = 0; (cArray[i] != ”);i++) { vArray.push_back(cArray[i]); } print(vArray); convertToUp(vArray); print(vArray); system(“PAUSE”); return 0;}void convertToUp(vector &a){ … Continue reading

Posted in C++ | Leave a comment

Array sort

inline void arraySort(int intArray[], int size ){ for(int i = 1; i < size; i++) { cout

Posted in C++ | Leave a comment

Array linear search

void arraySearch(int a[], int size, int search){char result = ”;for(int i = 0; i < size; i++){if(a[i] == search){cout

Posted in C++ | Leave a comment

Enum

keyword enum is a set of integer constants represented by identifiers.

Posted in C++ | Leave a comment

Random number generation.

#include <cstdlib> using std::rand; using std::srand; #include <ctime> using std::time; int main() { srand(time(0)); return 0; }

Posted in C++, Code samples | Leave a comment

C++ Standard Library header ?le

<i ostream> Contains function prototypes for the C++ standard input and standard output functions, introduced in Chapter 2, and is covered in more detail in Chapter 15, Stream Input/Output. This header ?le replaces header ?le <i ostream.h>. <i omani p> … Continue reading

Posted in C++ | Leave a comment

cmath

cei l ( x ) rounds x to the smallest integer not less than x cei l ( 9. 2 ) is 10. 0 cei l ( -9. 8 ) is -9. 0 cos( x ) trigonometric cosine of x … Continue reading

Posted in C++ | Leave a comment

UserInput cin

getline(cin, string variable); //Gets the whole line until enter is pressed.cin >> typevariable //Reads characters until space cin.get() //Reads a character

Posted in C++ | Leave a comment

Casting int to double : Cplusplus C++

#include <iomanip>;double average;int total;int counter;average = static_cast< double >( total ) / counter;

Posted in C++ | Leave a comment