0% found this document useful (0 votes)
63 views7 pages

Rainere M Asaldo Bscs1A 1) Calculator Console Visual Basic: Imports Sub Dim As Integer

The document contains 4 code examples that create calculator programs using different programming languages and environments (Visual Basic console, C# console, Visual Basic GUI, C# GUI). Each example accepts numeric input from the user, performs basic mathematical operations (add, subtract, multiply, divide, remainder) on the numbers, and displays the results to the user.

Uploaded by

Rainere Asaldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views7 pages

Rainere M Asaldo Bscs1A 1) Calculator Console Visual Basic: Imports Sub Dim As Integer

The document contains 4 code examples that create calculator programs using different programming languages and environments (Visual Basic console, C# console, Visual Basic GUI, C# GUI). Each example accepts numeric input from the user, performs basic mathematical operations (add, subtract, multiply, divide, remainder) on the numbers, and displays the results to the user.

Uploaded by

Rainere Asaldo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Rainere M Asaldo BSCS1A

1) Calculator Console Visual Basic


Imports System

Module Module1

Sub Main()
Dim Sum, Dif, Prod, Quo, Rema, Num1, Num2 As Integer
Console.Write("Please Enter First Number: ")
Num1 = Console.ReadLine()
Console.Write("Please Enter Second Number: ")
Num2 = Console.ReadLine()
Sum = Num1 + Num2
Dif = Num1 - Num2
Prod = Num1 * Num2
Quo = Num1 / Num2
Rema = Num1 Mod Num2
Console.WriteLine("The Sum of " & Num1 & " + " & Num2 & " is " & Sum)
Console.WriteLine("The Difference of " & Num1 & " - " & Num2 & " is " & Dif)
Console.WriteLine("The Product of " & Num1 & " * " & Num2 & " is " & Prod)
Console.WriteLine("The Quotient of " & Num1 & " / " & Num2 & " is " & Quo)
Console.WriteLine("The Remainder of " & Num1 & " % " & Num2 & " is " & Rema)
Console.WriteLine("Press any key to continue...")
Console.ReadKey(True)
End Sub

End Module
2) Calculator Console C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CalcuCSharp
{
class Program
{
static void Main(string[] args)
{
int Num1, Num2, Sum, Dif, Mul, Div, Mol;
Console.Write("Please Enter First Number: ");
Num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Please Enter Second Number: ");
Num2 = Convert.ToInt32(Console.ReadLine());
Sum = Num1 + Num2;
Dif = Num1 - Num2;
Mul = Num1 * Num2;
Div = Num1 / Num2;
Mol = Num1 % Num2;
Console.WriteLine("The Sum of " + Num1 + " + " + Num2 + " is " + Sum);
Console.WriteLine("The Difference of " + Num1 + " - " + Num2 + " is " + Dif);
Console.WriteLine("The Product of " + Num1 + " * " + Num2 + " is " + Mul);
Console.WriteLine("The Quotient of " + Num1 + " / " + Num2 + " is " + Div);
Console.WriteLine("The Remainder of " + Num1 + " % " + Num2 + " is " + Mol);
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
}
}
}
3) Calculator Visual Basic
Public Class Form1

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click


End
End Sub

Private Sub btnSum_Click(sender As Object, e As EventArgs) Handles SumBtn.Click


Dim Sum As Integer
Sum = Val(TextFirst.Text) + Val(TextSecond.Text)
AnswerLabel.Text = "The sum is " & Str(Sum)
End Sub

Private Sub btnDif_Click(sender As Object, e As EventArgs) Handles DiffBtn.Click


Dim Dif As Integer
Dif = Val(TextFirst.Text) - Val(TextSecond.Text)
AnswerLabel.Text = "The difference is " & Str(Dif)
End Sub

Private Sub btnProd_Click(sender As Object, e As EventArgs) Handles ProdBtn.Click


Dim Prod As Integer
Prod = Val(TextFirst.Text) * Val(TextSecond.Text)
AnswerLabel.Text = "The product is " & Str(Prod)
End Sub

Private Sub btnQuo_Click(sender As Object, e As EventArgs) Handles QuoBtn.Click


Dim Quo As Integer
Quo = Val(TextFirst.Text) / Val(TextSecond.Text)
AnswerLabel.Text = "The quotient is " & Str(Quo)
End Sub

Private Sub btnRem_Click(sender As Object, e As EventArgs) Handles RemBtn.Click


Dim Rema As Integer
Rema = Val(TextFirst.Text) Mod Val(TextSecond.Text)
AnswerLabel.Text = "The remainder is " & Str(Rema)
End Sub

Private Sub Button6_Click(sender As Object, e As EventArgs) Handles ExitBtn.Click

End Sub
End Class
Add:

Subtract:
Product:

Quotient:
Remainder:

4) Calculator C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CalcuCSharpGUI
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnExit_Click(object sender, EventArgs e)


{
this.Close();
}

private void btnSum_Click(object sender, EventArgs e)


{
int Sum;
Sum = Convert.ToInt32(txtFN.Text) + Convert.ToInt32(txtSN.Text);
lblAns.Text = "The sum is " + Convert.ToString(Sum);
}

private void btnDif_Click(object sender, EventArgs e)


{
int Dif;
Dif = Convert.ToInt32(txtFN.Text) - Convert.ToInt32(txtSN.Text);
lblAns.Text = "The difference is " + Convert.ToString(Dif);
}

private void btnProd_Click(object sender, EventArgs e)


{
int Prod;
Prod = Convert.ToInt32(txtFN.Text) * Convert.ToInt32(txtSN.Text);
lblAns.Text = "The product is " + Convert.ToString(Prod);
}

private void btnQuo_Click(object sender, EventArgs e)


{
int Quo;
Quo = Convert.ToInt32(txtFN.Text) / Convert.ToInt32(txtSN.Text);
lblAns.Text = "The quotient is " + Convert.ToString(Quo);
}

private void btnRem_Click(object sender, EventArgs e)


{
int Rem;
Rem = Convert.ToInt32(txtFN.Text) % Convert.ToInt32(txtSN.Text);
lblAns.Text = "The remainder is " + Convert.ToString(Rem);
}
}
}

You might also like