This tutorial will teach how to make a Student Grade Calculation in C#.net. Input the studentname and avg marks to calcuate the grade.
if the average is > 50 – Pass otherwise fail
First you have design the Calculator.
MainWindow.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | <Window x:Class="StudentMarksApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:StudentMarksApp" mc:Ignorable="d" Title="Student Marks Calculation App" Height="350" Width="380"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="25"/> <RowDefinition Height="*"/> <RowDefinition Height="5"/> </Grid.RowDefinitions> <StackPanel Grid.Column="1" Grid.Row="1"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="100"/> <ColumnDefinition Width="250"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="25"/> <RowDefinition Height="5"/> <RowDefinition Height="25"/> <RowDefinition Height="5"/> <RowDefinition Height="25"/> <RowDefinition Height="5"/> <RowDefinition Height="25"/> <RowDefinition Height="5"/> <RowDefinition Height="25"/> <RowDefinition Height="5"/> <RowDefinition Height="25"/> <RowDefinition Height="10"/> </Grid.RowDefinitions> <Label Content="Marks 1 :" Grid.Row="0" Grid.Column="0" /> <TextBox x:Name="TextBoxMarks1" Grid.Row="0" Grid.Column="1" /> <Label Content="Marks 2 :" Grid.Row="2" Grid.Column="0" /> <TextBox x:Name="TextBoxMarks2" Grid.Row="2" Grid.Column="1" /> <Label Content="Marks 3 :" Grid.Row="4" Grid.Column="0" /> <TextBox x:Name="TextBoxMarks3" Grid.Row="4" Grid.Column="1" /> <Label Content="Total :" Grid.Row="6" Grid.Column="0" /> <TextBox x:Name="TextBoxTotal" Grid.Row="6" Grid.Column="1" /> <Label Content="Avg :" Grid.Row="8" Grid.Column="0" /> <TextBox x:Name="TextBoxAvg" Grid.Row="8" Grid.Column="1" /> <Label Content="Grade :" Grid.Row="10" Grid.Column="0" /> <TextBox x:Name="TextBoxGrade" Grid.Row="10" Grid.Column="1" /> </Grid> <StackPanel Grid.Row="16" Grid.ColumnSpan="2" Orientation="Horizontal"> <Button Width="50" Content="Cal" x:Name="ButtonCal" Margin="10 0 10 0" Click="ButtonCal_Click" Background="#FF04097E" Foreground="White"/> <Button Width="50" Content="Clear" x:Name="ButtonClear" Margin="10 0 10 0" Click="ButtonClear_Click" Background="#FF04097E" Foreground="White" /> </StackPanel> </StackPanel> </Grid> </Window> |
MainWindow.xaml.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); ButtonCal.Click += ButtonCal_Click; ButtonClear.Click += ButtonClear_Click; } private void ButtonClear_Click(object sender, RoutedEventArgs e) { TextBoxMarks1.Text = ""; TextBoxMarks2.Text = ""; TextBoxMarks3.Text = ""; TextBoxTotal.Text = ""; TextBoxGrade.Text = ""; TextBoxAvg.Text = ""; TextBoxMarks1.Focus(); } private void ButtonCal_Click(object sender, RoutedEventArgs e) { double marks1, marks2, marks3, tot, avg; string grade; marks1 = double.Parse(TextBoxMarks1.Text); marks2 = double.Parse(TextBoxMarks2.Text); marks3 = double.Parse(TextBoxMarks3.Text); tot = marks1 + marks2 + marks3; TextBoxTotal.Text = tot.ToString(); avg = tot / 3; TextBoxTotal.Text = tot.ToString(); TextBoxAvg.Text = avg.ToString(); if(avg > 50) { grade = "Pass"; } else { grade = "Fail"; } TextBoxGrade.Text = grade; } } |
i have attached the video link below. which will do this tutorials step by step.