Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 15

SIES College of Management Studies FYMCA (Revised), Sem II,

Roll No: 24

Practical No: 3
Topic: Design Applications using Inheritance and Abstract Classes
Q1)Create a Windows forms application to book vehicles (2 wheelers/4 seaters/7
seaters/buses) using inheritance. The program should be capable of displaying
the cost of booking based on chosen vehicle and the km to travel. Design an
appropriate GUI.
Code:
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 Practical3A
{
public partial class Form1 : Form
{
int cost;
public Form1()
{
InitializeComponent();
}

class vehicle{
public int costcalculate(int dist, int cost) {
return (dist * cost);
}
}

class bike : vehicle


{
public int cost = 90;

class fourSeater : vehicle


{
public int cost = 170;
}
class sevenSeater : vehicle
{
public int cost = 270;
}

class bus : vehicle


{
public int cost = 400;
}

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)


{
if (!Char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
e.Handled = true;
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{
if (!Char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
e.Handled = true;
}

private void button3_Click(object sender, EventArgs e)


{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text
== "" || comboBox1.SelectedItem == null)
{
MessageBox.Show("Please enter all the values.");
}
else {
if(comboBox1.SelectedIndex == 0)
{
bike b = new bike();
cost = b.costcalculate(Int32.Parse(textBox1.Text),
b.cost);
richTextBox1.Text = "Name:" + textBox2.Text +
"\t\nPhone No:" + textBox3.Text + "\t\nVehicle
Type:"+comboBox1.Text+"\t\nDistance(Km):"+textBox1.Text+"\t\nCost(Rs.):"+co
st;
}
if (comboBox1.SelectedIndex == 1)
{
fourSeater b = new fourSeater();
cost = b.costcalculate(Int32.Parse(textBox1.Text),
b.cost);
richTextBox1.Text = "Name:" + textBox2.Text +
"\t\nPhone No:" + textBox3.Text + "\t\nVehicle Type:" + comboBox1.Text +
"\t\nDistance(Km):" + textBox1.Text + "\t\nCost(Rs.):" + cost;
}
if (comboBox1.SelectedIndex == 2)
{
sevenSeater b = new sevenSeater();
cost = b.costcalculate(Int32.Parse(textBox1.Text),
b.cost);
richTextBox1.Text = "Name:" + textBox2.Text +
"\t\nPhone No:" + textBox3.Text + "\t\nVehicle Type:" + comboBox1.Text +
"\t\nDistance(Km):" + textBox1.Text + "\t\nCost(Rs.):" + cost;
}
if (comboBox1.SelectedIndex == 3)
{
bus b = new bus();
cost = b.costcalculate(Int32.Parse(textBox1.Text),
b.cost);
richTextBox1.Text = "Name:" + textBox2.Text +
"\t\nPhone No:" + textBox3.Text + "\t\nVehicle Type:" + comboBox1.Text +
"\t\nDistance(Km):" + textBox1.Text + "\t\nCost(Rs.):" + cost.ToString();

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

}
}
}

private void button1_Click(object sender, EventArgs e)


{
textBox3.Clear();
textBox1.Clear();
textBox2.Clear();
richTextBox1.Clear();
comboBox1.SelectedItem = null;
cost = 0;
}

private void button2_Click(object sender, EventArgs e)


{
MessageBox.Show ( "Name:" + textBox2.Text + "\t\nPhone No:" +
textBox3.Text + "\t\nVehicle Type:" + comboBox1.Text + "\t\nDistance(Km):"
+ textBox1.Text + "\t\nCost(Rs.):" + cost.ToString());
comboBox1.SelectedItem = null;
textBox3.Clear();
textBox1.Clear();
textBox2.Clear();
}
}
}
Output:

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

Q2)Create an abstract class shape that defines an abstract method area. Derive
classes circle, rectangle, square, triangle from it to calculate the area of the various
figures. Design an appropriate GUI.
Code:
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 Practical3B
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public abstract class Shape {
abstract public double area();
}

class Circle : Shape


{
double pi = 3.14;
public double radious;
public override double area()
{
return this.pi * this.radious * this.radious ;
}
}

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

class Square : Shape


{
public double side;
public override double area()
{
return this.side * this.side;
}
}

class Rectangle : Shape


{
public double length;
public double width;
public override double area()
{
return this.length * this.width;
}
}

class Triangle : Shape


{
public double base1;
public double height;
public override double area()
{
return 0.5 * this.height * this.base1;
}
}

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox3_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox4_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

{
e.Handled = true;
}
}

