Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CONSOLE_PLAYGROUND.CPP(MAIN)--
- #include "pch.h"
- #include <iostream>
- #include "USEFUL_FUNCTIONS.h"
- using namespace std;
- int main()
- {
- /* Testing out the functions created in the separate cpp file with the help of
- the header file in the visual studio project */
- //compare_two_values()
- cout << compare_two_values(20, 20) << endl; //Returns 1 if the numbers are the same
- //getLengthOfString()
- string x = "Hello there";
- cout << getLengthOfString(x) << endl;
- //sortIntegerArray()
- int myArray[5] = { 5, 3, 9, 4, 1 };
- sortIntegerArray(myArray, 5);
- int pause; cin >> pause; //Pause the program
- return 0;
- }
- --USEFUL_FUNCTIONS.H--
- #pragma once
- using namespace std;
- int compare_two_values(int number_one, int number_two);
- int getLengthOfString(string unknown_string_length);
- void sortIntegerArray(int unsorted_array[], int length);
- --USEFUL_FUNCTIONS_DEFINITIONS.CPP--
- #include "pch.h"
- #include <iostream>
- #include "USEFUL_FUNCTIONS.h"
- using namespace std;
- //Below are some simple functions definitions
- int compare_two_values(int number_one, int number_two)
- {
- if (number_one > number_two)
- return number_one;
- else if (number_two > number_one)
- return number_two;
- else
- return 1;
- }
- int getLengthOfString(string unknown_string_length)
- {
- int x = 0;
- for (char character_iterator = ' '; character_iterator != '\0'; x++)
- {
- character_iterator = unknown_string_length[x];
- }
- return x - 1;
- }
- void sortIntegerArray(int (unsorted_array[]), int length)
- {
- int temp;
- for (int y = 0; y < length - 1; y++)
- {
- for (int x = (y + 1); x < length; x++)
- {
- if (unsorted_array[y] >= unsorted_array[x])
- {
- temp = unsorted_array[y];
- unsorted_array[y] = unsorted_array[x];
- unsorted_array[x] = temp;
- }
- }
- }
- for (int k = 0; k < length; k++)
- {
- cout << unsorted_array[k] << " ";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement