CS 411 Lab Manual Problems
CS 411 Lab Manual Problems
Prepared by
Bilal Bin Umar, Tutor/Instructor
Mid Term
11 Create a wpf application in C# XAML, with one button and one Text 17
Box, The Text box must have vertical scroll bars attached to it.
12 Create a html web page, use CSS to style the webpage, then 19
implement fade in function using Jquery.
1|Visual Programing
Lab 1
Problem Statement:
Write a C++ console program which reads the text file named VU.txt and prints all the text on
the console character by character.
Solution:
#include <iostream>
#include <fstream>
int main() {
char a = '-';
do {
a = f.get();
f.close();
} while (a!='x');
return 0;
2|Visual Programing
Lab 2
Problem Statement:
Write a C# program in Visual Studio: create an array of String type and initialize it with some
names, then print all the names on the console using for each loop.
Solution:
{
class Program
{
static void Main(string[] args)
{
string[] myarray = new string[]{ "Bilal", "Asad", "Saad",
"kamran" };
Console.ReadKey();
}
}
}
3|Visual Programing
Lab 3
Problem Statement:
Write a program in C# using Visual Studio: First create a Person class with Name and Age
properties, make another class named Student and inherit student class from person.
Student class has Student_Id and Student_Semester properties. Now create an instance of
student class in main and set all the properties then print it on the console.
Note: Create get set properties using C# language feature of creating properties.
Solution:
class Person {
private int m_id;
public int id {
get { return m_id; } set { m_id = value; }
}
private string m_name;
public string name {
get { return m_name; } set { m_name = value; }
}
}
class Student:Person {
private int s_id;
public int stdentid {
get { return s_id; }
set { s_id = value; }
}
private int s_semester;
public int semester {
get { return s_semester; } set { s_semester = value; }
} }
class Program
{
static void Main(string[] args)
{
Student s1 = new Student();
s1.id = 1;
s1.name = "Umar";
s1.stdentid = 10;
s1.semester = 3;
Console.WriteLine("ID:{0},Name:{1},Student ID:{2},Semester:{3}",
s1.id,s1.name,s1.stdentid,s1.semester);
Console.ReadKey();
} }
4|Visual Programing
Lab 4
Problem Statement:
Write a Program in WPF using Visual Studio: Which have two buttons Button 1 and Button 2 .
Clicking Button 1 will show a MessageBox printing Button 1 is clicked same for Button 2
MessageBox will be shown with button 2 cliked Message.
Solution:
XAML:
<Grid>
<Button x:Name="button" Content="Button 1" HorizontalAlignment="Left"
Margin="92,54,0,0" VerticalAlignment="Top" Width="75" Click="button_Click"/>
<Button x:Name="button1" Content="Button 2" HorizontalAlignment="Left"
Margin="295,54,0,0" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
</Grid>
C#:
5|Visual Programing
Lab 5
Problem Statement:
Design the following Layout in WPF XAML using StackPanel. With TextBlock at the top and 4
Buttons after the TextBlock.
Solution:
XAML:
<StackPanel>
<TextBlock Margin="10" FontSize="20">In which University Do you Study?
</TextBlock>
<Button Margin="10">Virtual University of Pakistan </Button>
<Button Margin="10">UET lahore</Button>
<Button Margin="10">Punjab University</Button>
<Button Margin="10">Comsats</Button>
</StackPanel>
Lab 6
6|Visual Programing
Problem Statement:
Design the following Layout in WPF XAML using StackPanel With 6 buttons in it.
Clicking Collapse button will set the visibility of button 2 to collapse. Same for the hidden and
visible button these buttons will set the visibility of button2.
Solution:
XAML:
<StackPanel>
<Button x:Name="button" Content="Button 1" />
<Button x:Name="button1" Content="Button 2"/>
<Button x:Name="button2" Content="Button 3"/>
<Button x:Name="button3" Content="Collapse" Click="button3_Click"/>
<Button x:Name="button4" Content="Hidden" Click="button4_Click"/>
<Button x:Name="button5" Content="Visible" Click="button5_Click"/>
</StackPanel>
C# Code:
7|Visual Programing
}
Lab 7
8|Visual Programing
Problem Statement:
Design the following layout in WPF with one listBox and one Button.
Now create a single Event Handler for Both the controls, clicking the button will show a
messageBox that button is clicked and clicking a list item will show a MessageBox with selected
list item content.
Solution:
XAML:
<Grid>
<ListBox x:Name="listBox" HorizontalAlignment="Left" Height="100"
Margin="113,69,0,0" VerticalAlignment="Top" Width="100" SelectionChanged="EventHandler">
<ListBoxItem Content="First"/>
<ListBoxItem Content="Second" />
<ListBoxItem Content="Third"/>
<ListBoxItem Content="Fourth"/>
</ListBox>
<Button x:Name="button" Content="Button" HorizontalAlignment="Left"
Margin="113,206,0,0" VerticalAlignment="Top" Width="75"
RenderTransformOrigin="0.024,0.436" Click="EventHandler"/>
</Grid>
C# code:
9|Visual Programing
MessageBox.Show("Button is CLicked");
} else if (e.RoutedEvent==ListBox.SelectionChangedEvent) {
SelectionChangedEventArgs sce = (SelectionChangedEventArgs)e;
if (sce.AddedItems.Count > 0) {
MessageBox.Show("Selected item is" + sce.AddedItems[0]);
}
}
10 | V i s u a l P r o g r a m i n g
Lab 8
Problem Statement:
Create a wpf application in C# and XAML, add an image on the canvas in xaml. Now handle
move, rotate and zoom events in c# using Delta manipulation on Touch Enabled devices.
Solution:
XAML:
</Image>
</Canvas>
11 | V i s u a l P r o g r a m i n g
C# Code:
}
}
}
12 | V i s u a l P r o g r a m i n g
Lab 9
Problem Statement:
Create a wpf application in XAML, First add 5 buttons and one TextBox inside a Stackpanel
Horizontally.
Now use TextBox’s built in command bindings to implement cut, copy , paste ,redo and undo
Commands.
Note: No C# code will be written, only write code in XAML file to implements the commands.
Solution :
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF CommandBindings" Height="300" Width="400">
<Grid>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center"
HorizontalAlignment="Center">
13 | V i s u a l P r o g r a m i n g
14 | V i s u a l P r o g r a m i n g
Lab 10
Problem Statement:
Create a wpf application in C# XAML, with 2 textBoxes , one button and one progress bar.
Clicking update button will start updating the progress bar 1 % per second i.e. it will take 100
seconds for progress bar to reach 100. But the other UI elements two textboxes for example
must remain responsive in between the process.
Solution:
XAML:
<Grid>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23"
Margin="251,77,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"
Width="120"/>
<TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="23"
Margin="251,124,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"
Width="120"/>
<Button x:Name="button" Content="Update" HorizontalAlignment="Left"
Margin="251,178,0,0" VerticalAlignment="Top" Width="120" Click="button_Click"/>
<ProgressBar Name="progressbar" HorizontalAlignment="Left" Height="16"
Margin="251,218,0,0" VerticalAlignment="Top" Width="120" />
</Grid>
C# code:
15 | V i s u a l P r o g r a m i n g
private void button_Click(object sender, RoutedEventArgs e)
{
updateProgressbar();
}
public async void updateProgressbar() {
for (int i = 0; i <= 100; i++)
{
progressbar.Value = i;
await Task.Delay(1000);
} }
16 | V i s u a l P r o g r a m i n g
Lab 11
Problem Statement:
Create a wpf application in C# XAML, with one button and one Text Box, The Text box must
have vertical scroll bars attached to it.
Clicking Start Button will start the loop which will write the loop values in the Text Box. And
scroll bar will automatically scroll down to latest values.
Solution:
XAML:
<Grid>
<Button x:Name="button" Content="Start" HorizontalAlignment="Left"
Margin="208,263,0,0" VerticalAlignment="Top" Width="76" Click="button_Click"/>
<TextBox Name="myTextBox"
Width="120" Height="150"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.CanContentScroll="True">
</TextBox>
</Grid>
17 | V i s u a l P r o g r a m i n g
C# Code:
18 | V i s u a l P r o g r a m i n g
Lab 12
Problem Statement:
Create a html web page, use CSS to style the webpage, then implement fade in function using
Jquery.
Solution:
HTML:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{
background-color:black;
color :white;
}
h1{
color:yellow;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("h1").click(function(){
$("body").hide().fadeIn(3000);
});
});
</script>
</head>
<body>
19 | V i s u a l P r o g r a m i n g
<h1>If you click on me, Everything will fade in</h1>
<div>
The iPhone 7 and 7 Plus are deeply unusual devices. They are full of aggressive breaks from
convention while wrapped in cases that look almost exactly like their two direct predecessors. Even that
continuity of design is a break from convention; after almost a decade of Apple’s steady two-year iPhone
update pattern, merely retaining the same design for a third straight year plays against expectations.
Inside that case, everything else about the iPhone 7 is a decisive statement about the future. The dual
cameras on the iPhone 7 Plus promise to usher in a new era in mobile photography. The iconic iPhone
home button is no longer a physical button, but instead a sophisticated ballet of pressure sensors and
haptic vibration motors that simulate the feel of a button. The new A10 Fusion processor blends two
high-power cores that rival laptop performance with two low-power cores that combine with a much
larger battery to extend run time by up to two hours.
</body>
</html>
20 | V i s u a l P r o g r a m i n g