private void textBox5_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox6_KeyPress(object sender, KeyPressEventArgs e)


{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar != (char)Keys.Back))
{
e.Handled = true;
}
}

private void comboBox1_SelectedIndexChanged(object sender,


EventArgs e)
{
if (comboBox1.SelectedItem == null) {
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =
textBox4.Enabled = textBox5.Enabled = textBox6.Enabled = false;
textBox1.Text = textBox2.Text = textBox3.Text =
textBox4.Text = textBox5.Text = textBox6.Text = null;

}
if (comboBox1.SelectedIndex == 0) {
textBox1.Enabled = true;
textBox2.Enabled = textBox3.Enabled = textBox4.Enabled =
textBox5.Enabled = textBox6.Enabled = false;
textBox2.Text = textBox3.Text = textBox4.Text =
textBox5.Text = textBox6.Text = null;
}
if (comboBox1.SelectedIndex == 1)
{
textBox2.Enabled = true;
textBox1.Enabled = textBox3.Enabled = textBox4.Enabled =
textBox5.Enabled = textBox6.Enabled = false;
textBox1.Text = textBox3.Text = textBox4.Text =
textBox5.Text = textBox6.Text = null;
}
if (comboBox1.SelectedIndex == 2)
{
textBox3.Enabled = textBox4.Enabled = true;
textBox1.Enabled = textBox2.Enabled = textBox5.Enabled =
textBox6.Enabled = false;
textBox1.Text = textBox2.Text = textBox5.Text =
textBox6.Text = null;
}
if (comboBox1.SelectedIndex == 3)
{
textBox5.Enabled = textBox6.Enabled = true;

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =


textBox4.Enabled = false;
textBox1.Text = textBox2.Text = textBox3.Text =
textBox4.Text = null;
}
}

private void button2_Click(object sender, EventArgs e)


{
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =
textBox4.Enabled = textBox5.Enabled = textBox6.Enabled = false;
comboBox1.SelectedItem = null;
richTextBox1.Clear();
}

private void Form1_Load(object sender, EventArgs e)


{
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =
textBox4.Enabled = textBox5.Enabled = textBox6.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)


{
if(comboBox1.SelectedItem == null)
{
MessageBox.Show("Select the shape and enter esential
values!");
}
if(comboBox1.SelectedIndex == 0 && textBox1.Text != null)
{
Circle c = new Circle();
c.radious = Int32.Parse(textBox1.Text);
double a = c.area();
richTextBox1.Text = "Area of the Circle With a radius of:"
+ textBox1.Text + "cm.\t\n is: "+ a;

}
if (comboBox1.SelectedIndex == 1 && textBox2.Text != null)
{
Square c = new Square();
c.side = Int32.Parse(textBox2.Text);
double a = c.area();
richTextBox1.Text = "Area of the Square With a side of:" +
textBox2.Text + "cm.\t\n is: " + a;

}
if (comboBox1.SelectedIndex == 2 && textBox3.Text != null &&
textBox4.Text != null)
{
Rectangle c = new Rectangle();
c.length = Int32.Parse(textBox3.Text);
c.width = Int32.Parse(textBox4.Text);
double a = c.area();
richTextBox1.Text = "Area of the Rectangle With a Length
of:" + textBox3.Text + "cm. \t\nand width of: " + textBox4.Text + "
\t\nis:" + a;

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

}
if (comboBox1.SelectedIndex == 3 && textBox5.Text != null &&
textBox6.Text != null)
{
Triangle c = new Triangle();
c.base1 = Int32.Parse(textBox5.Text);
c.height = Int32.Parse(textBox6.Text);
double a = c.area();
richTextBox1.Text = "Area of the Triangle With a base of:"
+ textBox5.Text + "cm. \t\nand height of: " + textBox6.Text + " \t\nis:" +
a;
}
}
}
}

