0% found this document useful (0 votes)
25 views6 pages

Spring 2024 - CS411 - 2

Uploaded by

javeriarizwan99
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)
25 views6 pages

Spring 2024 - CS411 - 2

Uploaded by

javeriarizwan99
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/ 6

CS411 – Visual Programming

Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

Instructions:

Please read the following instructions carefully before submitting assignment:

You need to use MS word document to prepare and submit the assignment on VU-LMS.

It should be clear that your assignment will not get any credit if:

 The assignment is submitted after due date.


 The assignment is not in the required format (doc or docx).
 The submitted assignment does not open or file is corrupt.

Objectives:

The objective of this assignment is to enhance the learning capabilities of the students about:

 Developing simple application using WPF XAML


 Using C# programming language with WPF XAML

If you have any confusion, you can send your query at [email protected]

Lectures Covered: 19 to 32

1
CS411 – Visual Programming
Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

Problem Statement:
You need to develop a WPF application (simple calculator) in C#.NET with the following
functional requirements:

1. You need to develop and design simple calculator (as shown in the figure above.) that has
three text boxes, three buttons, and labels using WPF XAML with file name
"MainWindow.xaml".

2. Write the C# code in file named " MainWindow.xaml.cs" that receive two integer numbers
form the users entered in first two textboxes and perform addition operation when "Add" button
is pressed and perform multiplication operation when "Multiply" button is pressed.

3. The application will also display Result of the entered values in textbox labeled as Result.

4. When "clear" button is pressed the values need to be disappear from the textboxes.

Instructions:
 At the top of application, you will write your own VU ID.
 If you didn’t use your own VU ID, you will get zero marks.
 Paste the screen shot of output at top of solution in word document, then paste code (XAML and
C#) of program. (Solution Template is given on page No 3 of this file)
 If you submit only the screen shot of the source code, you will get zero marks.

2
CS411 – Visual Programming
Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

Sample Output:

//Put screenshot of output here


1. Pressing "Add" button

2. Pressing "Multiply" button

//Put your XAML code (code of the MainWindow.xaml file) here

<Window x:Class="WpfCalculator.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Simple Calculator" Height="300" Width="400">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30*" />
<RowDefinition Height="30*" />
<RowDefinition Height="30*" />
<RowDefinition Height="100*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>

3
CS411 – Visual Programming
Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

<ColumnDefinition Width="100*" />


<ColumnDefinition Width="100*" />
<ColumnDefinition Width="100*" />
</Grid.ColumnDefinitions>

<Label Content="Number 1:" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Center"


VerticalAlignment="Center" />
<TextBox x:Name="txtNumber1" Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Right" />
<Label Content="Number 2:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center"
VerticalAlignment="Center" />
<TextBox x:Name="txtNumber2" Grid.Row="1" Grid.Column="1"
HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Right" />

<Button Content="Add" Grid.Row="2" Grid.Column="0" Click="btnAdd_Click"


HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button Content="Multiply" Grid.Row="2" Grid.Column="1" Click="btnMultiply_Click"
HorizontalAlignment="Center" VerticalAlignment="Center" />
<Button Content="Clear" Grid.Row="2" Grid.Column="2" Click="btnClear_Click"
HorizontalAlignment="Center" VerticalAlignment="Center" />

<Label Content="Result:" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center"


VerticalAlignment="Center" />
<TextBox x:Name="txtResult" Grid.Row="3" Grid.ColumnSpan="2" IsReadOnly="True"
TextAlignment="Right" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
</Window>

//Put your C# code (code of the MainWindow.xaml.cs file) here

using System;
using System.Windows;

namespace WpfCalculator

4
CS411 – Visual Programming
Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void btnAdd_Click(object sender, RoutedEventArgs e)


{
try
{
double num1 = double.Parse(txtNumber1.Text);
double num2 = double.Parse(txtNumber2.Text);

double result = num1 + num2;


txtResult.Text = result.ToString();
}
catch (FormatException)
{
MessageBox.Show("Please enter valid numbers.", "Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

private void btnMultiply_Click(object sender, RoutedEventArgs e)


{
try
{

5
CS411 – Visual Programming
Total Marks: 20
Assignment No. 02
Semester: Spring 2024 Due Date: June 24, 2024

double num1 = double.Parse(txtNumber1.Text);


double num2 = double.Parse(txtNumber2.Text);

double result = num1 * num2;


txtResult.Text = result.ToString();
}
catch (FormatException)
{
MessageBox.Show("Please enter valid numbers.", "Error", MessageBoxButton.OK,
MessageBoxImage.Error);
}
}

private void btnClear_Click(object sender, RoutedEventArgs e)


{
txtNumber1.Text = "";
txtNumber2.Text = "";
txtResult.Text = "";
}
}
}

You might also like