Question

In: Computer Science

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C# I have struggled on this program for quite some...

USING VISUAL STUDIO 2017, LANGUAGE VISUAL C#

I have struggled on this program for quite some time and still can't quite figure it out.

I'm creating an app that has 2 textboxes, 1 for inputting customer name, and the second for entering the number of tickets the customer wants to purchase. There are 3 listboxes, the first with the days of the week, the second with 4 different theaters, and the third listbox is to display the customer name, number of tickets, and total price. The ticketbase = 50, weekend upcharge = 30, for Imax & Upac theaters = 35 and for Capital and Premier theaters = 25. There are 4 buttons: Process customer, Display daily report, clear all, and exit. For the process customer button, it is clicked after customer has inputted their info in textbox1 and 2 and selected from listbox 1 and 2. it is supposed to compute the cost of tickets and enter that data into an array, not more than 5 customers can be processed without clearing all with the clear all button. Once process customer button is pressed it displays a message box displaying "customer processed", and all selected inputs should be cleared after pressing OK. In the display daily report button it is supposed to take array elements using a loop, one at a time and add them to the listbox3. There are supposed to be 2-3 arrays for the input one for name of customer, another for number of tickets, and another for the cost. And for the output it is supposed to be stored in internal arrays. I am not sure of how to set this up.

Solutions

Expert Solution

Short Summary:

  • Implemented a windows application using C#.
  • Provided designer.cs file for your reference

Source Code:

Form1.cs File:

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 BookingApp

