In: Computer Science
Develop a form to display centigrade temperature and corresponding Fahrenheit temperature ranging from 30 to 90 at increments of 10. Use a do while loop. Please use the below formula to convert Celsius to Fahrenheit in advance C#
I need the form not a table. Thank you!
C Sharp Program:
File: Form1.Designer.cs
namespace TemperatureForm
{
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.lstBoxTemperature = new System.Windows.Forms.ListBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lstBoxTemperature
//
this.lstBoxTemperature.FormattingEnabled = true;
this.lstBoxTemperature.Location = new System.Drawing.Point(51,
58);
this.lstBoxTemperature.Name = "lstBoxTemperature";
this.lstBoxTemperature.Size = new System.Drawing.Size(188,
199);
this.lstBoxTemperature.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(48, 22);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(191, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Celsius to Fahrenheit Conversion Table";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 276);
this.Controls.Add(this.label1);
this.Controls.Add(this.lstBoxTemperature);
this.Name = "Form1";
this.Text = "Celsius to Fahrenheit";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ListBox lstBoxTemperature;
private System.Windows.Forms.Label label1;
}
}
_________________________________________________________________________________________
File: Form1.cs
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 TemperatureForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Form load event handler
private void Form1_Load(object sender, EventArgs e)
{
//Variables
double tempC=30, tempF;
//Writing headers in listbox
lstBoxTemperature.Items.Add("Celsius \t Fahrenheit");
//Looping over temperatures from 30 to 90 at increments of
10
do
{
//Converting temperature
tempF = (tempC * 1.8) + 32;
//Adding a row
lstBoxTemperature.Items.Add(tempC.ToString("0.00") + "\t" +
tempF.ToString("0.00"));
//Incrementing tempC
tempC = tempC + 10;
} while (tempC <= 90);
}
}
}
__________________________________________________________________________________________
Sample Run: