0% found this document useful (0 votes)
75 views10 pages

Task 1: Faiqa Mehboob BSE-2016-O32

The document contains code for three tasks related to creating a calculator application using C# and Windows Forms. Task 1 defines the logic and event handlers for buttons to perform basic mathematical operations in a calculator interface. Task 2 adds functionality to calculate GPA based on entered course credits and marks, then display the calculated GPA and grade. Task 3 adds a login screen to the application that disables the login fields after three incorrect attempts.

Uploaded by

Faiqa mehboob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views10 pages

Task 1: Faiqa Mehboob BSE-2016-O32

The document contains code for three tasks related to creating a calculator application using C# and Windows Forms. Task 1 defines the logic and event handlers for buttons to perform basic mathematical operations in a calculator interface. Task 2 adds functionality to calculate GPA based on entered course credits and marks, then display the calculated GPA and grade. Task 3 adds a login screen to the application that disables the login fields after three incorrect attempts.

Uploaded by

Faiqa mehboob
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

FAIQA MEHBOOB

BSE-2016-O32

Lab#6
Task 1
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 WindowsFormsApplication6
{
public partial class Form1 : Form
{
double num, ans,x;
char c;
int count;
bool anstemp;

public void enable()


{
button1.Enabled = true;
button2.Enabled = true;
button3.Enabled = true;
button4.Enabled = true;
button5.Enabled = true;
button6.Enabled = true;
button7.Enabled = true;
button8.Enabled = true;
button9.Enabled = true;
button10.Enabled = true;
button11.Enabled = true;
button12.Enabled = true;
button13.Enabled = true;
button14.Enabled = true;
button15.Enabled = true;
button16.Enabled = true;
button17.Enabled = true;
button18.Enabled = true;
button19.Enabled = true;
button20.Enabled = true;
button21.Enabled = true;
button22.Enabled = true;
button23.Enabled = true;
button24.Enabled = true;
button25.Enabled = true;
button26.Enabled = true;
button27.Enabled = true;
button28.Enabled = true;
}
FAIQA MEHBOOB
BSE-2016-O32
public void disable()
{
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
button6.Enabled = false;
button7.Enabled = false;
button8.Enabled = false;
button9.Enabled = false;
button10.Enabled = false;
button11.Enabled = false;
button12.Enabled = false;
button13.Enabled = false;
button14.Enabled = false;
//button15.Enabled = false;
button16.Enabled = false;
button17.Enabled = false;
button18.Enabled = false;
button19.Enabled = false;
button20.Enabled = false;
button21.Enabled = false;
button22.Enabled = false;
button23.Enabled =false;
button24.Enabled = false;
button25.Enabled = false;
button26.Enabled = false;
button27.Enabled = false;
button28.Enabled = false;
}
public void compute() // calculate the result on basis of the button pressed
{
switch (count)
{
case 1:
ans = num + double.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 2:
ans = num - double.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 3:
ans = num * double.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 4:
ans = num / double.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
case 5:
ans = num * num;
FAIQA MEHBOOB
BSE-2016-O32
textBox1.Text = ans.ToString();
break;
case 6:
ans = num * num * num;
textBox1.Text = ans.ToString();
break;
case 7:
x = 1;
for (int i = 1; i <= double.Parse(textBox1.Text); i++)
{ x = x * num; }
ans = x;
textBox1.Text = ans.ToString();
break;
case 8:
anstemp = num > double.Parse(textBox1.Text);
textBox1.Text = anstemp.ToString();
break;
case 9:
anstemp = num < double.Parse(textBox1.Text);
textBox1.Text = anstemp.ToString();
break;
case 10:
ans = num % double.Parse(textBox1.Text);
textBox1.Text = ans.ToString();
break;
default:
break;
}
}

public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "1";
}

private void button2_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "2";
}

private void button3_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "3";
}

private void button4_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "4";
FAIQA MEHBOOB
BSE-2016-O32
}

private void button5_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "5";
}

private void button6_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "6";
}

private void button7_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "7";
}

private void button8_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "8";
}

private void button9_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "9";
}

private void button10_Click(object sender, EventArgs e)


{
textBox1.Text = textBox1.Text + "0";
}

private void button12_Click(object sender, EventArgs e)


{
// -button
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 2;
}
else
textBox1.Text = "-";

private void button17_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{ textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1, 1); }
else
textBox1.Clear();
FAIQA MEHBOOB
BSE-2016-O32
}

private void button11_Click(object sender, EventArgs e)


{
// +button
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 1;
}
else
textBox1.Text = "+";
}

private void button13_Click(object sender, EventArgs e)


{
compute();
}

private void button18_Click(object sender, EventArgs e)


{
// *button
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 3;
}
else
textBox1.Text = "*";
}

private void button19_Click(object sender, EventArgs e)


{
// /button
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 4;
}
else
textBox1.Text = "/";
}

private void button14_Click(object sender, EventArgs e)


{
textBox1.Clear();
}
FAIQA MEHBOOB
BSE-2016-O32

private void button15_Click(object sender, EventArgs e)


{
enable();
}

private void button16_Click(object sender, EventArgs e)


{
disable();
}

private void button25_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 9;
}
else
textBox1.Text = "<";

private void button24_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 8;
}
else
textBox1.Text = ">";
}

private void button26_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 5;
}
else
textBox1.Text = "x^2";
}

private void button27_Click(object sender, EventArgs e)


FAIQA MEHBOOB
BSE-2016-O32
{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 6;
}
else
textBox1.Text = "x^3";
}

private void button28_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 7;
}
else
textBox1.Text = "x^y";
}

private void button23_Click(object sender, EventArgs e)


{
if (textBox1.Text.Length != 0)
{
num = double.Parse(textBox1.Text);
textBox1.Clear();
textBox1.Focus();
count = 10;
}
else
textBox1.Text = "mod";
}
}
}

Task 2:

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;
FAIQA MEHBOOB
BSE-2016-O32
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
double credithours;
double marks;
double total;

public Form1()
{
InitializeComponent();
}

private void btnCalculate_Click(object sender, EventArgs e)


{
credithours = double.Parse(textBox6.Text) + double.Parse(textBox7.Text) + double.Parse(textBox8.Text) +
double.Parse(textBox9.Text) + double.Parse(textBox10.Text);
marks = (double.Parse(textBoxVP.Text) * double.Parse(textBox6.Text)) + (double.Parse(textBoxDB.Text) *
double.Parse(textBox7.Text)) + (double.Parse(textBoxISD.Text) * double.Parse(textBox8.Text)) +
(double.Parse(textBoxMC.Text) * double.Parse(textBox9.Text)) + (double.Parse(textBoxCEI.Text) *
double.Parse(textBox10.Text));
total = marks / credithours;
if (total >= 90)
{ MessageBox.Show("Your GPA IS 4 And Grade is A+"); }
if (total >= 85 & total <= 89)
{ MessageBox.Show("Your GPA IS 3.7 And Grade is A"); }
if (total >= 80 & total <= 84)
{ MessageBox.Show("Your GPA IS 3.5 And Grade is B+"); }
if (total >= 75 & total <= 79)
{ MessageBox.Show("Your GPA IS 3.0 And Grade is B"); }
if (total >= 70 & total <= 74)
{ MessageBox.Show("Your GPA IS 2.7 And Grade is B-"); }
if (total >= 65 & total <= 69)
{ MessageBox.Show("Your GPA IS 2.5 And Grade is C+"); }
if (total >= 60 & total <= 64)
{ MessageBox.Show("Your GPA IS 2.0 And Grade is C"); }
if (total >= 55 & total <= 59)
{ MessageBox.Show("Your GPA IS 1.7 And Grade is C-"); }
if (total >= 50 & total <= 54)
{ MessageBox.Show("Your GPA IS 1.5 And Grade is D"); }
if (total <= 50)
{ MessageBox.Show("Your GPA IS 1.3 And Grade is F"); }

private void btnInfo_Click(object sender, EventArgs e)


{
{
Form2 f = new Form2();
TextBox l = new TextBox();
l.Height = 40;
l.Width = 300;
l.Location = new Point(20, 150);
FAIQA MEHBOOB
BSE-2016-O32
l.Font = new Font("Georgia", 10);
l.Multiline = true;
this.Hide();
f.Show();
f.Controls.Add(l);
l.Text = "your name is... " + textBoxVP.Text;
l.Text =l.Text + " Your Semester is " + textBoxISD.Text;
}
}
}
}

Task 3

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 WindowsFormsApplication7
{
public partial class Form1 : Form
{
int count = 0;
public Form1()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)


{
{
if (textBox1.Text == "Sania" && textBox2.Text == "059")
{
Form1 f = new Form1();
this.Hide();
f.Show();
}
FAIQA MEHBOOB
BSE-2016-O32
if (textBox1.Text != "Sania" || textBox2.Text != "059")
{
count = count + 1;
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
textBox2.Focus();
}
if (count == 3)
{
textBox1.Enabled = false;
textBox2.Enabled = false;
MessageBox.Show("you exceed the time limit");
}

}}}

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