Same Questions as Assignment 1
Client side scripting languages are programming languages where the heavy processing happens client side, usually on the client application or on the web browser itself. Here are some client side scripting languages:
The .NET Framework is a software framework created by Microsoft for development of Windows Apps.
This provides a set of libraries, tools, and a runtime environment to build apps with programming languages like C#, F#, Visual Basic, etc. With some effort, you can compile to various targets like Windows Desktop, Linux(x11/xWayland), Mac, web, mobile, and even build games using Godot(C# through mono), Unity(C#, Only for scripting),
Visual Basic(previously known as VisualBasic.NET(VB.NET)) is an object oriented language for .NET, .NET Framewowrk and Mono
It is a successor to VB6 from .NET framework, and it supports OOP concepts like abstraction, encapsulation, inheritance, polymorphism. This means that everything in the language is an object.
It is not a case sensitive language, and is used to quickly develop a full object oriented program with full access to all libraries from the .NET Framework.
Web technology is used to describe all the different things people use to make websites and web-based applications.
We can simplify this into these classifications of Web Technology:
A c# program is basically collection of tokens.
There are five tokens in C#.
event
, extern
, null
, etchello
, a
, b
, variable1
, etc+
for addition;
(semicolon)Procedural programming is about writing procedures or methods that perform operations on the data, while object-oriented programming is about creating objects that contain both data and methods.
Object-oriented programming has several advantages over procedural programming:
DRY
(Don’t Repeat Yourself), and makes the code easier to maintain, modify and debugClasses and objects are the two main aspects of object-oriented programming. Look at the following illustration to see the difference between class and objects: | Class | Objects | | — | — | | fruit | apple, banana, mango | | car | volvo, audi, toyota |
Everything in C# is associated with classes and objects, along with its attributes and methods.
Inheritance is an OOP Concept where we define a class based on another class while bringing over the properties and more from the previous class.
In C#, there are 4 types of inheritance:
graph TD;
A[BaseClass] --> B[DerivedClass]
graph TD;
A[BaseClass] --> B[DerivedClass1]
B --> C[DerivedClass2]
graph TD;
A[BaseClass] --> B[DerivedClass1]
A --> C[DerivedClass2]
A --> D[DerivedClass3]
graph TD;
A[BaseClass1] --> D[DerivedClass]
B[BaseClass2] --> D[DerivedClass]
Program:
using System;
// Base class
class Animal {
public void Speak() {
Console.WriteLine("Animal speaks");
}
}
// Derived class (Single Inheritance)
class Dog : Animal {
public void Bark() {
Console.WriteLine("Dog barks");
}
}
// Derived class (Multi-level Inheritance)
class Puppy : Dog {
public void Whine() {
Console.WriteLine("Puppy whines");
}
}
class Program {
static void Main() {
Puppy puppy = new Puppy();
puppy.Speak(); // Inherited from Animal
puppy.Bark(); // From Dog
puppy.Whine(); // From Puppy
}
}
graph TD;
A[Animal] --> B[Dog]
B --> C[Puppy]
C# has the following conditional statements:
if
to specify a block of code to be executed, if a specified condition is trueelse
to specify a block of code to be executed, if the same condition is falseelse
if to specify a new condition to test, if the first condition is falseswitch
to specify many alternative blocks of code to be executedUse the if
statement to specify a block of C# code to be executed if a condition is True
.
graph TD
A([Start]) --> B{Condition}
B -- Yes --> C[Execute Code Block]
B -- No --> D([End])
C --> D
Syntax:
if (condition)
{
// block of code to be executed if the condition is True
}
Example:
if (20 > 18)
{
Console.WriteLine("20 is greater than 18");
}
Use the else
statement to specify a block of code to be executed if the condition is False
.
graph TD
A([Start]) --> B{Condition}
B -- Yes --> C[Execute Code Block]
B -- No --> D[Execute Else Block]
C --> E([End])
D --> E
Syntax:
if (condition)
{
// block of code to be executed if the condition is True
}
else
{
// block of code to be executed if the condition is False
}
Example:
if (20 < 18)
{
Console.WriteLine("20 is less than 18");
}
else
{
Console.WriteLine("20 is more than 18");
}
Ternary Operation:
(condition)?Result1:Result2;
Use the else if
statement to specify a new condition if the first condition is False
and fallback to else if that is also false.
graph TD
A([Start]) --> B{Condition 1}
B -- Yes --> C[Execute Code Block 1]
B -- No --> D{Condition 2}
D -- Yes --> E[Execute Code Block 2]
D -- No --> F[Execute Else Block]
C --> G([End])
E --> G
F --> G
Syntax:
if (condition1)
{
// block of code to be executed if condition1 is True
}
else if (condition2)
{
// block of code to be executed if the condition1 is false and condition2 is True
}
else
{
// block of code to be executed if the condition1 is false and condition2 is False
}
Example:
if (20 < 18)
{
Console.WriteLine("20 is less than 18");
}
else if(30 < 20)
{
Console.WriteLine("30 is less than 20");
}
else
{
Console.WriteLine("20 is more than 18");
}
Use the switch
statement to select one of many code blocks to be executed.
graph TD
A([Start]) --> B[Evaluate Expression]
B --> C{Case 1}
C -- Match --> D[Execute Case 1 Block]
C -- No Match --> E{Case 2}
E -- Match --> F[Execute Case 2 Block]
E -- No Match --> G{Default Case}
G -- Execute --> H[Execute Default Block]
D --> I([End])
F --> I
H --> I
Syntax:
switch(expression)
{
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
break;
}
Example:
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;
}
The break Keyword
break
keyword, it breaks out of the switch block.The default Keyword
default
keyword is optional and specifies some code to run if there is no case match
| Data Type | Size | Description | |–|–|–| | int| 4 bytes | Stores whole numbers from -2,147,483,648 to 2,147,483,647| | long | 8 bytes | Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807| | float | 4 bytes | Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits| | double | 8 bytes | Stores fractional numbers. Sufficient for storing 15 decimal digits| | bool | 1 bit | Stores true or false values| | char | 2 bytes | Stores a single character/letter, surrounded by single quotes| | string | 2 bytes per character | Stores a sequence of characters, surrounded by double quotes|
Lists (<ul>
, <ol>
, <li>
):
- Lists allow you to organize items in bullet points (<ul>
) or numbered order (<ol>
). Each item within a list is wrapped in <li>
tags.
There are three types of lists in HTML
<ul>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
<li>Grapes</li>
<li>Orange</li>
</ul>
<ol type="i">
<ol>
<li>Apple</li>
<li>Mango</li>
<li>Banana</li>
<li>Grapes</li>
<li>Orange</li>
</ol>
<dl>
(Definition list) tag
<dt>
(Definition Term) tag
<dd>
tag (Definition Description)
</dl>
tag (Definition list)
<dl>
<dt><b>Apple</b></dt>
<dd>A red colored fruit</dd>
<dt><b>Honda</b></dt>
<dd>A brand of a car</dd>
<dt><b>Spinach</b></dt>
<dd>A green leafy vegetable</dd>
</dl>
Operators are tokens we use to perform operations with one, two or more operands. Types of Operators are:
+
operator adds two operands.
x+y
.-
operator subtracts two operands.
x-y
.*
operator multiplies two operands.
x*y
./
operator divides the first operand by the second.
x/y
.%
operator returns the remainder when first operand is divided by the second.
x%y
.==
(Equal To) operator checks whether the two given operands are equal or not.
5==5
will return true.!=
(Not Equal To) operator checks whether the two given operands are equal or not.
5!=5
will return false.>
(Greater Than) operator checks whether the first operand is greater than the second operand.
6>5
will return true.<
(Less Than) operator checks whether the first operand is lesser than the second operand.
6<5
will return false.>=
(Greater Than Equal To) operator checks whether the first operand is greater than or equal to the second operand.
5>=5
will return true.<=
(Less Than Equal To) operator checks whether the first operand is lesser than or equal to the second operand.
5<=5
will also return true.&&
operator returns true when both the conditions in consideration are satisfied.a && b
returns true when both a and b are true (i.e. non-zero).||
operator returns true when one (or both) of the conditions in consideration is satisfied.a || b
returns true if one of a or b is true (i.e. non-zero).!
operator returns true the condition in consideration is not satisfied.!a
returns true if a is false, i.e. when a=0.=
(Simple Assignment): This is the simplest assignment operator. This operator is used to assign the value on the right to the variable on the left.a = 10
;+=
(Add Assignment): This operator is combination of +
and =
operators. This operator first adds the current value of the variable on left to the value on the right and then assigns the result to the variable on the left.a += b
can be written as a = a + b
-=
(Subtract Assignment): This operator is combination of ‘-‘ and ‘=’ operators. This operator first subtracts the current value of the variable on left from the value on the right and then assigns the result to the variable on the left.a -= b
can be written as a = a - b
*=
(Multiply Assignment): This operator is combination of *
and =
operators. This operator first multiplies the current value of the variable on left to the value on the right and then assigns the result to the variable on the left.a *= b
can be written as a = a * b
/=
(Division Assignment): This operator is combination of /
and =
operators. This operator first divides the current value of the variable on left by the value on the right and then assigns the result to the variable on the left.a /= b
can be written as a = a / b
%=
(Modulus Assignment): This operator is combination of %
and =
operators. This operator first modulo the current value of the variable on left by the value on the right and then assigns the result to the variable on the left.a %= b
can be written as a = a % b
++
operator is used to increment the value of an integer.x=x+1
x++
--
operator is used to decrement the value of an integer.x=x-1
x--
.condition ? first_expression : second_expression;
c = a>b?a:b;
Here, C will take on the value of the larger variable.It is the program that runs on server dealing with the generation of content of web page. 1) Querying the database 2) Operations over databases 3) Access/Write a file on server. 4) Interact with other servers. 5) Structure web applications. 6) Process user input. For example if user input is a text in search box, run a search algorithm on data stored on server and send the results.
It is the program that runs on the client machine (browser) and deals with the user interface/display and any other processing that can happen on client machine like reading/writing cookies.
1) Interact with temporary storage 2) Make interactive web pages 3) Interact with local storage 4) Sending request for data to server 5) Send request to server 6) work as an interface between server and user
Here are some features of C#: 1) Simple - C# is a simple language in the sense that it provides structured approach (to break the problem into parts), rich set of library functions, data types etc. 2) Modern Programming Language - C# programming is based upon the current trend and it is very powerful and simple for building scalable, interoperable and robust applications. 3) Object Oriented - C# is object oriented programming language. OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grow. 4) Type Safe - C# type safe code can only access the memory location that it has permission to execute. Therefore it improves a security of the program. 5) Interoperability - Interoperability process enables the C# programs to do almost anything that a native C++ application can do. 6) Scalable and Updateable - C# is automatic scalable and updateable programming language. For updating our application we delete the old files and update them with new ones. 7) Component Oriented - C# is component oriented programming language. It is the predominant software development methodology used to develop more robust and highly scalable applications. 8) Structured Programming Language - C# is a structured programming language in the sense that we can break the program into parts using functions. So, it is easy to understand and modify. 9) Rich Library - C# provides a lot of inbuilt functions that makes the development fast. 10) Fast Speed - The compilation and execution time of C# language is fast.
Visual Basic is a high-level programming language with many features to develop a secure and robust application.
HTML documents are text files that contains structured code which tells browsers how to display a webpage.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content=
"width=device-width, initial-scale=1.0" />
<title>Structure of HTML Document</title>
</head>
<body>
<!-- Main content of website -->
<h1>BCA-Students</h1>
<p>A one-stop place for solved questions</p>
</body>
</html>
As we can see, the document has the following elements:
<!DOCTYPE HTML>
:
<!DOCTYPE html>
declaration is placed at the beginning of the document.<html>
Tag:
<html>
tag wraps the entire document, serving as the root element of an HTML page.<head>
Section:
<head>
section contains metadata, scripts, styles, and other information not displayed directly on the page but essential for functionality and SEO.<body>
Section:
<body>
section contains all the visible content of the web page, including text, images, videos, links, and more.Popular .NET Programming Languages are:
When executing C# code, different errors can occur: coding errors made by the programmer, errors due to wrong input, or other unforeseeable things.
When an error occurs, C# will normally stop and generate an error message which means C# will throw an exception (throw an error).
try
statement allows you to define a block of code to be tested for errors while it is being executed.catch
statement allows you to define a block of code to be executed, if an error occurs in the try block.Syntax:
try
{
// Block of code to try
}
catch (Exception e)
{
// Block of code to handle errors
}
Program:
using System;
public class Program
{
public static void Main()
{
try
{
int[] myNumbers = {1,2,3};
Console.WriteLine(myNumbers[10]);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
Output:
Index was outside the bounds of the array.
There are three types of arrays in C#, which are
int[] arr = new int[10];
int[] myNum = {10, 20, 30, 40};
int[,] numbers = { {1, 4, 2}, {3, 6, 8} };
int[][] jaggedArray = new int[2][];
jaggedArray[0] = new int[4];
jaggedArray[1] = new int[6];
jaggedArray[0] = new int[] { 4, 6, 8, };
jaggedArray[1] = new int[] { 1, 0, 2, 4, 6 };
Mutable and immutable are English words that mean “can change” and “cannot change” respectively.
That means the mutable types are those whose data members can be changed after the instance is created but Immutable types are those whose data members can not be changed after the instance is created.
When we change the value of mutable objects, value is changed in same memory. But in immutable type, the new memory is created and the modified value is stored in new memory.
Strings are immutable, which means we are creating new memory every time instead of working on existing memory.
StringBuilder is a mutable type, that means we are using the same memory location and keep on appending/modifying the stuff to one instance. It will not create any further instances hence it will not decrease the performance of the application.
An interface is a completely “abstract class”, which can only contain abstract methods and properties (with empty bodies)
It is considered good practice to start with the letter “I” at the beginning of an interface, as it makes it easier for yourself and others to remember that it is an interface and not a class.
Eg.
// interface
interface Animal
{
void animalSound(); // interface method (does not have a body)
void run(); // interface method (does not have a body)
}
Full Example:
using System;
// Interface
interface IAnimal
{
void animalSound(); // interface method (does not have a body)
}
// Pig "implements" the IAnimal interface
class Pig : IAnimal
{
public void animalSound()
{
// The body of animalSound() is provided here
Console.WriteLine("The pig says: wee wee");
}
}
class Program
{
static void Main(string[] args)
{
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound();
}
}