Output:

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

Q3)Design anInterest_Calculatorclass and Link it to GUI. Provide calculation facilities


for
a) Simple Interest
b) Compound Interest
Make use of interfaces in the above application and design an appropriate
GUI.
Code:
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 Practical3C
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

interface calculateInterest {
public double calculate();
}

class simpleInterest : calculateInterest {


public double amount;
public double time;
public double inRate;
public double calculate() {
return (this.amount * this.time * this.inRate)/100;
}
}

class compoundInterest : calculateInterest


{
public double amount;
public double time;
public double inRate;
public double no;
public double calculate()
{
double power = (this.no * this.time);

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

double body = (1 + (this.inRate / (this.no * 100)));


double a = (amount * Math.Pow(body, power));
return (a - amount);
}
}

private void textBox1_KeyPress(object sender,


KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar !=
(char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox2_KeyPress(object sender,


KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar !=
(char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox3_KeyPress(object sender,


KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar !=
(char)Keys.Back))
{
e.Handled = true;
}
}

private void textBox4_KeyPress(object sender,


KeyPressEventArgs e)
{
if (!char.IsDigit(e.KeyChar) && (e.KeyChar !=
(char)Keys.Back))
{
e.Handled = true;
}
}

private void comboBox1_SelectedIndexChanged(object sender,


EventArgs e)
{
if (comboBox1.SelectedItem == null)
{

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

textBox1.Enabled = textBox2.Enabled =
textBox3.Enabled = textBox4.Enabled = false;
textBox1.Text = textBox2.Text = textBox3.Text =
textBox4.Text = null;

}
if (comboBox1.SelectedIndex == 0)
{
textBox2.Enabled = textBox3.Enabled =
textBox1.Enabled = true;
textBox4.Enabled = false;
textBox4.Text = null;
}
if (comboBox1.SelectedIndex == 1)
{
textBox1.Enabled = textBox3.Enabled =
textBox4.Enabled = textBox2.Enabled = true;
}
}

private void button2_Click(object sender, EventArgs e)


{
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
richTextBox1.Clear();
comboBox1.SelectedItem = null;
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =
textBox4.Enabled = false;
}

private void button1_Click(object sender, EventArgs e)


{
if(comboBox1.SelectedIndex == 0 && textBox1.Text != null
&& textBox2.Text != null && textBox3.Text != null)
{
simpleInterest s = new simpleInterest();
s.amount = Int32.Parse(textBox1.Text);
s.inRate = Int32.Parse(textBox2.Text);
s.time = Int32.Parse(textBox3.Text);
double ans = s.calculate();
richTextBox1.Text = "Priciple: " + textBox1.Text +
"\t\nRate of interest: " + textBox2.Text + "\t\nTime:
"+textBox3.Text+ "\t\nSimple Interest: "+ans ;

}
if (comboBox1.SelectedIndex == 1 && textBox1.Text !=
null && textBox2.Text != null && textBox3.Text != null &&
textBox4.Text != null)
{
compoundInterest s = new compoundInterest();
Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

s.amount = Int32.Parse(textBox1.Text);
s.inRate = Int32.Parse(textBox2.Text);
s.time = Int32.Parse(textBox3.Text);
s.no = Int32.Parse(textBox4.Text);
double ans = s.calculate();
richTextBox1.Text = "Priciple: " + textBox1.Text +
"\t\nRate of interest: " + textBox2.Text + "\t\nTime: " +
textBox3.Text + "\t\nNo of time amount is compounded: " +
textBox4.Text+"\t\nCumpound Interest: " + ans;

}
}

private void Form1_Load(object sender, EventArgs e)


{
textBox1.Enabled = textBox2.Enabled = textBox3.Enabled =
textBox4.Enabled = false;
}
}
}

Output:

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21
SIES College of Management Studies FYMCA (Revised), Sem II,
Roll No: 24

Subject: MCAL24 Advanced Web Technology Lab Academic Year Second Half 2020_21

You might also like