KARBYTES_JOURNAL_2023_ENTRY_216


KARBYTES_JOURNAL_2023_ENTRY_216


Today I used the OpenAI chatbot Playground web interface by entering text into a text field and clicking a submit button after typing in plain-text input. AI-generated plain text output is generated within seconds of me pressing the submit button. What follows is a transcript of one of my first ten “conversations” with the chatbot (a web page interface which implements the ChatGPT API service).

The following dialogue involves karbytes submitting an instruction to write a C++ program which generates an array of one hundred random integers (which are each no smaller than 0 and no larger than 99), sorts that array using the bubble sort algorithm, and then prints those array values to the command line. After the AI output the C++ code, karbytes copied and pasted that code into a blank document in a text editor and saved that document as openai_karbytes_bubble_sort_test.cpp. Then karbytes compiled and executed that C++ code and copy and pasted that program output (which was copied from the text output generated by an online C/C++ compiler service named OnlineGDB to the bottom of this web page main content section).

Note that the green highlighted text was generated by the artificial intelligence which karbytes was interacting with and not by karbytes. Note that karbytes inserted space characters between the angle bracket characters which enclose C++ library names (so that the WordPress web page server would not misinterpret those C++ preprocessing directives as HTML web page source code tags).


preset_web_page: https://platform.openai.com/playground/p/qGiyK7pkcBJAP7s9TiToegWZ

preset_name: openai_karbytes_bubble_sort_test

* * *

Write a C++ program which (a) instantiates an int array of 100 elements named A, (b) sets each element of A to some random nonnegative integer less than 100, (c) prints the array values to the command line, (d) uses bubble sort to arrange that array such that its elements are listed in ascending order (i.e. where A[0] is the smallest value and A[99] is the largest value), and (e) prints the sorted array values to the command line.

#include < iostream >
#include < cstdlib >
#include < ctime >

using namespace std;

int main()
{
    // Instantiate an int array of 100 elements named A
    int A[100];

    // Set each element of A to some random nonnegative integer less than 100
    srand(time(NULL));
    for (int i = 0; i < 100; i++)
    {
        A[i] = rand() % 100;
    }

    // Print the array values to the command line
    cout << "Unsorted array values:" << endl;
    for (int i = 0; i < 100; i++)
    {
        cout << A[i] << " ";
    }
    cout << endl;

    // Use bubble sort to arrange that array such that its elements are listed in ascending order
    int temp;
    for (int i = 0; i < 99; i++)
    {
        for (int j = 0; j < 99 - i; j++)
        {
            if (A[j] > A[j + 1])
            {
                temp = A[j];
                A[j] = A[j + 1];
                A[j + 1] = temp;
            }
        }
    }

    // Print the sorted array values to the command line
    cout << "Sorted array values:" << endl;
    for (int i = 0; i < 100; i++)
    {
        cout << A[i] << " ";
    }
    cout << endl;

    return 0;
}

program_output:

Unsorted array values:
17 66 94 59 1 91 87 96 64 95 47 29 51 52 93 83 58 90 48 15 38 1 74 78 31 19 94 45 86 76 87 4 94 81 63 96 25 2 44 89 98 91 70 1 95 63 85 54 6 85 69 96 87 95 27 70 14 21 15 53 50 54 57 44 88 72 92 13 75 37 54 25 80 24 26 76 40 63 30 46 49 51 94 36 47 21 58 13 95 74 66 45 28 75 41 68 48 34 81 75 
Sorted array values:
1 1 1 2 4 6 13 13 14 15 15 17 19 21 21 24 25 25 26 27 28 29 30 31 34 36 37 38 40 41 44 44 45 45 46 47 47 48 48 49 50 51 51 52 53 54 54 54 57 58 58 59 63 63 63 64 66 66 68 69 70 70 72 74 74 75 75 75 76 76 78 80 81 81 83 85 85 86 87 87 87 88 89 90 91 91 92 93 94 94 94 94 95 95 95 95 96 96 96 98

This web page was last updated on 28_MARCH_2023. The content displayed on this web page is licensed as PUBLIC_DOMAIN intellectual property.