(+)Addition
(-)Subtraction
(/)Division
(*)Multiplication
The following steps demonstrate these operators at work:
1. Start MSVC++ Express 2008 by clicking on the Start button, All Programs then clicking on the Microsoft Visual C++ Express Edition Start menu option.
2. Click File>New>Project. The new project dialog box will then come into view.
3. Select Windows Forms Application from the Visual Studio Installed templates, type the project name>Click Ok.
After clicking the Ok button, an IDE suited for windows forms application will then appear containing a form, a toolbox window, and a properties window.
4. Create a user interface similar to the one below:
Note: Those texts that appear beside each control are the suggested names for our form controls in this example. If you noticed I am using .Net naming convention in naming controls because it is simpler to use than Leszynski naming convention. To change the value of the name property of each control, just click each individual control then locate the name property in the properties window then assign those descriptive names in our illustration correspondingly.
5. Double-click your form then locate the following line:
#pragma endregion6. Declare the following variables below it:
int intnum1, intnum2, intans;Declaring these variables below the #pragma endregion line allows our variables to be available publicly and to be used by other procedures.
Your code should now appear just like this:
#pragma endregion int intnum1, intnum2,intans;
7. Double-click the control named TimesButton,type the following:
intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 * intnum2; this->OperatorLabel->Text="*"; this->AnsLabel->Text=Convert::ToString(intans);
Your code should now appear just like this:
private: System::Void TimesButton_Click(System::Object^ sender, System::EventArgs^ e) { intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 * intnum2; this->OperatorLabel->Text="*"; this->AnsLabel->Text=Convert::ToString(intans); }
8. Double-click the control named DivButton,type the following:
intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 / intnum2; this->OperatorLabel->Text="/"; this->AnsLabel->Text=Convert::ToString(intans);
Your code should now appear just like this:
private: System::Void DivButton_Click(System::Object^ sender, System::EventArgs^ e) { intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 / intnum2; this->OperatorLabel->Text="/"; this->AnsLabel->Text=Convert::ToString(intans); }
9. Double-click the control named AddButton,type the following:
intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 + intnum2; this->OperatorLabel->Text="+"; this->AnsLabel->Text=Convert::ToString(intans);
Your code should now appear just like this:
private: System::Void AddButton_Click(System::Object^ sender, System::EventArgs^ e) { intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 + intnum2; this->OperatorLabel->Text="+"; this->AnsLabel->Text=Convert::ToString(intans); }
10. Double-click the control named DiffButton,type the following:
intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 - intnum2; this->OperatorLabel->Text="-"; this->AnsLabel->Text=Convert::ToString(intans);
Your code should now appear just like this:
private: System::Void DiffButton_Click(System::Object^ sender, System::EventArgs^ e) { intnum1=int::Parse(this->FnumTextBox->Text); intnum2=int::Parse(this->SnumTextBox->Text); intans=intnum1 - intnum2; this->OperatorLabel->Text="-"; this->AnsLabel->Text=Convert::ToString(intans); }
11. Double-click the control named ClearButton,type the following:
this->FnumTextBox->Text=""; this->SnumTextBox->Text=""; this->OperatorLabel->Text=""; this->AnsLabel->Text="";
Your code will now look like this:
private: System::Void ClearButton_Click(System::Object^ sender, System::EventArgs^ e) { this->FnumTextBox->Text=""; this->SnumTextBox->Text=""; this->OperatorLabel->Text=""; this->AnsLabel->Text=""; }
12.Double-click ExitButton, then type this->Close:
private: System::Void ExitButton_Click(System::Object^ sender, System::EventArgs^ e) { this->Close(); }13. Press F5 to execute your application. I will add comments to the codes above when I have time. Till then:)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.