{

    public partial class Form1 : Form

    {

        // Arrays to hold the input values

        string[] name;

        int[] numTickets;

        //string[] days;

        //string[] theaters;

        int[] costs;

        const int MAX_CUSTOMERS = 5;

        int currentCapacity;

        // Ticket costs

        const int TICKET_BASE = 50;

        const int WEEKEND_UPCHARGE = 30;

        const int IMAX_COST = 35;

        const int UPAC_COST = 35;

        const int CAPTIAL_COST = 25;

        const int PREMIER_COST = 25;

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            // Initialize the array

            name = new string[MAX_CUSTOMERS];

            numTickets = new int[MAX_CUSTOMERS];

            //days = new string[MAX_CUSTOMERS];

            //theaters = new string[MAX_CUSTOMERS];

            costs = new int[MAX_CUSTOMERS];

            currentCapacity = 0;

        }

        /// <summary>

        /// Calculates total costs for the given input

        /// </summary>

        private int GetCost(int numTicket, string day, string theater)

        {

            int totalcost = TICKET_BASE;

            //weekend upcharge

            if(day == "Saturday" || day == "Sunday")

            {

                totalcost += WEEKEND_UPCHARGE;

            }

            // Add theater cost

            if(theater == "Imax")

            {

                totalcost += IMAX_COST;

            }

            else if(theater == "Upac")

            {

                totalcost += UPAC_COST;

            }

            else if (theater == "Capital")

            {

                totalcost += CAPTIAL_COST;

            }

            else if (theater == "Premier")

            {

                totalcost += PREMIER_COST;

            }

            //return the total

            return totalcost;

        }

        /// <summary>

        /// Reset the input boxes

        /// </summary>

        private void ResetInputs()

        {

            txtCustName.Text = "";

            txtNumOfTickets.Text = "";

            lbDays.SelectedIndex = -1;

            lbTheater.SelectedIndex = -1;

        }

        private void btnProcess_Click(object sender, EventArgs e)

        {

            // Validate if it has enough capacity

            if(MAX_CUSTOMERS == currentCapacity)

            {

                MessageBox.Show("Reached maximum capacity, clear all before proceed to add new customer",

                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

          }

            // Validate if customer entered

            if (string.IsNullOrEmpty(txtCustName.Text.Trim()))

            {

                MessageBox.Show("Enter customer name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // validate if number of tickcets

            int numTicket = 0;

            if (int.TryParse(txtNumOfTickets.Text.Trim(), out numTicket) == false || numTicket <= 0)

            {

                MessageBox.Show("Enter valid number of tickets", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Validate if day is selected

            if(lbDays.SelectedIndex == -1)

            {

                MessageBox.Show("Select a day of the week", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Validate if theater is selected

            if (lbTheater.SelectedIndex == -1)

            {

                MessageBox.Show("Select a theater", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;

            }

            // Add input values to the array

            name[currentCapacity] = txtCustName.Text.Trim();

            numTickets[currentCapacity] = numTicket;

            //days[currentCapacity] = lbDays.SelectedItem.ToString();

            //theaters[currentCapacity] = lbTheater.SelectedItem.ToString();

            costs[currentCapacity] = GetCost(numTicket, lbDays.SelectedItem.ToString(), lbTheater.SelectedItem.ToString());

            // Increase the current index

            currentCapacity++;

            // Display the meesage

            MessageBox.Show("Customer processed", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            // clear the inputs

            ResetInputs();

            txtCustName.Focus();

        }

        private void btnDailyReport_Click(object sender, EventArgs e)

        {

            // clear any previous values

            lbResults.Items.Clear();

            lbResults.Items.Add(string.Format("{0, -10} {1, 10} {2, 10}", "Name", "NumTickets", "TotalCost"));

            for (int index = 0; index < currentCapacity; index++)

            {

                lbResults.Items.Add(string.Format("{0, -10} {1, 10} {2, 10}", name[index], numTickets[index], costs[index]));

            }

        }

        private void btnClear_Click(object sender, EventArgs e)

        {

            ResetInputs();

            lbResults.Items.Clear();

            Array.Clear(name, 0, MAX_CUSTOMERS);

            Array.Clear(numTickets, 0, MAX_CUSTOMERS);

            Array.Clear(costs, 0, MAX_CUSTOMERS);

            currentCapacity = 0;

        }

        private void btnExit_Click(object sender, EventArgs e)

        {

            Application.Exit();

        }

    }

}

Form1.designer.cs File:

namespace BookingApp

{

    partial class Form1

    {

        /// <summary>

        /// Required designer variable.

        /// </summary>

        private System.ComponentModel.IContainer components = null;

        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }

       #region Windows Form Designer generated code

        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

            this.label1 = new System.Windows.Forms.Label();

            this.txtCustName = new System.Windows.Forms.TextBox();

            this.txtNumOfTickets = new System.Windows.Forms.TextBox();

            this.label2 = new System.Windows.Forms.Label();

            this.lbDays = new System.Windows.Forms.ListBox();

            this.label3 = new System.Windows.Forms.Label();

            this.label4 = new System.Windows.Forms.Label();

            this.lbTheater = new System.Windows.Forms.ListBox();

            this.btnProcess = new System.Windows.Forms.Button();

            this.btnDailyReport = new System.Windows.Forms.Button();

            this.btnClear = new System.Windows.Forms.Button();

            this.btnExit = new System.Windows.Forms.Button();

            this.lbResults = new System.Windows.Forms.ListBox();

            this.label5 = new System.Windows.Forms.Label();

            this.SuspendLayout();

            //

            // label1

            //

            this.label1.AutoSize = true;

            this.label1.Location = new System.Drawing.Point(89, 57);

            this.label1.Name = "label1";

            this.label1.Size = new System.Drawing.Size(132, 20);

            this.label1.TabIndex = 0;

            this.label1.Text = "Customer Name: ";

            //

            // txtCustName

            //

            this.txtCustName.Location = new System.Drawing.Point(265, 54);

            this.txtCustName.Name = "txtCustName";

            this.txtCustName.Size = new System.Drawing.Size(257, 26);

            this.txtCustName.TabIndex = 1;

            //

            // txtNumOfTickets

            //

            this.txtNumOfTickets.Location = new System.Drawing.Point(265, 115);

            this.txtNumOfTickets.Name = "txtNumOfTickets";

            this.txtNumOfTickets.Size = new System.Drawing.Size(257, 26);

            this.txtNumOfTickets.TabIndex = 3;

            //

            // label2

            //

            this.label2.AutoSize = true;

            this.label2.Location = new System.Drawing.Point(80, 118);

            this.label2.Name = "label2";

            this.label2.Size = new System.Drawing.Size(141, 20);

            this.label2.TabIndex = 2;

            this.label2.Text = "Number of Tickets:";

            //

            // lbDays

            //

            this.lbDays.FormattingEnabled = true;

            this.lbDays.ItemHeight = 20;

            this.lbDays.Items.AddRange(new object[] {

            "Sunday",

            "Monday",

            "Tuesday",

            "Wednesday",

            "Thursday",

            "Friday",

            "Saturday"});

            this.lbDays.Location = new System.Drawing.Point(265, 177);

            this.lbDays.Name = "lbDays";

            this.lbDays.Size = new System.Drawing.Size(160, 164);

            this.lbDays.TabIndex = 4;

            //

            // label3

          //

            this.label3.AutoSize = true;

            this.label3.Location = new System.Drawing.Point(117, 177);

            this.label3.Name = "label3";

            this.label3.Size = new System.Drawing.Size(104, 20);

            this.label3.TabIndex = 5;

            this.label3.Text = "Day of Week:";

            //

            // label4

            //

            this.label4.AutoSize = true;

            this.label4.Location = new System.Drawing.Point(91, 376);

            this.label4.Name = "label4";

            this.label4.Size = new System.Drawing.Size(130, 20);

            this.label4.TabIndex = 6;

            this.label4.Text = "Select a Theater:";

            //

            // lbTheater

            //

            this.lbTheater.FormattingEnabled = true;

            this.lbTheater.ItemHeight = 20;

            this.lbTheater.Items.AddRange(new object[] {

            "Imax",

            "Upac",

            "Capital",

            "Premier"});

            this.lbTheater.Location = new System.Drawing.Point(265, 376);

            this.lbTheater.Name = "lbTheater";

            this.lbTheater.Size = new System.Drawing.Size(160, 144);

            this.lbTheater.TabIndex = 7;

            //

            // btnProcess

            //

            this.btnProcess.Location = new System.Drawing.Point(65, 564);

            this.btnProcess.Name = "btnProcess";

            this.btnProcess.Size = new System.Drawing.Size(182, 38);

            this.btnProcess.TabIndex = 8;

            this.btnProcess.Text = "Process Customer";

            this.btnProcess.UseVisualStyleBackColor = true;

            this.btnProcess.Click += new System.EventHandler(this.btnProcess_Click);

            //

            // btnDailyReport

            //

            this.btnDailyReport.Location = new System.Drawing.Point(340, 564);

            this.btnDailyReport.Name = "btnDailyReport";

            this.btnDailyReport.Size = new System.Drawing.Size(182, 38);

            this.btnDailyReport.TabIndex = 9;

            this.btnDailyReport.Text = "Display Daily Report";

            this.btnDailyReport.UseVisualStyleBackColor = true;

            this.btnDailyReport.Click += new System.EventHandler(this.btnDailyReport_Click);

            //

            // btnClear

            //

            this.btnClear.Location = new System.Drawing.Point(65, 649);

            this.btnClear.Name = "btnClear";

            this.btnClear.Size = new System.Drawing.Size(182, 38);

            this.btnClear.TabIndex = 10;

            this.btnClear.Text = "Clear All";

            this.btnClear.UseVisualStyleBackColor = true;

            this.btnClear.Click += new System.EventHandler(this.btnClear_Click);

            //

            // btnExit

            //

            this.btnExit.Location = new System.Drawing.Point(340, 649);

            this.btnExit.Name = "btnExit";

            this.btnExit.Size = new System.Drawing.Size(182, 38);

            this.btnExit.TabIndex = 11;

            this.btnExit.Text = "Exit";

            this.btnExit.UseVisualStyleBackColor = true;

            this.btnExit.Click += new System.EventHandler(this.btnExit_Click);

            //

            // lbResults

            //

            this.lbResults.Enabled = false;

            this.lbResults.FormattingEnabled = true;

            this.lbResults.ItemHeight = 20;

            this.lbResults.Location = new System.Drawing.Point(265, 778);

            this.lbResults.Name = "lbResults";

            this.lbResults.Size = new System.Drawing.Size(325, 204);

            this.lbResults.TabIndex = 12;

            //

            // label5

            //

            this.label5.AutoSize = true;

            this.label5.Location = new System.Drawing.Point(93, 778);

            this.label5.Name = "label5";

            this.label5.Size = new System.Drawing.Size(114, 20);

            this.label5.TabIndex = 13;

            this.label5.Text = "Display Result:";

            //

            // Form1

            //

            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(649, 1028);

            this.Controls.Add(this.label5);

            this.Controls.Add(this.lbResults);

            this.Controls.Add(this.btnExit);

            this.Controls.Add(this.btnClear);

            this.Controls.Add(this.btnDailyReport);

            t


Related Solutions

write a c++ program using micro soft visual studio 2010 to write a program and store...
write a c++ program using micro soft visual studio 2010 to write a program and store 36 in variable x and 8 in variable y. add them and store the result in the variable sum. then display the sum on screen with descriptive text. calculate the square root of integer 36 in x. store the result in a variable. calculate the cube root of integer 8 in y. store result in a variable. display the results of square root and...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that...
C++ PROGRAM Using the attached C++ code (Visual Studio project), 1) implement a CoffeeMakerFactory class that prompts the user to select a type of coffee she likes and 2) returns the object of what she selected to the console. #include "stdafx.h" #include <iostream> using namespace std; // Product from which the concrete products will inherit from class Coffee { protected:    char _type[15]; public:    Coffee()    {    }    char *getType()    {        return _type;   ...
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length...
In Assembly Language (Visual Studio 2017), create a procedure that generates a random string of Length L, containing all capital letters. When calling the procedure, pass the value of L in EAX, and pass a pointer to an array of byte that will hold the random string. Write a test program that calls your procedure 20 times and displays the strings in the console window. In your program, the random string size shall be preset as a constant. Please include...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings...
Please write in x86 Assembly language on Visual Studio Write a program to compare two strings in locations str1 and str2. Initialize str1 to Computer and initialize str2 to Compater. Assume Str1 holds the correct spelling and str2 may have an incorrect spelling. Use string instructions to check if str2 is correct and if not correct the mistake in str2.
Language: c++ using visual basic Write a program to open a text file that you created,...
Language: c++ using visual basic Write a program to open a text file that you created, read the file into arrays, sort the data by price (low to high), by box number (low to high), search for a price of a specific box number and create a reorder report. The reorder report should alert purchasing to order boxes whose inventory falls below 100. Sort the reorder report from high to low. Inventory data to input. Box number Number boxes in...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout,...
 VISUAL STUDIO (File Creation and Submissions)  FLOWCHART  Writing program in C++ ( cout, \n, \t, solving expressions )  Correcting errors Q1: Draw flow Chart of the following problems: a) Display “Hello World” on screen. b) Display Your Name, date of birth and mobile number on screen. c) Compute and display the perimeter and area of a rectangle with a height of 7 inches and width of 5 inches. d) Compute and display the perimeter and area...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name...
Develop a C++/Python program using visual studio connected to mysql workbench to show all vendor's name and phone (vendor_name and vendor_phone) in the state "CA" and the city "Los Angeles". here is the database tables CREATE TABLE general_ledger_accounts ( account_number INT PRIMARY KEY, account_description VARCHAR(50) UNIQUE ); CREATE TABLE terms ( terms_id INT PRIMARY KEY AUTO_INCREMENT, terms_description VARCHAR(50) NOT NULL, terms_due_days INT NOT NULL ); CREATE TABLE vendors ( vendor_id INT PRIMARY KEY AUTO_INCREMENT, vendor_name VARCHAR(50) NOT NULL UNIQUE, vendor_address1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT