0% found this document useful (0 votes)
5 views5 pages

C#2

The document contains multiple C# programs demonstrating different functionalities. The first program calculates total revenue after applying discounts based on quantity, the second calculates area or perimeter based on user selection, the third computes areas of a triangle and a circle, and the fourth solves quadratic equations. Each program includes user input and output through console or Windows Forms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

C#2

The document contains multiple C# programs demonstrating different functionalities. The first program calculates total revenue after applying discounts based on quantity, the second calculates area or perimeter based on user selection, the third computes areas of a triangle and a circle, and the fourth solves quadratic equations. Each program includes user input and output through console or Windows Forms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

QUESTION 1

using System;

class Program
{
static void Main()
{
Console.Write("Enter unit price:$ ");
double unitPrice = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter quantity: ");


int quantity = Convert.ToInt32(Console.ReadLine());

double discountRate = 0;

if (quantity >= 100 && quantity <= 120)


discountRate = 0.10;
else if (quantity > 120)
discountRate = 0.15;

double revenue = unitPrice * quantity * (1 - discountRate);

Console.WriteLine("Total revenue after discount: " +


string.Format("{0:C}", revenue));
Console.ReadKey();
}
}
QUESTION 2
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 WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
double length = double.Parse(textBox1.Text);
double width = double.Parse(textBox2.Text);
double result;

if (radioButton1.Checked)
result = length * width;
else if (radioButton2.Checked)
result = 2 * (length + width);
else
{
MessageBox.Show("Please select an option.");
return;
}

MessageBox.Show("Result: " + result);


}
}
}
QUESTION 3
using System;

class Area
{
public double Base { get; set; }
public double Height { get; set; }
public double Radius { get; set; }
}

class Triangle : Area


{
public double CalculateArea()
{
return 0.5 * Base * Height;
}
}

class Circle : Area


{
public double CalculateArea()
{
return Math.PI * Radius * Radius;
}
}

class Program
{
static void Main()
{
Triangle triangle = new Triangle();
Console.Write("Enter base of triangle: ");
triangle.Base = double.Parse(Console.ReadLine());

Console.Write("Enter height of triangle: ");


triangle.Height = double.Parse(Console.ReadLine());

Circle circle = new Circle();


Console.Write("Enter radius of circle: ");
circle.Radius = double.Parse(Console.ReadLine());

Console.WriteLine("Triangle Area: " + triangle.CalculateArea());


Console.WriteLine("Circle Area: " + circle.CalculateArea());
Console.ReadKey();
}
}
QUESTION 4
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{

double a = double.Parse(textBox1.Text);
double b = double.Parse(textBox2.Text);
double c = double.Parse(textBox3.Text);

double discriminant = b * b - 4 * a * c;
if (discriminant > 0)
{
double root1 = (-b + Math.Sqrt(discriminant)) / (2 * a);
double root2 = (-b - Math.Sqrt(discriminant)) / (2 * a);
textBox4.Text = root1.ToString();
textBox5.Text = root2.ToString();
}
else if (discriminant == 0)
{
double root = -b / (2 * a);
textBox4.Text = root.ToString();
textBox5.Text = "Same as Root1";
}
else
{
textBox4.Text = "No real solution";
textBox5.Text = "No real solution";
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
}
private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy