In order to have a text field, you need a GUI. GUI is not an inherent part of C++, so you have to use some of the GUI frameworks like Qt. Theoretically, you can do it with WinAPI only, but it would be painful I suppose. In my sample I take input number from console.
Regarding calling batch and passing arguments, it is simple. Just call process cmd.exe /C {yourbatch}.bat {parameters}
. Note that you can pass input data to batch as command line parameters (also, you can use environment variables). In order to start exe-file, you can use CreateProcess function of WinAPI (I have taken sample from this answer)
Getting output is a bit harder. One of the ways is to capture console output stream of your batch with a pipe. Something like this... However, it is much easier to simply use files to pass any data.
Sample C++:
#include <stdio.h>
#include <windows.h>
int main() {
int n;
scanf("%d", &n); //read integer n from console
int *arr = new int[n]; //create array of 1..n integers
for (int i = 0; i < n; i++)
arr[i] = i + 1;
char cmd[1024] = "cmd.exe /C script.bat"; //base command line
for (int i = 0; i < n; i++) //add array elements as console parameters
sprintf(cmd, "%s %d", cmd, i);
STARTUPINFO info = {sizeof(info)}; //create cmd.exe process
PROCESS_INFORMATION processInfo;
if (CreateProcess(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo)) {
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess); //note that we wait for completition
CloseHandle(processInfo.hThread);
}
int sum;
FILE *f = fopen("sum.txt", "r"); //read sum from 'sum.txt'
fscanf(f, "%d", &sum);
fclose(f);
printf("Sum of 1..%d is %d\n", n, sum); //print the sum
return 0;
}
Sample Batch (must be named script.bat in working directory):
del sum.txt
set sum=0
for %%x in (%*) do ( //sum all the parameters
set /A sum+=%%~x
)
echo %sum% >sum.txt //write result to sum.txt