Problem: Take Two Numbers, Add Them Together And Display The Results. Now To Build The Flowchart… We Probably Need One Like This… Let’s Add The Routines… Start Get Number 1 Get Number 2 Number 3 = Number 1 + Number 2 Display Number 3 Stop What Now??? Let’s Program Using It. Which Language Do You Want To Use? C++, Visual C++ Or Visual Basic? Let’s Start With C++
Let’s Put The Chart Up For A Reference. Now We Begin With A Comment Line. // Program Name: Test.cpp Then We Include A Reference To The iostream File. #include Now We Setup Our Main Routine. void main( ) { Then Define Our Integers. int test1; int test2; int test3; Get Input From User And Store It In Integers. cout << “Enter number 1:”; cin >> test1; cout << “\n”; cout << “Enter number 2:”; cin >> test2; We Add Them Together. test3 = test1 + test2; And Print The Results. cout << “The total is: \n”; cout << test3; cout << “\n”; } Compile And Run The Program.
Program It In…
Select MFC AppWizard(exe) First Open Visual C++ Type In A File Name
Select Dialog Based And Press Next
Press Next, We Are Going To Use The Defaults On This Screen.
Press Next, Again We Will Use The Defaults.
Now We Can Press Finished. The Wizard Will Build Our Program.
After The Wizard Is Finished, We Get This. We Can’t Use It Like It Is, We Need To Make Changes. Delete This First. Then Move Our Buttons Down To About Here. Add Three Edit Boxes About Here. You Get The Edit Boxes From Your Tool Box
Right Click On The Buttons To Change Properties. Change ID To IDADD and Caption To ADD. This Is A Reference Name To The Control In Your Program.. This Is The Displayed Caption. Change The Cancel Button To Exit.
It Should Look Like This Now. Now We Program The Code. Select The Exit Button. Right Click On The Exit Button And Select ClassWizard
Select IDCANCEL BNCLICKED ADD Function When This Box Shows, Press OK Then Press Edit Code
A Section Of Code Will Appear. Add OnOK(); Type It Exactly As Shown. C++ Is Case Sensitive. Now Our Exit Button Works…
To Define Our Variables, Select ClassWizard Again. Press The Second Tab. Select Edit1. Now Press Add Variables
Type In m_Test1 Change This To Int. We Are Using Integers. Press OK Do The Same Thing On Edit2 And Edit3, But Rename The Variables To m_Test2 And m_Test3 To Match The Edit Boxes.
Select ClassWizard Again. Select IDADD BN_CLICKED Press Edit Code We Are Going To Put In Our ADD Routine.
Type In Exactly As Shown… UpdateData(TRUE); m_Test3 = m_Test1 + m_Test2; UpdateData(FALSE); Congratulations… Our Program Is Now Finished. Compile And Run The Program.
From A Flowchart... To A Working Program.
Program It In…
Start Visual Basic And Select Standard EXE. Then Press Open
A Blank Form Box Will Appear. Add Three Text Boxes From The ToolBox On To The Form. Add Two Buttons From The ToolBox On To The Form.
Select Command1 Button. Under The Caption Properties, Change To ADD. Change Command2 Caption Property To Exit.
Select Text1 Clear The Text Property So The Text Box Will Be Clear. Do The Same For Text2 And Text3
Double Click On The Exit Button And Insert The Following Code… Unload Me
Double Click On The Add Button And Add The Following Code... Text3.Text = val(Text1.Text) + val(Text2.Text) The Program Is Now Finished
From A Flowchart… To A Working Program.