0% found this document useful (0 votes)
36 views19 pages

Lab Manual - V BCA B

The document outlines a BCA program for the year 2023-24, focusing on .NET programming with a series of C# programming exercises. It includes tasks such as solving problems using C# syntax, implementing command line arguments, stack operations, and GUI development using event-handling models. Additionally, it covers concepts like searching, sorting algorithms, and object-oriented programming with examples.

Uploaded by

pritiagrawal348
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)
36 views19 pages

Lab Manual - V BCA B

The document outlines a BCA program for the year 2023-24, focusing on .NET programming with a series of C# programming exercises. It includes tasks such as solving problems using C# syntax, implementing command line arguments, stack operations, and GUI development using event-handling models. Additionally, it covers concepts like searching, sorting algorithms, and object-oriented programming with examples.

Uploaded by

pritiagrawal348
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/ 19

School of Computer Science and Applications

Program Name: BCA Year: 2023-24


Subject Name: .NET Programming Course Code: B21CA5060
Sem: V

List of Programs Part A and Part B

PART-A

1. Solve simple problems using the fundamental syntax and semantics of


the C# programming language

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();

3. Write a program in C# to implement stack operations

using System;
usingSystem.Collections;
usingSystem.Linq;
usingSystem.Text;

{
class Class1
{
static void Main(string[] args)
{

Stack s = new Stack();


s.Push(1);
s.Push(2);
s.Push(3);
s.Push(4);
Console.WriteLine("Original Stack: ");
foreach (int i in s)
{
Console.WriteLine(i);
}
s.Pop();
s.Pop();
s.Pop();
Console.WriteLine("Stack after Pop() operation: ");
foreach (inti in s)
{
Console.WriteLine(i);
}
Console.ReadLine();
}
}
}

4. Write C# programs that use selection (if, switch, conditional operator)

(i)

class Program

static void Main(string[] args)

int time = 22;

if (time < 10)

Console.WriteLine("Good morning.");

}
else if (time < 20)

Console.WriteLine("Good day.");

else

Console.WriteLine("Good evening.");

Console.ReadLine();

(ii) class Program

static void Main(string[] args)

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();
}
}

5. Write C# programs that use loops (while, do while, for)

(i) classbreak1
{
staticvoid Main(string[] args)
{

int a =Convert.ToInt32(Console.ReadLine());

/* while loop execution */


while (a < 20) {
Console.WriteLine("value of a: {0}", a);
a++;

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

static void Main(string[] args)

for (inti = 0; i < 5; i++)

Console.WriteLine(i);

Console.ReadLine();
}

6. Write a program to reverse a given string using C#

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();

}
}

7. Write C# programs that use one-dimensional arrays.

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();
}
}

8. Apply simple searching and sorting algorithms

(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

{ public static void Main()

int[] array = {2, 11, 15, 1, 7, 99, 6, 85, 4 };

Array.Sort(array); //sorting array

Array.Reverse(array);

Console.WriteLine("Second Highest Value in Array "+array[1]);

foreach (var result in array)

{ Console.Write(result + " "); // Array values

10. Write programs in C# to demonstrate boxing and unboxing


classboxing-unboxing
{
staticvoid Main(string[] args)
{
inti = 123;
object o = i;
int j = (int)o;
Console.WriteLine("The value-type value = {0}", i);
Console.WriteLine("The object-type value = {0}", o);
Console.WriteLine("The object-type changed value = {0}", j);
Console.ReadLine();
}
}
11. Write simple objectusing IDEAS to IPR oriented programs objects and
classes in c#.

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();
}

privatevoid button1_Click(object sender, EventArgs e)


{
string movies = "";
if (checkBox1.Checked)
{
movies = movies + checkBox1.Text+Environment.NewLine;
}
if (checkBox2.Checked)
{
movies = movies + checkBox2.Text+Environment.NewLine;
}
if (checkBox3.Checked)
{
movies = movies + checkBox3.Text+Environment.NewLine;
}
if (checkBox4.Checked)
{
movies = movies + checkBox4.Text + Environment.NewLine;
}
MessageBox.Show(movies);
}

privatevoid button2_Click(object sender, EventArgs e)


{
stringChosenMovie = "";

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);
}

privatevoid button3_Click(object sender, EventArgs e)


{
varsrn=txtsrn.Text;
var name=txtname.Text;
var mobile=txtmobile.Text;
var email=txtmobile.Text;
var course = combocourse.SelectedItem;
var details = (srn+Environment.NewLine) +
(name+Environment.NewLine) + (mobile+Environment.NewLine) +
(email+Environment.NewLine) + (course+Environment.NewLine);
MessageBox.Show("My Details Are:"+details);
}

}
}
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 textBox1_KeyDown(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("Enter Key Down");
}
}

privatevoid textBox1_KeyPress(object sender, KeyPressEventArgs


e)
{
if (e.KeyChar == 13)
{
MessageBox.Show("Enter Key is pressed");
}
}

privatevoid textBox1_KeyUp(object sender, KeyEventArgs e)


{
if (e.KeyCode == Keys.Enter)
{
MessageBox.Show("Enter Key Up");
}
}

privatevoid button1_MouseEnter(object sender, EventArgs e)


{
button1.Height += 30;
button1.Width += 30;
button1.Top -= 15;
button1.Left -= 15;

}
privatevoid button1_MouseLeave(object sender, EventArgs e)
{
button1.Height -= 30;
button1.Width -= 30;
button1.Top += 15;
button1.Left += 15;
}

privatevoid button2_MouseClick(object sender, MouseEventArgs e)


{
MessageBox.Show(String.Format("Clicked at point({0},{1})", e.X,
e.Y));
}

}
}

You might also like