Intermixing C++ With Pro-SiMPLE
SiMPLE lets you write programs and tasks that contain C++ statements intermixed with SiMPLE statements. When writing such a "hybrid" program, there are three principal rules you must remember:
Pro-SiMPLE
Common Int patrn[]={7, 2, 8}
Common Int color[]={2, 4, 9}
graphon; dx=25
+Circle (320-dx_, 240, 50);
circle (320+dx, 240, 50)
+for (int i=-1; i<2; i++)
+{
+ setfillstyle (patrn_[i+1], color_[i+1]);
+ floodfill (320+i*(dx_+49), 240, 15);
+}
tabxy (34, 11)
+cout << "Filled Circles" << endl;
Notice the two different ways in which we chose to invoke SiMPLE's Circle task. In line 5 of the program we invoked it the usual way (by using a SiMPLE statement), while in line 4 we invoked it by using a C++ statement (just to be different, and hence the necessity of using an upper case "C" in the name "Circle").
When you run the program, the following image is generated:
Including User-defined C++ Functions
The previous discussion assumed that your hybrid program consisted of only a main program. However, there may be times when you also want to define your own C++ functions along with your main program. When doing so, there is one more additional rule you must remember:
As an example of how to include a user-defined C++ function, let's write a hybrid program that invokes a user-defined mytask function:
Pro-SiMPLE
//The first statement must NOT be C++.
Int null //Therefore this is just a do-nothing.
+void mytask (Text); //function declaration
//Task main
param = "Hello, World"
+mytask (param_);
Pause
Cls; Quit
End main //MUST be included here!
+void mytask (Text string)
+{
+ cout << string.get_str() << endl;
+}
Notice that, even though we must use an End statement to indicate the end of the main program, we do not use a Task main statement to indicate the start of the program. (SiMPLE generates one for you automatically.)
[
Webmaster |
FAQ's |
Home Page |
Contact Us ]