using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Multi_Choice_area_s
{
class Program
{
static void Main(string[] args)
{
//Assigning variables
string shape = "default";
double X, Y, Z;
const double PI = Math.PI;
while (!shape.Equals("exit"))
{
//Showing user the shapes
Console.WriteLine("Options are: Rectangle, Triangle, Circle, Parallelogram, " +
"Trapezium or exit. \"case insensitive\"\n");
Console.Write("\nEnter shape: ");
shape = Console.ReadLine();
switch (shape.ToLower()) //Changes input to lower case for comparing
{
case "rectangle":
Console.Write("Length: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Width/Height: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nThe area of the {0} is: {1}", shape, X * Y);
break;
case "triangle":
Console.Write("Height: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Base length: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, (Y / 2) * X);
break;
case "circle":
Console.Write("Radius: ");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, PI * (X * X));
break;
case "parallelogram":
goto case "rectangle";
case "trapezium":
Console.Write("Height: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Top Length: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.Write("Base Length: ");
Z = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, (X / 2) * (Y + Z));
break;
case "exit":
break;
//If anything that is not a shape entered - ERROR
default:
Console.WriteLine("ERROR: unknown shape entered, try again");
break;
}
Console.Write("Press any key to continue/exit");
Console.ReadKey(); //Wait for user
Console.Clear(); //Clear the console
}
}
}
}
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 Calculator_for_Asian
{
public partial class Form1 : Form
{
double total1 = 0, total2 = 0;
bool plusButtonClicked = false, minusButtonClicked = false,
multiplyButtonClicked = false, divideButtonClicked = false;
public Form1()
{
InitializeComponent();
}
private void btnOne_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnOne.Text;
}
private void btnTwo_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnTwo.Text;
}
private void btnThree_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnThree.Text;
}
private void btnFour_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnFour.Text;
}
private void btnFive_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnFive.Text;
}
private void btnSix_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnSix.Text;
}
private void btnSeven_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnSeven.Text;
}
private void btnEight_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnEight.Text;
}
private void btnNine_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnNine.Text;
}
private void btnZero_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnZero.Text;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnPlus_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = true;
minusButtonClicked = false;
multiplyButtonClicked = false;
divideButtonClicked = false;
}
private void btnEquals_Click(object sender, EventArgs e)
{
if (plusButtonClicked == true)
{
total2 = total1 + double.Parse(txtDisplay.Text);
}
else if (minusButtonClicked == true)
{
total2 = total1 - double.Parse(txtDisplay.Text);
}
else if (multiplyButtonClicked == true)
{
total2 = total1 * double.Parse(txtDisplay.Text);
}
else if (divideButtonClicked == true)
{
total2 = total1 / double.Parse(txtDisplay.Text);
}
txtDisplay.Text = total2.ToString();
total1 = 0;
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text += btnPoint.Text;
}
private void lblCalculator_Click(object sender, EventArgs e)
{
}
private void txtDisplay_TextChanged(object sender, EventArgs e)
{
}
private void btnMinus_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = false;
minusButtonClicked = true;
multiplyButtonClicked = false;
divideButtonClicked = false;
}
private void btnMultiply_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = false;
minusButtonClicked = false;
multiplyButtonClicked = true;
divideButtonClicked = false;
}
private void btnDivide_Click(object sender, EventArgs e)
{
total1 += double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = false;
minusButtonClicked = false;
multiplyButtonClicked = false;
divideButtonClicked = true;
}
}
}
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 basicwordprocessor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
string Chosen_File = "";
#region properties
openFD.InitialDirectory = "C:";
openFD.Title = "Open a text file";
openFD.FileName = "";
openFD.Filter = "Text Files|*.txt|Word Documents|*.doc";
#endregion
if (openFD.ShowDialog() != DialogResult.Cancel)
{
Chosen_File = openFD.FileName;
txtBox.LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
string Save_File = "";
#region properties
saveFD.InitialDirectory = "C:";
saveFD.Title = "Save a text file";
saveFD.FileName = "";
saveFD.Filter = "Text File|*.txt";
#endregion
if (saveFD.ShowDialog() != DialogResult.Cancel)
{
Save_File = saveFD.FileName;
txtBox.SaveFile(Save_File, RichTextBoxStreamType.PlainText);
}
}
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtBox.Text != "")
{
if (MessageBox.Show("Are you sure you want to quit?", "Warning",
MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Application.Exit();
}
else
{
Application.Exit();
}
}
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
txtBox.Clear();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
if (txtBox.SelectionLength > 0)
{
txtBox.Copy();
}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
txtBox.Paste();
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Multi_Choice_area_s
{
class Program
{
static int Main(string[] args)
{
//Assigning variables
string shape;
double X, Y, Z, PI = Math.PI;
//Showing user the shapes
Console.WriteLine("Options are: Rectangle, Triangle, Circle, Parallelogram, " +
"Trapezium or exit. (case insensitive)");
for (;
{
Console.WriteLine("Enter shape:");
shape = Console.ReadLine();
switch (shape.ToLower()) //Changes input to lower case for comparing
{
case "rectangle":
Console.WriteLine("Length:");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Width:");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area is: {0}", X * Y);
break;
case "triangle":
Console.WriteLine("Height:");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Base length:");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area is: {0}", (Y / 2) * X);
break;
case "circle":
Console.WriteLine("Radius:");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area is: {0}", PI * (X * X));
break;
case "parallelogram":
goto case "rectangle"; //Goto is efficient here for less space
case "trapezium":
Console.WriteLine("Height:");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Top Length:");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Base Length:");
Z = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area is: {0}", (X / 2) * (Y + Z));
break;
case "exit":
return 0; //Couldn't figure any other way to exit/don't know one yet.
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Multi_Choice_area_s
{
class Program
{
static int Main(string[] args)
{
//Assigning variables
string shape;
double X, Y, Z, PI = Math.PI;
while (true)
{
//Showing user the shapes
Console.WriteLine("Options are: Rectangle, Triangle, Circle, Parallelogram, " +
"Trapezium or exit. \"case insensitive\"");
Console.Write("\nEnter shape: ");
shape = Console.ReadLine();
switch (shape.ToLower()) //Changes input to lower case for comparing
{
case "rectangle":
Console.Write("Length: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Width/Height: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("\nThe area of the {0} is: {1}", shape, X * Y);
break;
case "triangle":
Console.Write("Height: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Base length: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, (Y / 2) * X);
break;
case "circle":
Console.Write("Radius: ");
X = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, PI * (X * X));
break;
case "parallelogram":
goto case "rectangle";
case "trapezium":
Console.Write("Height: ");
X = Convert.ToDouble(Console.ReadLine());
Console.Write("Top Length: ");
Y = Convert.ToDouble(Console.ReadLine());
Console.Write("Base Length: ");
Z = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("The area of the {0} is: {1}", shape, (X / 2) * (Y + Z));
break;
case "exit":
return 0; //Couldn't figure any other way to exit/don't know one yet.
//If anything that is not a shape entered - ERROR
default:
Console.WriteLine("ERROR: unknown shape entered, try again");
break;
}
//wait for user to press any key
Console.ReadKey();
//clear the screen (thus giving appearance of restarting the program)
Console.Clear();
}
}
}
}
const double PI = Math.PI;
private static string WordWrap(string text, int bufferWidth)
{
// declare "result" to store the result of world wrap
// initialize to nothing/blank
string result = "";
// declare string array "lines" to store each line on console
// initialize to each time the text on console is split by a new line
string[] lines = text.Split('\n';
// for each line in the console window, do the following...
foreach (string line in lines)
{
// declare the "lineLength" to store the length of each line
// initialize to zero
int lineLength = 0;
// declare string array "words" to store each word
// initialize to each time a space character appears in the console window
string[] words = line.Split(' ';
// for each word in the console window, do the following...
foreach (string word in words)
{
// if the length of a word, plus the length of the line is greater than or equal to width of the consoel window minus 1 character, do the following...
if (word.Length + lineLength >= bufferWidth - 1)
{
// set result equal to a new line plus whatever was already in result
result += "\n";
//reset lineLength to zero
lineLength = 0;
}
// set result to the word, plus a space, plus whatever was already in it
result += word + " ";
//set lineLength to the length of the word, plus one, plus whatever was already in it
lineLength += word.Length + 1;
}
//set result to a new line, plus whatever was already in it
result += "\n";
}
//return result
return result;
}
Console.WriteLine(WordWrap("YOUR TEXT HERE", Console.WindowWidth));
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 calculatorv1
{
public partial class Form1 : Form
{
/* This program is currently being powered by a series of "if...then...else" statements, as opposed to a "switch" statement, the code for a switch statement is
* present though, so as to prevent the program from trying to "run twice" and crash the code for the switch statment is commented out, it will be commented out
* in the same way this text is, not the double-forward-slash method. */
double total1 = 0; //sets up totals, total1 will be the current/running value, total2 will be the final value displayed to the user
double total2 = 0;
bool plusButtonClicked = false; //sets up plus/minus button booleans, both set to false
bool minusButtonClicked = false;
bool multiplyButtonClicked = false; //sets up multiply/divide button booleans, both set to false
bool divideButtonClicked = false;
/* string theOperator; */
public Form1()
{
InitializeComponent();
}
private void btnOne_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnOne.Text;
}
private void btnTwo_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnTwo.Text;
}
private void btnThree_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnThree.Text;
}
private void btnFour_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFour.Text;
}
private void btnFive_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnFive.Text;
}
private void btnSix_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSix.Text;
}
private void btnSeven_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnSeven.Text;
}
private void btnEight_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnEight.Text;
}
private void btnNine_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnNine.Text;
}
private void btnZero_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnZero.Text;
}
private void btnClear_Click(object sender, EventArgs e)
{
txtDisplay.Clear();
}
private void btnPlus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = true; //changes the plus/addition boolean to true when the addition button is clicked
minusButtonClicked = false;
multiplyButtonClicked = false;
divideButtonClicked = false;
/* theOperator = "+"; */
}
private void btnEquals_Click(object sender, EventArgs e)
{
if (plusButtonClicked == true) //if the plus button is clicked, then add the current total to the user input
{
total2 = total1 + double.Parse(txtDisplay.Text);
}
else if (minusButtonClicked == true) //if the minus button is clicked, then subtract the user input from the current total
{
total2 = total1 - double.Parse(txtDisplay.Text);
}
else if (multiplyButtonClicked == true) //if the multiply button is clicked, then multiply the current total by the user input
{
total2 = total1 * double.Parse(txtDisplay.Text);
}
else if (divideButtonClicked == true) //if the divide button is clicked, then divide the current total by the user input
{
total2 = total1 / double.Parse(txtDisplay.Text);
}
/* switch (theOperator)
* {
* case "+":
* //ADDITION CODE HERE (from the if statement)
* break;
* //add more cases here as needed
* default:
* //DEFAULT CODE HERE (what to do if none of the variables apply to one of the cases)
* break;
* } */
txtDisplay.Text = total2.ToString(); //sets the display text to the value of total2 (that gets converted from a double [number] to a string [text]
total1 = 0; //resets total1 so it can hold more data
}
private void btnPoint_Click(object sender, EventArgs e)
{
txtDisplay.Text = txtDisplay.Text + btnPoint.Text;
}
private void label1_Click(object sender, EventArgs e)
{
}
private void txtDisplay_TextChanged(object sender, EventArgs e)
{
}
private void btnMinus_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear(); //sets the total1 to itself + the contents of the textbox (adds user input to current/running total)
plusButtonClicked = false;
minusButtonClicked = true; //changes minus boolean to true when the minus button is clicked
multiplyButtonClicked = false;
divideButtonClicked = false;
/* theOperator = "-"; */
}
private void btnMultiply_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = false;
minusButtonClicked = false;
multiplyButtonClicked = true; //changes the multiply boolean to true when multiply button is clicked
divideButtonClicked = false;
/* theOperator = "*"; */
}
private void btnDivide_Click(object sender, EventArgs e)
{
total1 = total1 + double.Parse(txtDisplay.Text);
txtDisplay.Clear();
plusButtonClicked = false;
minusButtonClicked = false;
multiplyButtonClicked = false;
divideButtonClicked = true; //changes the divide boolean to true when the divide button is clicked
/* theOperator = "/"; */
}
}
}
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 basicwordprocessor
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
// Open file to the Rich Text Box
string Chosen_File = "";
#region properties
openFD.InitialDirectory = "C:";
openFD.Title = "Open a Text File";
openFD.FileName = "";
openFD.Filter = "Text Files|*.txt|Word Documents|*.doc";
#endregion
if (openFD.ShowDialog() != DialogResult.Cancel)
{
Chosen_File = openFD.FileName;
txtBox.LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);
}
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
// Save file from text in Rich Text Box into .txt format
string Save_File = "";
#region properties
saveFD.InitialDirectory = "C:";
saveFD.Title = "Save a Text File";
saveFD.FileName = "";
saveFD.Filter = "Text File|*.txt";
#endregion
if (saveFD.ShowDialog() != DialogResult.Cancel)
{
Save_File = saveFD.FileName;
txtBox.SaveFile(Save_File, RichTextBoxStreamType.PlainText);
}
}
private void quitToolStripMenuItem1_Click(object sender, EventArgs e)
{
// Closes program
if (txtBox.Text != "")
{
if (MessageBox.Show("Are you sure you want to quit?", "Close", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
{
Application.Exit();
}
}
else
{
Application.Exit();
}
}
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
// Clears text buffer
txtBox.Clear();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
// Copies selected text to Clipboard
if (txtBox.SelectionLength > 0)
{
txtBox.Copy();
}
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
// Pastes text that was on Clipboard
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
txtBox.Paste();
}
}
}
}
Form2 form = new Form2;
form.Show();
MessageBox.Show("Your body text", "Your title text", MessageBoxButtons.*buttons*, MessageBoxIcon.*icon*);
Copyright © 2024, NextGenUpdate.
All Rights Reserved.