Flowchart.ppt

Download Report

Transcript Flowchart.ppt

What Now???
Problem:
Take Two Numbers,
Add Them Together
And Display The Results.
Now To Build
The Flowchart…
We Probably
Need One Like This…
Let’s Program Using
It. Which Language
Do You Want To
Use?
C++, Visual C++
Or Visual Basic?
Start
Get Number 1
Get Number 2
Number 3 =
Number 1 +
Number 2
Let’s Start With C++
Display
Number 3
Let’s Add The
Routines…
Stop
// Program Name: Test.cpp
#include <iostream.h>
void main( )
{
int test1;
int test2;
int test3;
Let’s
Put
The
Chart
Now
We
Setup
WeFor
Add
Up
A Reference.
Our
Main
Routine.
Them Together.
Now
We
BeginOur
Then
Define
And A
Print
With
Comment
Integers.
The Results.
Line.
Get Input
From
Then
We Include
Compile
User
AndThe
Store
AAnd
Reference
To
Run
It Iniostream
Integers.File.
The
Program.
cout << “Enter number 1:”;
cin >> test1;
cout << “\n”;
cout << “Enter number 2:”;
cin >> test2;
test3 = test1 + test2;
cout << “The total is: \n”;
cout << test3;
cout << “\n”;
}
Program It In…
First Open
Visual C++
Select
MFC AppWizard(exe)
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.
Delete
This
First.
After
The
Wizard
Is Finished, We Get
Then Move Our
This.
Buttons Down To
About
Here.
We
Can’t
Use It
Like It Is, We Need
Add
Three
Edit
To
Make
Changes.
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.
Change The Cancel
Button To Exit.
This Is A Reference Name To The
Control In Your Program..
This Is The Displayed Caption.
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.