Loading
View RSS Feed

Angad Kumar Shukla's blog

Dot Net Code: Write A Program To Implement Simple Calculator.

Rating: 6 votes, 2.83 average.
Code:
//Context:-To implement addition,subtraction,multiplication,division in a menu format
//Assumptions:-Nothing
//Contract:-"Add(int,int)->int,Sub(int,int)->int,Mul(int,int)->int,Div(int,int)->int"
//Example:-"Add(2,1)->3,Sub(2,1)->1,Mul(2,3)->6,Div(6,2)->3"
/*Psuedo Code:-Add(int,int)
                    return sum;
 *             Sub(int,int)
 *                  return difference;
 *             Mul(int,int)
 *                  return product;
 *             Div(int,int)
 *                  return division;*/
/*TEST CASES:-  INPUT       OPTION                OUTPUT                              STATUS
 *               1,2           1               THE RESULT IS=3                      Satisfied
 *               2,3           2               THE RESULT IS=-1                     Satisfied
 *               8,9           6                PROGRAM EXITS                       Satisfied*/             


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace calculator
{
    class Program
    {
        static int Add(int first, int second)
        {
            return (first + second);
        }
        static int Sub(int first, int second)
        {
            return (first - second);
        }
        static int Mul(int first, int second)
        {
            return (first * second);
        }
        static int Div(int first, int second)
        {
            return (first / second);
        }
        static void Main(string[] args)
        {
                Console.WriteLine("ENTER THE TWO NOS");
                int a = int.Parse(Console.ReadLine());
                int b = int.Parse(Console.ReadLine());

                Console.WriteLine("ENTER UR CHOICE");
                Console.WriteLine("1.Addition");
                Console.WriteLine("2.Subtraction");
                Console.WriteLine("3.Multiplication");
                Console.WriteLine("4.Division");
                Console.WriteLine("ANY OTHER TO EXIT");

                int number = int.Parse(Console.ReadLine());
                
                switch (number)
                {

                    case 1:
                        int x = Add(a, b);
                        Console.WriteLine("RESULT IS=" + x);
                        break;
                    case 2: 
                        int y = Sub(a, b);
                        Console.WriteLine("RESULT IS=" + y);
                        break;
                    case 3: 
                        int z = Mul(a, b);
                        Console.WriteLine("RESULT IS=" + z);
                        break;
                    case 4: 
                        int d = Div(a, b);
                        Console.WriteLine("RESULT IS=" + d);
                        break;
                    default: Console.Read();
                        break;

                }
            

            Console.Read();
        }
    }
}

Submit "Dot Net Code: Write A Program To Implement Simple Calculator." to Digg Submit "Dot Net Code: Write A Program To Implement Simple Calculator." to del.icio.us Submit "Dot Net Code: Write A Program To Implement Simple Calculator." to StumbleUpon Submit "Dot Net Code: Write A Program To Implement Simple Calculator." to Google

Categories
ASP .Net

Comments




Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.