Question

In: Computer Science

OBJECTIVE C 2) // Create a small app that takes user input and performs a useful...

OBJECTIVE C

2) // Create a small app that takes user input and performs a useful calculation with that user input

// - make sure that absolutely no input crashes the app.

// - Use layout constraints to make sure the app looks good in portraint and landscape mode, as well as on small and large devices.

Solutions

Expert Solution

using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace CalculatorApp
    {
        public partial class Form1 : Form
        {
            double FirstNumber;
            string Operation;
            public Form1()
            {
                InitializeComponent();
            }
    
           
            private void n1_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "1";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "1";
                }
            }
    
            private void n2_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "2";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "2";
                }
            }
    
            private void n3_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "3";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "3";
                }
            }
    
            private void n4_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "4";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "4";
                }
            }
    
            private void n5_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "5";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "5";
                }
            }
    
            private void n6_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "6";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "6";
                }
            }
    
            private void n7_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "7";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "7";
                }
            }
    
            private void n8_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "0" && textBox1.Text != null)
                {
                    textBox1.Text = "8";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "8";
                }
            }
    
            private void n9_Click(object sender, EventArgs e)
            {
                if (textBox1.Text == "" && textBox1.Text != null)
                {
                    textBox1.Text = "9";
                }
                else
                {
                    textBox1.Text = textBox1.Text + "9";
                }
            }
    
            private void n0_Click(object sender, EventArgs e)
            {
                textBox1.Text = textBox1.Text + "0";
            }
    
            private void bad_Click(object sender, EventArgs e)
            {
                FirstNumber = Convert.ToDouble(textBox1.Text);
                textBox1.Text = "0";
                Operation = "+";
            }
    
            private void bsub_Click(object sender, EventArgs e)
            {
                FirstNumber = Convert.ToDouble(textBox1.Text);
                textBox1.Text = "0";
                Operation = "-";
    
            }
    
            private void bmul_Click(object sender, EventArgs e)
            {
                FirstNumber = Convert.ToDouble(textBox1.Text);
                textBox1.Text = "0";
                Operation = "*";
            }
    
            private void bdiv_Click(object sender, EventArgs e)
            {
                FirstNumber = Convert.ToDouble(textBox1.Text);
                textBox1.Text = "0";
                Operation = "/";
            }
    
            private void bc_Click(object sender, EventArgs e)
            {
                textBox1.Text = "0";
            }
    
            private void ndot_Click(object sender, EventArgs e)
            {
                textBox1.Text = textBox1.Text + ".";
            }
    
            private void nequal_Click(object sender, EventArgs e)
            {
                double SecondNumber;
                double Result;
    
                SecondNumber = Convert.ToDouble(textBox1.Text);
    
                if (Operation == "+")
                {
                    Result = (FirstNumber + SecondNumber);
                    textBox1.Text = Convert.ToString(Result);
                    FirstNumber = Result;
                }
                if (Operation == "-")
                {
                    Result = (FirstNumber - SecondNumber);
                    textBox1.Text = Convert.ToString(Result);
                    FirstNumber = Result;
                }
                if (Operation == "*")
                {
                    Result = (FirstNumber * SecondNumber);
                    textBox1.Text = Convert.ToString(Result);
                    FirstNumber = Result;
                }
                if (Operation == "/")
                {
                    if (SecondNumber == 0)
                    {
                        textBox1.Text = "Cannot divide by zero";
    
                    }
                    else
                    {
                        Result = (FirstNumber / SecondNumber);
                        textBox1.Text = Convert.ToString(Result);
                        FirstNumber = Result;
                    }
                }
            }
        }
    }


Related Solutions

C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Important! Consider which control structures will work best for which aspect of the assignment. For example, which would be the best to use for a menu?...
C Program: Create a C program that prints a menu and takes user choices as input....
C Program: Create a C program that prints a menu and takes user choices as input. The user will make choices regarding different "geometric shapes" that will be printed to the screen. The specifications must be followed exactly, or else the input given in the script file may not match with the expected output. Your code must contain at least one of all of the following control types: nested for() loops a while() or a do-while() loop a switch() statement...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic:...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat until they enter -1 for the number. . Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10. Next sort all the numbers using selection sort and display them. Next give the user option to search for a specific number in the list....
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic:...
IN C++. Objective: Create a Singly linked list of numbers based upon user input. Program logic: Ask for a number, add that number to the front of the list, print the list. Repeat until they enter -1 for the number. . Sample Input: 10, 15, 5, 2, 4, -1 Output: 4, 2, 5, 15, 10. Next sort all the numbers using selection sort and display them. Next give the user option to search for a specific number in the list....
USE C++ for following problem and also use create full program that takes input from user...
USE C++ for following problem and also use create full program that takes input from user also do not use loops only recursion and try to keep program simple A palindrome is any word, phrase, or sentence that reads the same forwards or backwards. Here are some palindromes: Level Civic Pot top A man a plan a canal Panama Write a boolean function that determines if a string argument is a palindrome. The function should return true if the argument...
Create a console app c#. Using a List, ask the user to enter all of their...
Create a console app c#. Using a List, ask the user to enter all of their favorite things. Once they are done, randomly pick a value from the list and display it.
Create the logic for a rhyming program that takes in five words from a user input...
Create the logic for a rhyming program that takes in five words from a user input and replaces the selected rhyming words with the user's input, then creates and displays the Humpty Dumpty rhyme with the five words from the user input. Hint: 1. You will use the sentinel values: start and stop 2. The program will ask the user for 5 words. 3. The program will store the 5 words 4. The program outputs the rhyme replacing the ____...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Python: You will modify the given code to create a guessing game that takes user input...
Python: You will modify the given code to create a guessing game that takes user input and allows you to make multiple guesses. There should also be a loop Use the following attached Sample Code as a guide. There are mistakes in the code!!! #Guessing Game import random number=random.randint(1, another number) print("Hello, CIS 101") print("Let's play a guessing Game!called guess my number.") print("The rules are: ") print("I think of a number and you'll have to guess it.") guess = random.randint(1,...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT