Must be in Visual Studio C# Create an application that simulates a soft-drink ve
ID: 3685989 • Letter: M
Question
Must be in Visual Studio C#
Create an application that simulates a soft-drink vending machine. The application should let the user select one of the following soft drinks:
Cola ($1.00 each)
Root Beer ($1.00 each)
Lemon Lime Soda ($1.00 each)
Grape Soda ($1.50 each)
Cream Soda ($1.50 each)
Here's an example of the application's form (The images that are displayed in the PictureBox controls are in the the attached Drink Machine zip file.)
When the application starts, the vending machine will have 20 of each type of soft drink. Each time the user selects a drink, the application should subtract 1 from the quantity of the selected drink. It should also update and display the total amount of sales. If the user selects a drink that is sold out, a message should be displayed indicating so.
In the application's code, create a structure that has fields for the following data:
Drink name
Drink cost
Number of drinks in machine
The program should create an array of five structure objects. Each element of the array should keep data for a specific type of soft drink.
Explanation / Answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace softdrinks
{
public partial class Form1 : Form
{
double tot;
struct cola
{
public String cname;
public double ccost;
public int no;
}
struct rbeer
{
public String cname;
public double ccost;
public int no;
}
struct lsoda
{
public String cname;
public double ccost;
public int no;
}
struct gsoda
{
public String cname;
public double ccost;
public int no;
}
struct csoda
{
public String cname;
public double ccost;
public int no;
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
cola o;
rbeer o1;
lsoda o2;
gsoda o3;
csoda o4;
o.ccost = 1;
o.no = 20;
o1.ccost = 1;
o1.no = 20;
o2.ccost = 1;
o2.no = 20;
o3.ccost = 1;
o3.no = 20;
o4.ccost = 1;
o4.no = 20;
if (checkBox1.Checked)
{
tot = tot + o.ccost;
o.no = o.no - 1;
}
if (checkBox2.Checked)
{
tot = tot + o.ccost;
o.no = o.no - 1;
}
if (checkBox3.Checked)
{
tot = tot + o.ccost;
o.no = o.no - 1;
}
if (checkBox4.Checked)
{
tot = tot + o.ccost;
o.no = o.no - 1;
}
if (checkBox5.Checked)
{
tot = tot + o.ccost;
o.no = o.no - 1;
}
label1.Text = tot.ToString ();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.