Question: Write the following C# code in Pseudocode Format: 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
Write the following C# code in Pseudocode Format:
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 tipCalculator2018a1_proj { public partial class TipCalcForm : Form { // /* // Declare global variables and constants: private string[] SERVICE_LEVELS = {"Poor","OK","Good","Great"}; private decimal[] TIP_RATES = { 0.05m, 0.10m, 0.15m, 0.20m }; private decimal decBillAmount, decTipRate; private const string ERROR_TITLE = "Bad Data!"; private const string BAD_AMOUNT_MSG = "Please enter a correct bill amount."; private const string BAD_LEVEL_MSG = "Please select a valid service level."; // */ public TipCalcForm() { InitializeComponent(); }
private void TipCalcForm_Load(object sender, EventArgs e) { // /* // Initialize dropdown list: serviceList.Items.Add("Select one . . ."); // Process through service level array by adding items to dropdown list: foreach (string level in SERVICE_LEVELS) { serviceList.Items.Add(level); } // Set dropdown list to top item: serviceList.SelectedIndex = 0; // Hide results section: resultTable.Visible = false; // */ }
private void calcButton_Click(object sender, EventArgs e) { // /* // Declare local variables: decimal decTipAmount, decTotal; // Call GetData() method to get data from form: GetData(); // Validate input data: if (decBillAmount > 0.00m && decTipRate > 0.00m) { // Call CalculateTip() method to calculate tip: decTipAmount = CalculateTip(decTipRate, decBillAmount); // Calculate total (tipAmount + billAmount): decTotal = decBillAmount + decTipAmount; // Prepare and assign calculation results to output: tipAmountLabel.Text = decTipAmount.ToString("c2"); totalAmountLabel.Text = decTotal.ToString("c2"); // Unhide results section: resultTable.Visible = true; } // */ }
// /* private void GetData() { // Declare local variables: bool blnAmountOK,blnTipOK; int i; // Read and validate data from interface: blnAmountOK = decimal.TryParse(amountBox.Text, out decBillAmount); blnTipOK = (serviceList.SelectedIndex == 0) ? false : true; // If inputs are valid: if (blnAmountOK==true && blnTipOK==true){ // Determine tip rate based on selected service level: i = serviceList.SelectedIndex - 1; decTipRate = TIP_RATES[i]; } // Otherwise handle error messages: else { // Bad service level selection: if (!blnTipOK) { MessageBox.Show(BAD_LEVEL_MSG, ERROR_TITLE); serviceList.Focus(); } // Bad amount entry: if (!blnAmountOK) { MessageBox.Show(BAD_AMOUNT_MSG, ERROR_TITLE); amountBox.Focus(); // Should also have a line following: amountBox.SelectAll(); } } return; } // */
// /* private decimal CalculateTip(decimal tipRate, decimal billAmount) { // Declare local variables: decimal tipAmount = 0m; // Calculate tip amount (tipRate * billAmount): tipAmount = billAmount * tipRate; return tipAmount; } // */ } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
