An Example of Control Structures Windowbased application Control

An Example of Control Structures • • Window-based application Control structures (selection and repetition) Graphics Read integers from a file Classes Event handling Others

Create a form application using Visual C++ • Step 0: //Create a Windows Forms application in Visual Studio 2012 – Create an empty Form 1 following class web “Useful Links” on “how-touse …” , http: //cs 351. cs. ua. edu/F 2013/VS 2012. htm – do not add stuffs to the empty Form 1 – change Form 1’s Text to “CS 351”: with the “Form 1. h[Design]” active, open the “Properties” window, change the existing “Form 1” to “CS 351” – Add (copy-paste) code from main. cpp to Form 1. cpp by first clicking the Form 1. cpp from the “Solution Explorer” window to open it; then modifying the namespace to be your project name; – Build and run, make sure it works

Cont’d I • There are two approaches to try to work out the rest of the sample code, – Approach 1 is a direct copy-paste, – Approach 2 takes each step in class. • Step 1, Approach 1: – Copy the sample code to the Form 1. h (double click Form 1 in the [Design], modify the namespace to your project name. – Or, copy the sample code file Form 1. h to the project directory (replace the existing file); modify the namespace to your project name. – Prepare a text file control. txt with an integer in it. – Build and run – Change the integer in control. txt, run again.

Cont’d I • Step 1, Approach 2: // read the sample code to help – Open Form 1. h , by double clicking Form 1 in the [Design] view – Add int choice; to the Form 1 class, – Add the code to read an integer from the control. txt file in the Form 1’s constructor; add, close to the beginning, to use the System: : IO name space. – Add the Form 1_Paint event handler to the Form 1 class: • Go to the [Design] view of Form 1, then to the “Properties” window, • Right on top, click the icon look like a lightning bolt (the cursor shows “Events”) • Find “Paint”, double click (the needed code of the handler function is created , doing nothing) – Copy the body of this function from the part of the sample code (for-loops etc) within the same handler function name. – Prepare a text file control. txt with an integer in it – Build and run – Change the integer in control. txt, run again.

First Assignment • Control structures (selection and repetition) • Graphics • Tips: code relating to Graphics is all given in sample code; the focus is to figure out the Control Structures to use the draw functions.

Math Functions • There is a class called System: : Math • double radian=Math: : PI/180. 0; • double y=Math: : Sin(x);
- Slides: 6