Advertisement
Felanpro

Header Files Experimenting

Mar 22nd, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. --CONSOLE_PLAYGROUND.CPP(MAIN)--
  2. #include "pch.h"
  3. #include <iostream>
  4. #include "USEFUL_FUNCTIONS.h"
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     /* Testing out the functions created in the separate cpp file with the help of
  11.     the header file in the visual studio project */
  12.  
  13.     //compare_two_values()
  14.     cout << compare_two_values(20, 20) << endl; //Returns 1 if the numbers are the same
  15.  
  16.     //getLengthOfString()
  17.     string x = "Hello there";
  18.     cout << getLengthOfString(x) << endl;
  19.  
  20.     //sortIntegerArray()
  21.     int myArray[5] = { 5, 3, 9, 4, 1 };
  22.     sortIntegerArray(myArray, 5);
  23.  
  24.     int pause; cin >> pause; //Pause the program
  25.     return 0;
  26. }
  27.  
  28. --USEFUL_FUNCTIONS.H--
  29. #pragma once
  30.  
  31. using namespace std;
  32.  
  33. int compare_two_values(int number_one, int number_two);
  34. int getLengthOfString(string unknown_string_length);
  35. void sortIntegerArray(int unsorted_array[], int length);
  36.  
  37. --USEFUL_FUNCTIONS_DEFINITIONS.CPP--
  38. #include "pch.h"
  39. #include <iostream>
  40. #include "USEFUL_FUNCTIONS.h"
  41.  
  42. using namespace std;
  43.  
  44. //Below are some simple functions definitions
  45.  
  46. int compare_two_values(int number_one, int number_two)
  47. {
  48.     if (number_one > number_two)
  49.         return number_one;
  50.     else if (number_two > number_one)
  51.         return number_two;
  52.     else
  53.         return 1;
  54. }
  55.  
  56. int getLengthOfString(string unknown_string_length)
  57. {
  58.     int x = 0;
  59.  
  60.     for (char character_iterator = ' '; character_iterator != '\0'; x++)
  61.     {
  62.         character_iterator = unknown_string_length[x];
  63.     }
  64.  
  65.     return x - 1;
  66. }
  67.  
  68. void sortIntegerArray(int (unsorted_array[]), int length)
  69. {
  70.     int temp;
  71.     for (int y = 0; y < length - 1; y++)
  72.     {
  73.         for (int x = (y + 1); x < length; x++)
  74.         {
  75.             if (unsorted_array[y] >= unsorted_array[x])
  76.             {
  77.                 temp = unsorted_array[y];
  78.                 unsorted_array[y] = unsorted_array[x];
  79.                 unsorted_array[x] = temp;
  80.             }
  81.         }
  82.     }
  83.  
  84.     for (int k = 0; k < length; k++)
  85.     {
  86.         cout << unsorted_array[k] << " ";
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement