Lab Manual - V BCA B
Lab Manual - V BCA B
PART-A
classProgram
{ staticvoid Main(string[] args)
{
intmyNum = 5; // integer (whole number)
doublemyDoubleNum = 5.99D; // floating point number
charmyLetter = 'D'; // character
boolmyBool = true; // boolean
stringmyText = "Hello"; // string
Console.WriteLine(myNum);
Console.WriteLine(myDoubleNum);
Console.WriteLine(myLetter);
Console.WriteLine(myBool);
Console.WriteLine(myText);
Console.ReadKey();
}
}
2. Write a Program in C# to demonstrate Command line arguments
processing.
classProg2
{
staticvoid Main(string[] args)
{
Console.WriteLine("CommandLinearguements");
Console.WriteLine();
For (inti=0; i<args.Length; i++)
{
Console.WriteLine("Arg:{0}", args[i]);
}
Console.ReadLine();
using System;
usingSystem.Collections;
usingSystem.Linq;
usingSystem.Text;
{
class Class1
{
static void Main(string[] args)
{
(i)
class Program
Console.WriteLine("Good morning.");
}
else if (time < 20)
Console.WriteLine("Good day.");
else
Console.WriteLine("Good evening.");
Console.ReadLine();
int day = 4;
switch (day)
case 1:
Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
case 4:
Console.WriteLine("Thursday");
break;
case 5:
Console.WriteLine("Friday");
break;
case 6:
Console.WriteLine("Saturday");
break;
case 7:
Console.WriteLine("Sunday");
break;
Console.ReadLine();
}
(iii)
classClass2
{
staticvoid Main(string[] args)
{
int time= Convert.ToInt32(Console.ReadLine());
string result = (time < 18) ? "Good day." :"Good evening.";
Console.WriteLine(result);
Console.ReadLine();
}
}
(i) classbreak1
{
staticvoid Main(string[] args)
{
int a =Convert.ToInt32(Console.ReadLine());
if (a > 15) {
/* terminate the loop using break statement */
break;
}
}
Console.ReadLine();
}
}
(ii) classcontinue1
{
staticvoid Main(string[] args)
{
int a = 10;
/* do loop execution */
do {
if (a == 15) {
/* skip the iteration */
a = a + 1;
continue;
}
Console.WriteLine("value of a: {0}", a);
a++;
}
while (a < 20);
Console.ReadiLine();
}
}
(iii)
class Program
Console.WriteLine(i);
Console.ReadLine();
}
classReverse
{
staticvoid Main(string[] args)
{
String myStr, rev;
rev = "";
myStr=Console.ReadLine();
Console.WriteLine("String is {0}", myStr);
// find string length
intlen;
len = myStr.Length - 1;
while (len>= 0)
{
rev = rev + myStr[len];
len--;
}
Console.WriteLine("Reversed String is {0}", rev);
Console.ReadLine();
}
}
classClass3
{
staticvoid Main(string[] args)
{
string[] cars = newstring[4];
for (inti = 0; i<cars.Length; i++)
{
Console.Write("\tElement[" + i + "]: ");
cars[i] = Console.ReadLine();
}
for (inti = 0; i<cars.Length; i++)
{
Console.WriteLine(cars[i]);
}
Console.ReadLine();
}
}
(i) Searching
classSearching
{
publicstaticvoid Main()
{
int[] a = newint[100];
int flag = 0;
//intpos = 0;
Console.WriteLine("Enter number of elements you want to hold in
the array ?");
int x = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("-------------------------");
Console.WriteLine("\n Enter array elements \n");
for (inti = 0; i < x; i++)
{
a[i] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("-------------------------");
Console.WriteLine("Enter Search element\n");
int x2 = Convert.ToInt32(Console.ReadLine());
for (inti = 0; i < x; i++)
{
if (a[i] == x2)
{
Console.WriteLine("-------------------------");
Console.WriteLine("Search successful");
Console.WriteLine("Element{0} found at locationn{1}\n",x2,i+1);
flag++;
break;
}
}
if (flag == 0)
{
Console.WriteLine("Search unsuccessful");
}
Console.ReadLine();
}
}
(ii) Sorting
class sorting
{
class Program
{
static void Main(string[] args)
{
// Sort a string
string [] college = {"Reva", "CMR", "BMS", "New Horizon"};
Array.Sort(college);
foreach (string i in college)
{
Console.WriteLine(i);
}
// Sort an int
int [] myNumbers = { 5, 1, 8, 9 };
Array.Sort(myNumbers);
foreach (inti in myNumbers)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}
9. Write a Program in C# to find the second largest element in single
dimensional arrays.
class Program
Array.Reverse(array);
using System;
public class Student
{
public int id;
public String name;
}
class TestStudent{
public static void Main(string[] args)
{
Student s1 = new Student();
s1.id = 101;
s1.name = "Sonoo Jaiswal";
Console.WriteLine(s1.id);
Console.WriteLine(s1.name);
PART B
1. Develop graphical user interfaces for C# programs using GUI components such
as labels, buttons, text boxes, radio button and check boxes
2. Use the C# event-handling model to respond to events arising from the GUI
components
PART B
1. Develop graphical user interfaces for C# programs using GUI components such as labels, buttons, text
boxes, radio button and check boxes
Form Design
Change the Properties of the controls as follows
Labels
Label1
Text=SRN No
Label2
Text= Name
Label3
Text=Mobile No
Label4
Text=Email ID
Label5
Text=Course
TextBoxes
Textbox1
Name=txtsrn
Textbox2
Name=txtname
Textbox3
Name=txtmobile
Textbox4
Name=txtemail
Combobox
Name=combocourse
Add Items to the combobox using items property
Items: BCA, BBA,BCom, MCA, MBA
Controls Properties Value
GroupBox1 Text Personal Details
Label1 Text SRN No
Label 2 Text Name
Label 3 Text Mobile No
Label 4 Text Email ID
Label 5 Text Course
Textbox1 Name txtsrn
Textbox2 Name txtname
Textbox3 Name txtmobile
Textbox4 Name txtemail
Combobox Name combocourse
Combobox Items Add Items: BCA, BSc, BBA, BCom, MSc, MCA, MBA,
Button1 Text My Details
GroupBox2 Text What Type of Movie Do You Like?
Checkbox1 Text Comedy
Checkbox2 Text Action
Checkbox3 Text Science Fiction
Checkbox4 Text Animation
Button2 Text Select Movie
GroupBox3 Text And Your Favorite Is?
Radio Button1 Text Comedy
Radio Button2 Text Action
Radio Button3 Text Science Fiction
Radio Button4 Text Animation
Button3 Text My Favorite Movie
Code:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCheckbox_and_Radio_Button
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
if (radioButton1.Checked)
{
ChosenMovie = radioButton1.Text;
}
if (radioButton2.Checked)
{
ChosenMovie = radioButton2.Text;
}
if (radioButton3.Checked)
{
ChosenMovie = radioButton3.Text;
}
if (radioButton4.Checked)
{
ChosenMovie = radioButton4.Text;
}
MessageBox.Show(ChosenMovie);
}
}
}
2. Use the C# event-handling model to respond to events arising from the GUI components
Form Design
Code:
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceKeyoard_and_Mouse_Events
{
publicpartialclassForm1 : Form
{
public Form1()
{
InitializeComponent();
}
}
privatevoid button1_MouseLeave(object sender, EventArgs e)
{
button1.Height -= 30;
button1.Width -= 30;
button1.Top += 15;
button1.Left += 15;
}
}
}