Professional Documents
Culture Documents
COMPILED BY
PROF. JHUNEL B. PEÑAFLORIDA
OVERVIEW
The course aims to teach a high-level programming language that is beneficial to a variety
of real-world applications. It introduces the advanced topics of the selected language as well as
its properties. It will also involve development of several applications, case studies and exercises.
During the second half of the semester, students work in teams to build a mid-scale software
application based on the needs of a specific client.
Each team presents the final project, sharing how course concepts were applied to
address unique client needs. The concepts and skills learned in this course are transferable to a
wide variety of contemporary programming languages and software development tools.
i
ii
TABLE OF CONTENTS
OVERVIEW .......................................................................................................................................i
TABLE OF CONTENTS................................................................................................................... ii
COURSE OUTCOMES ................................................................................................................... iii
LESSON 1 INTRODUCTION TO C# .............................................................................................. 1
LESSON 2 REVIEW OF STATEMENTS AND EXCEPTIONS ...................................................... 8
LESSON 3 REVIEW OF ARRAYS AND INTRODUCTION OF INDEXERS ............................... 26
LESSON 4 REVIEW OF METHODS AND PARAMETERS ......................................................... 36
LESSON 5 OBJECT-ORIENTED PROGRAMMING CONCEPTS .............................................. 48
LESSON 6 INHERITANCE ........................................................................................................... 64
LESSON 7 VIRTUAL METHODS AND POLYMORPHISM ......................................................... 76
LESSON 8 INTERFACES ............................................................................................................ 84
LESSON 9 ADVANCED WINDOW APPLICATION ..................................................................... 89
LESSON 10 DATA CONNECTION .............................................................................................. 96
GRADING SYSTEM ................................................................................................................... 104
REFERENCES ........................................................................................................................... 105
iii
COURSE OUTCOMES
1. The students are expected to implement flow control, looping and exception handling.
2. Create methods, functions and subroutines that take return values and take parameters.
3. Create, initialize and use arrays.
4. Use the common objects and reference types.
5. Create windows applications using forms, control and event handling.
6. Understand and use graphics and multimedia.
7. Create, read from, write to, and update data files.
8. Access Relational Databases using Structured Query Language.
9. Develop web applications using ASP.NET Web Forms and web controls.
1
LESSON 1
INTRODUCTION TO C#
Learning Outcomes
Course Materials
1.1 Introduction to C#
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[]args)
{
Console.WriteLine("Hello World!")
}
}
}
The program runs in a command window (prompt), where it prints the text Hello World on
the screen. The program is not doing much, but it is a full-fledged program.
The above example shows in principle the overall architecture of a C# program which is a
class that has a Main() method as a starting point.
The program below has several statements and methods. This shows how a method is
called and written in C#. These methods are important for many reasons but basically to subdivide
the code into more manageable parts.
using System;
namespace Example02
{
class Program
{
static void Main(string[]args)
{
Title();
More();
}
Code Explanation: This works like the example provided in the previous section. The methods
Title() and More() are create with print statement inside each block and they are called in the
Main() method.
1.4 Variables
Applications must process data and to do this, they need a way to save or store the data. These
programs have variables which may have or may store a value. A variable is characterized by:
• a name
• a type
• operators
Variables must have a name so you can refer to them in the program. C# is similar to other modern
programming languages relatively flexible in regard to the naming of variables but should be
complied with:
Variables must be created or declared before they can be used. This is done by a statement of
the form:
First you write the type, then the variable name, and finally assigned it a value, for example:
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
int num1 = 17;
int num2 = 23;
Console.WriteLine(" The sum of " + num1 + " and " + num2 + " is "
+ sum);
Console.ReadKey();
}
}
}
Note: ReadKey() Method makes the program wait for a key press and it prevents the screen until
a key is pressed. In short, it obtains the next character or any key pressed by the user.
When the above code is executed it produces the following result.
5
Explanation:
First, the program declares two variables num1 and num2 that are initialized respectively
with 17 and 23. The type is int, which means that the two variables may contain integer values.
They are local variables, as they are created in the Main(), and they are only known in the Main()
method. Then the sum of the two variables is stored in the variable sum. Note that the value
stored in sum, is the result of an expression. WriteLine() writes the result. In this case, it builds a
string from a number of parts or elements. Note that the individual elements are separated by +
which here means string concatenating, and integer values automatically are converted to a
string.
1. 5 Operators
C# has the following operators in order of priority, and with decreasing priority downwards:
Operators
() . [] function(...) new typeof sizeof checked unchecked
+ - ! ~ ++ -- (unary operatorer)
*/%
+-
<< >>
< > <= >= is as
== !=
&
^
|
&&
||
?:
= *= /= %= += -= <<= >>= &= ^= |=
In the previous lesson, you have learned the Console.WriteLine() to output or print
values. Now we will use the Console.ReadLine() to get user input.
Example:
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
//Displays a command to input the name
Console.WriteLine("Enter your name: ");
6
}
}
When the above code is executed it displays the input of the user in console.
Example:
When the above code is executed it displays an error message Cannot implicitly
convert type 'string' to 'int'.
To address this situation, the type casting is used by convert any type explicitly, by using
one of the Convert.To methods:
It is also possible to convert data types explicitly by using built-in methods, such as
Convert.ToBoolean, Convert.ToDouble, Convert.ToString, Convert.ToInt32 (int)
and Convert.ToInt64 (long):
Example:
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
7
Console.WriteLine("Enter your name");
string name = Console.ReadLine();
Console.WriteLine("Your name is: " + name + " and you are " + age
+ " years old");
Console.ReadKey();
}
}
}
Notice that the use of conversion method Convert.ToInt32 to convert the string age because
by default the Console.ReadLine(); returns a string.
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program.
Learning Outcomes
Course Materials
In the previous examples, the programs run sequentially this time. We will understand
when we want to execute a statement depending on condition such as:
Example: If there is enough money in the bank account, give the money.
We want to execute one statement when a condition holds and another statement when
a condition does not hold.
We want to select from many statements according to one or more criteria (selection).
Example: If dollar is high and euro is low, sell dollar and buy euro. If dollar is low and euro is high,
sell euro and buy dollar. If both of them are high, sell both and buy YTL. The conditional execution
can be achieved using the if-else statements.
2.1.1 If Statements
If the condition is true, then the block (the block’s statements) inside the if is executed.
Otherwise, nothing happens.
A condition is an expression whose value is a bool and hence an expression that is true
or false. If only a single statement has to be controlled by a condition, you must omit the
parentheses and simply write:
if (condition) statement;
9
Example:
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
}
}
With the switch/case conditional statement, we can simplify some of the tasks that are
long and cumbersome when we use the ladderized if else if. This is substitute in writing concise
and clearer multi-way decision program. However, it has a limitation it cannot test or evaluate
floating point and string values or variables. This means that only those variables that are declared
as integer or character are the candidates that can be tested or evaluated by the switch/case
conditional statement.
Example
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
switch (Convert.ToInt32(text))
10
{
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.ReadKey();
}
}
The while, for and do are control structures for loops or iterations,
It is often needed to carry out a statement or a block several times until a condition occurs.
Here you can use a while statement, which has the following form:
while (condition)
block
11
The significance is that the block and its statements are performed as long as the condition
after while is true. Then the program continues with the next statement after the while construct.
Example
using System;
namespace ConsoleApplication
{
class Program
{
const int N = 100; //declared as constant and global variable.
long s = 0;
int n = 1;
while (n <= N)
{
s +=n;
++n; //Incrementing
}
Console.WriteLine("The value is " + s);
Console.ReadKey();
}
}
Explanation
Note the algorithm. First define a variable s to the result. Next, define a variable n to the number
to be added to the sum and initialize it to 1, which is the first number. Then repeat the subsequent
block as long as n is less than or equal to 100 (the constant N). In the block two things happens:
The value of the variable n is added to s and n is incremented by 1. Note that the last statement
means that n is 1 more for each repetition, and thus the condition for the while, sooner or later
becomes false.
12
2.2.2 For Loop
The for statement has three parts separated by semicolons: initialization, condition and
expression:
Each of the three parts of the for statement can actually be empty. When the statement is
carried out, the following occurs:
Example
using System;
namespace ConsoleApplication
{
class Program
{
const int N = 100; //declared as constant and global variable.
Console.ReadKey();
}
}
If the initialization expression declares the control variable, the control variable will not
exist outside the for statement. This restriction is known as the variable’s scope. Similarly, a
local variable can be used only in the method that declares the variable and only from the point
of declaration.
13
2.2.3 Do While Loop
It is similar to while loop, but the test is after the execution of the loop body. The while loop may
never execute, do-while loop executes at least once.
Syntax
do
{
<statement1>
…
}
while(condition)
The significance is that the statements in the block are performed and then the condition
is tested. Is it true, repeat the block and it continues until the condition becomes false. Compared
with the while statement is the difference that do always will perform the block at least once, since
the condition is first tested after the block is executed. The do loop is not used as often as the
other loops.
Example
using System;
namespace ConsoleApplication
{
class Program
do
{
Console.WriteLine("Number = {0}", num);
num++;
} while (num <= 10);
Console.ReadKey();
}
}
}
14
2.2.4 foreach Loop
C# provides an easy to use and more readable alternative to for loop, the foreach loop
when working with arrays and collections to iterate through the items of arrays/collections. The
foreach loop iterates through each item, hence called foreach loop.
Syntax
using System;
namespace ConsoleApplication
{
class Program
}
}
The in keyword used along with foreach loop is used to iterate over the iterable-item.
The in keyword selects an item from the iterable-item on each iteration and store it in the
variable element.
On first iteration, the first item of iterable-item is stored in element. On second iteration,
the second element is selected and so on.
The number of times the foreach loop will execute is equal to the number of elements in
the array or collection.
The break, goto, continue, return and throw statements are known as jump statements.
These are used to transfer program control from one point in the program to another point, at any
time.
This statement terminates the execution of loop or switch in which it appears and transfers
program control to the next statement which is placed immediately after the loop or switch
16
Example
using System;
namespace ConsoleApplication
{
class Program
}
}
Notice that the program jumps out of the loop when the variable i == 4. Try changing the values
and see what happens.
This statement transfers program control to a labeled statement. The label statement must
exist in the scope of the goto statement. More than one goto statement can transfer control to the
same label. This statement can be used to get out from a loop or an inner nested loop to outer
loop.
Example
using System;
namespace ConsoleApplication
{
class Program
}
}
Notice that when condition inside the if statement is true then the program executed the goto
statement and jumps to its label.
This statement skips the current iteration and passes program control to the next iteration
of the enclosing loop in which it appears. The continue statement breaks one iteration (in the
loop), if a specified condition occurs, and continues with the next iteration in the loop.
Example
using System;
namespace ConsoleApplication
{
class Program
Console.ReadKey();
}
}
}
The program above skips the value of four and continue iterating until the condition is met
in the for loop statement.
using System;
namespace ConsoleApplication
{
class Program
Console.ReadKey();
}
}
}
using System;
namespace ConsoleApplication
{
class Program
}
}
Exceptions provide a way to transfer control from one part of a program to another. C#
exception handling is built upon four keywords: try, catch, finally, and throw.
A try block identifies a block of code for which particular exceptions is activated. It is
followed by one or more catch blocks.
Syntax
try
{
//Statements
}
catch(Exception e1)
{
//Error Handling code
}
catch(Exception e2)
{
20
//Error Handling code
}
catch(Exception e2)
{
//Error Handling code
}
finally
{
//statements to be executed
}
Example
using System;
namespace ConsoleApplication
{
class Program
}
}
If an error occurs, we can use try...catch to catch the error and execute some code
to handle it.
In the following example, we use the variable inside the catch block (e) together with the
built-in Message property, which outputs a message that describes the exception.
You can also output or display your own error. Below is an example.
21
using System;
namespace ConsoleApplication
{
class Program
}
}
2.3.2 Finally
The finally statement lets you execute code, after try...catch, regardless of the result:
Example
using System;
namespace ConsoleApplication
{
class Program
Console.ReadKey();
}
}
}
The throw statement allows you to create a custom error. The throw statement is used together
with an exception class. There are many exception classes available in C#:
ArithmeticException, FileNotFoundException, IndexOutOfRangeException,
TimeOutException, etc:
Example
using System;
namespace ConsoleApplication
{
class Program
try
{
GetDetails();
Console.WriteLine(ex.Message);
Console.ReadLine();
}
23
if (string.IsNullOrEmpty(name))
{
else
{
}
}
C# exceptions are represented by classes. The exception classes in C# are mainly directly
or indirectly derived from the System.Exception class. Some of the exception classes derived
from the System.Exception class are the System.ApplicationException and
System.SystemException classes.
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program.
a. if-else statement
b. Switch/case statement
Write a program that displays an equivalent color once an input letter matches its first
character. For example, b for Blue, r for Red, and so on. Here is the given criteria:
Letters Colors
‘B’ or ‘b’ Blue
‘R’ or ‘r’ Red
‘G’ or ‘g’ Green
‘Y’ or ‘y’ Yellow
Other letters Unknown Color
25
c. Looping
Write a program that calculates and produces these two columns sequence
numbers using the three looping statements.
Learning Outcomes
Course Materials
3.1 C# Array
An array stores a fixed-size sequential collection of elements of the same type. An array
is used to store a collection of data, but it is often more useful to think of an array as a collection
of variables of the same type stored at contiguous memory locations.
All arrays consist of contiguous memory locations. The lowest address corresponds to the
first element and the highest address to the last element.
Declaring Arrays
Syntax:
datatype[] arrayName;
where
Initializing an Array
Declaring an array does not initialize the array in the memory. When the array variable is
initialized, you can assign values to the array.
Array is a reference type, so you need to use the new keyword to create an instance of the array.
Example
Example
using System;
namespace ArrayApplication
{
class Program
}
}
int[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
Example:
using System;
namespace ConsoleApplication
{
class Program
int[,] arr = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
};//declaration and initialization
//traversal
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Console.Write(arr[i, j] + " ");
}
Console.WriteLine();//new line at each row
}
29
Console.ReadKey();
}
}
}
A jagged array in C# is an array whose elements are arrays. The elements of a jagged
array can be of different dimensions and sizes. A jagged array is sometimes called an "array of
arrays." A special type of array is introduced in C#. A Jagged Array is an array of an array in which
the length of each array index can differ.
Example
You can also initialize the array upon declaration like this:
int[][] jaggedArray =
{
new int[] { 3, 5, 7, },
new int[] { 1, 0, 2, 4, 6 },
new int[] {1, 2, 3, 4, 5, 6, 7, 8},
30
new int[] {4, 5, 6, 7, 8}
};
Example
using System;
namespace ConsoleApplication
{
class Program
Console.ReadKey();
}
}
}
3.4 Indexers
An indexer can be defined the same way as property with this keyword and square brackets
[].
Syntax
Example:
using System;
namespace ConsoleApplication
{
class Program
strStore[0] = "One";
strStore[1] = "Two";
strStore[2] = "Three";
strStore[3] = "Four";
Console.ReadKey();
}
}
}
The above StringDataStore class defines an indexer for its private array strArr. So now,
you can use the StringDataStore like an array to add and retrieve string values from strArr,
as shown below.
using System;
namespace ConsoleApplication
{
class Program
32
strStore[0] = "One";
strStore[1] = "Two";
strStore[2] = "Three";
strStore[3] = "Four";
Console.ReadKey();
}
}
}
Indexer can also be generic. It means that it can be used with any data type.
Example
class DataStore<T>
{
private T[] store;
public DataStore()
{
store = new T[10];
}
return store[index];
}
set
{
if (index < 0 || index >= store.Length)
throw new IndexOutOfRangeException("Index out of
range");
store[index] = value;
}
}
You can be overloaded with the different data types for index. The following example
overloads an indexer with int type index as well as string type index.
Example
using System;
namespace ConsoleApplication
{
class StringDataStore
{
private string[] strArr = new string[10]; // internal data storage
return strArr[index];
}
set
{
if (index < 0 || index >= strArr.Length)
throw new IndexOutOfRangeException("Index out of range");
strArr[index] = value;
}
}
return null;
}
}
35
}
class Program
{
static void Main(string[] args)
{
StringDataStore strStore = new StringDataStore();
strStore[0] = "One";
strStore[1] = "Two";
strStore[2] = "Three";
strStore[3] = "Four";
Console.WriteLine(strStore["one"]);
Console.WriteLine(strStore["two"]);
Console.WriteLine(strStore["Three"]);
Console.WriteLine(strStore["Four"]);
}
}
}
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program.
1. Define the different types of Arrays presented in this lesson and cite your own example.
2. Create a program that utilizes the multidimensional array in real life scenario.
3. Using jagged arrays create a movie ticket counter where ticket selling counters are fixed
(rows are fixed) but you don't know how many people will be standing in each counter in
a queue (column numbers are not fixed can vary on different rows).
4. Create an Indexer class named myIndexer and access the class in the main method of
the main program. It can be generic or overloaded.
36
LESSON 4
REVIEW OF METHODS AND PARAMETERS
Learning Outcomes
Course Materials
In C#, static means something which cannot be instantiated. You cannot create an object
of a static class and cannot access static members using an object.
A static field is a class field, which means that its data is stored in one location in
memory, no matter how many objects are created from its class. In fact, you can use a static field
to keep track of how many objects have been created from a particular class.
Static fields in a non-static class can be defined using the static keyword. Static fields
of a non-static class is shared across all the instances. So, changes done by one instance would
reflect in others.
Example:
using System;
}
37
public StopWatch()
{
StopWatch.NoOfInstances++;
}
}
You can define one or more static methods in a non-static class. Static methods can be
called without creating an object. You cannot call static methods using an object of the non-static
class.
The static methods can only call other static methods and access static members. You
cannot access non-static members of the class in the static methods.
Static methods are called by using the class name, not the instance of the class.
Example
using System;
Program.withoutObj();
Console.ReadKey();
}
using System;
In the above example, myVar is a non-static field so to use this field we first need to create
the object of that class. On the other hand, static data is shared among all the objects of that
class. That is, for all the objects of a class, there will be only one copy of static data.
Example
using System;
A method is a group of statements that together perform a task. Every C# program has at
least one class with a method named Main.
When defining a method, we basically declare the elements of its structure. The syntax is below.
<AccessSpecifier><ReturnType><MethodName>(Parameter List)
{
Method Body
}
Where:
• Access Specifier: This determines the visibility of a variable or a method from another
class.
• Return type: A method may return a value. The return type is the data type of the value
the method returns. If the method is not returning any values, then the return type is void.
• Method name: Method name is a unique identifier and it is case sensitive. It cannot be
same as any other identifier declared in the class.
• Parameter list: Enclosed between parentheses, the parameters are used to pass and
receive data from a method. The parameter list refers to the type, order, and number of
the parameters of a method. Parameters are optional; that is, a method may contain no
parameters.
• Method body: This contains the set of instructions needed to complete the required
activity.
Example
class NumberManipulator {
return result;
}
...
}
The method is called using the name of the method as shown in the example below.
Example 1
using System;
Example 2
using System;
class NumberManipulator {
return result;
}
}
public static void Main()
{
You can also You can also call public method from other classes by using the instance of
the class. For example, the method FindMax belongs to the NumberManipulator class, you can
call it from another class Test.
Example
using System;
namespace CalculatorApplication
{
class NumberManipulator
{
public int FindMax(int num1, int num2)
{
/* local variable declaration */
int result;
return result;
}
}
42
class Test
{
static void Main(string[] args)
{
/* local variable definition */
int a = 100;
int b = 200;
int ret;
NumberManipulator n = new NumberManipulator();
A method can call itself. This is known as recursion. Following is an example that calculates
factorial for a given number using a recursive function.
Example
using System;
namespace CalculatorApplication
{
class NumberManipulator
{
public int factorial(int num)
{
/* local variable declaration */
int result;
if (num == 1)
{
return 1;
}
else
{
result = factorial(num - 1) * num;
return result;
}
}
static void Main(string[] args)
{
NumberManipulator n = new NumberManipulator();
//calling the factorial method {0}", n.factorial(6));
43
Console.WriteLine("Factorial of 7 is : {0}", n.factorial(7));
Console.WriteLine("Factorial of 8 is : {0}", n.factorial(8));
Console.ReadLine();
}
}
}
A method’s parameters can be of any type, but there are several kinds of parameter
passing. When you define a method that you specify the parameters the method should have,
and these parameters are called the formal parameters and specify the values that the method
should operate on. When you call the method, you must specify the values (parameters) to be
transferred to the method, and they are called for the actual parameters.
Value parameters
When this method is called, there must be transmitted two actual parameters. Exactly
what happens is that on the stack the system creates a so-called activation block, which contains
four basic things
• the return address, so the system knows where the program will continue after the method
is terminated
• a copy of each actual parameter
• a place to the return value corresponding to the method’s type
• the method’s local variables, if it has local variables.
44
Example
using System;
namespace ParameterExample
{
class Program
{
static int AddNumbers(int a, int b)
{
int sum;
sum = a + b;
Console.WriteLine("The Answer is " + sum);
return sum;
}
static void Main(string[] args)
{
Example
The example below demonstrates the use of different methods with parameters.
using System;
namespace ParameterExample
{
class Program
{
static int Sum(int a, int b)
{
int sum;
sum = a + b;
Console.WriteLine("The Answer is " + sum);
return sum;
45
}
Note: The void keyword, used in the examples above, indicates that the method should not return
a value. If you want the method to return a value, you can use a primitive data type (such as int
or double) instead of void, and use the return keyword inside the method:
46
4.4 Overloading methods
With method overloading, multiple methods can have the same name with different parameters:
Example
using System;
namespace ParameterExample
{
class Program
{
static int PlusMethodInt(int x, int y)
{
return x + y;
}
Console.ReadKey();
}
}
}
Instead of defining two methods that should do the same thing, it is better to overload one.
In the example below, we overload the PlusMethod method to work for both int and double:
Example
using System;
namespace ParameterExample
{
class Program
{
static int PlusMethod(int x, int y)
{
47
return x + y;
}
Console.ReadKey();
}
}
}
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program.
1. What is static field and static method and how they are used in a program? Provide your
own example of this.
2. How a method is overloaded in a program? Demonstrate this by creating your own
methods which are overloaded in the main class.
3. Create the following machine problems.
a. Create a program with a method that will accept as input a number of N seconds and
determine from this number how many days, hours, minutes, and seconds it represents.
Sample Output:
How many seconds do you want to be converted? 100000100000 Seconds is equal to:
1Day
3Hours
46Minutes
40 Seconds
b. Create a Jack n Poy Game that implements the conditional statement, methods and
parameters in a program.
48
LESSON 5
OBJECT-ORIENTED PROGRAMMING CONCEPTS
Learning Outcomes
Course Materials
Example
class Car
{
string color = "red";
}
An object is created from a class. In the above example, the class Car was created. This
time we are going to create an object from the class Car.
Example
using System;
class Car
{
string color = "red";
Note that the (.) is used to separate class from an object, or to access variables/fields inside a
class. The class Car is instantiated by creating object myObj and the field color is used.
Example
class Car
{
string color = "red";
static void Main(string[] args)
{
Car myObj1 = new Car();
Car myObj2 = new Car();
Console.WriteLine(myObj1.color);
Console.WriteLine(myObj2.color);
}
}
An object of class can also be created and can be accessed it in another class. Usually,
this is done for better organization of classes. In other words (one class has all the fields and
methods, while other class holds the Main() method.
• Car.cs
50
• Program.cs
1. Upon creating new project in the file tab. It will automatically generate a class name Program.cs
that contains the main() method.
2. Navigate to the right of the window under the Solution explorer right click and Add and then
click class and name it whatever you want but usually it starts with a capital letter.
The Program.cs contains the main method that invoke the Car.cs with fields in it.
Car.cs
using System;
namespace ObjectOrientedProgramming
{
class Car
{
public string color = "red";
}
}
Program.cs
using System;
namespace ObjectOrientedProgramming
{
class Program
{
static void Main(string[] args)
{
51
Car myObj = new Car();
Console.WriteLine(myObj.color);
Console.ReadKey();
}
}
}
Example
using System;
namespace ObjectOrientedProgramming
{ //Create class Car
class Car
{
public string model; //Create a Field
//Create a class Constructor for the Car class
public Car()
{
model = "Mustang"; // Set the initial value for model
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ObjectOrientedProgramming
{
class Program
{
static void Main(string[] args)
{
Car Ford = new Car(); // Create an object of the Car Class (this
will call the constructor)
Console.WriteLine(Ford.model); // Print the value of model
Console.ReadKey();
52
}
}
}
Note that the constructor name must match the class name, and it cannot have a return type
(like void or int). The constructor is called upon object is created. All classes have constructors
by default: if you do not create a class constructor yourself, C# creates one for you. However,
then you are not able to set initial values for fields.
The following example adds a string modelName parameter to the constructor. Inside
the constructor we set model to modelName (model=modelName). When we call the
constructor, we pass a parameter to the constructor ("Mustang"), which will set the value of
model to "Mustang":
Car.cs
using System;
namespace ObjectOrientedProgramming
{ //Create class Car
class Car
{
public string model;
// Create a class constructor with a parameter
public Car(string modelName)
{
model = modelName;
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ObjectOrientedProgramming
{
class Program
{
static void Main(string[] args)
{
53
Car Ford = new Car("Mustang");
Console.WriteLine(Ford.model);
Console.ReadKey();
}
}
}
class Program
{
static void Main(string[] args)
{
Car Ford = new Car();
Ford.model = "Mustang";
Ford.color = "red";
Ford.year = 1969;
Console.WriteLine(Ford.model);
Console.WriteLine(Opel.model);
}
}
class Program
{
static void Main(string[] args)
{
Car Ford = new Car("Mustang", "Red", 1969);
Car Opel = new Car("Astra", "White", 2005);
Console.WriteLine(Ford.model);
Console.WriteLine(Opel.model);
}
}
5.3 Encapsulation
Encapsulation is defined 'as the process of enclosing one or more items within a physical
or logical package'. Encapsulation, in object-oriented programming methodology, prevents
access to implementation details.
54
• Public
• Private
• Protected
• Internal
• Protected internal
Public access specifier allows a class to expose its member variables and member
functions to other functions and objects. Any public member can be accessed from outside the
class.
Example
using System;
namespace EncapsulationExample
{
class Rectangle
{
//member variables
public double length;
public double width;
r.length = 4.5;
r.width = 3;
r.Display();
Console.ReadKey();
}
}
}
In the preceding example, the member variables length and width are declared public, so
they can be accessed from the function Main using an instance of the Rectangle class, named r.
The member function Display and GetArea can also access these variables directly
without using any instance of the class.
The member functions Display is also declared public, so it can also be accessed from
Main using an instance of the Rectangle class, named r.
Private access specifier allows a class to hide its member variables and member functions
from other functions and objects. Only functions of the same class can access its private
members. Even an instance of a class cannot access its private members.
Example
using System;
namespace EncapsulationExample
{
class Rectangle
{
//member variables
private double length;
private double width;
}
class Program
{
static void Main(string[] args)
{
}
}
}
In the preceding example, the member variables length and width are declared private, so
they cannot be accessed from the function Main. The member functions AcceptDetails and
Display can access these variables. Since the member functions AcceptDetails and Display are
declared public, they can be accessed from Main using an instance of the Rectangle class, named
r.
Protected access specifier allows a child class to access the member variables and
member functions of its base class. This way it helps in implementing inheritance. This will be
covered in Inheritance.
Internal access specifier allows a class to expose its member variables and member
functions to other functions and objects in the current assembly. In other words, any member with
57
internal access specifier can be accessed from any class or method defined within the application
in which the member is defined.
Example
using System;
namespace EncapsulationExample
{
class Rectangle {
//member variables
internal double length;
internal double width;
double GetArea() {
return length * width;
}
public void Display() {
Console.WriteLine("Length: {0}", length);
Console.WriteLine("Width: {0}", width);
Console.WriteLine("Area: {0}", GetArea());
}
}//end class Rectangle
class Program
{
static void Main(string[] args)
{
}
}
}
In the preceding example, notice that the member function GetArea() is not declared with any
access specifier. The default access modifier of a class member is private since no access
specifier is declared.
The protected internal access specifier allows a class to hide its member variables and
member functions from other class objects and functions, except a child class within the same
application. This is also used while implementing inheritance.
58
5.4 Inheritance
Inheritance allows us to define a class in terms of another class, which makes it easier to
create and maintain an application. This also provides an opportunity to reuse the code
functionality and speeds up implementation time.
When creating a class, instead of writing completely new data members and member
functions, the programmer can designate that the new class should inherit the members of an
existing class. This existing class is called the base class, and the new class is referred to as the
derived class.
The idea of inheritance implements the IS-A relationship. For example, mammal IS A
animal, dog IS-A mammal hence dog IS-A animal as well, and so on.
A class can be derived from more than one class or interface, which means that it can inherit data
and functions from multiple base classes or interfaces.
Syntax
Example
using System;
namespace RectangleApplication
{
class Shape
{
public void setWidth(int w)
{
width = w;
}
public void setHeight(int h)
{
height = h;
}
protected int width;
59
protected int height;
}
// Derived class
class Rectangle : Shape
{
public int getArea()
{
return (width * height);
}
}
class Program
{
static void Main(string[] args)
{
Rect.setWidth(5);
Rect.setHeight(7);
C# does not support multiple inheritance. However, you can use interfaces to
implement multiple inheritance. This will be covered in lesson for Interfaces.
Example
using System;
namespace RectangleApplication
{
class Shape {
public void setWidth(int w) {
width = w;
}
public void setHeight(int h) {
height = h;
}
protected int width;
60
protected int height;
}
// Derived class
class Rectangle : Shape, PaintCost {
public int getArea() {
return (width * height);
}
public int getCost(int area) {
return area * 70;
}
}
class Program
{
static void Main(string[] args)
{
Rect.setWidth(5);
Rect.setHeight(7);
area = Rect.getArea();
Instantiation is the process of creating object of a defined class and the instance is the
object itself, which is created in runtime. This instance is characterized by state–set of values,
associated with class attributes. In the context of such behavior the object consists of two things:
current state and behavior defined in the class of the object. The state is specific for the instance
(the object), but the behavior is common for all objects which are instances of this class.
61
Example
The class Cat models the real-world object "cat" and has the properties name and color.
The given class defines several fields, properties and methods.
Class Cat
//Name
}
//Name ends
//Color
//Default Constructor
public Cat()
{
this.name = "Unnamed";
this.color = "gray";
62
}
The example class Cat defines the properties Name and Color, which keep their values
in the hidden (private) fields name and color. Furthermore, two constructors are defined for
creating instances of the class Cat, respectively with and without parameters, and a method of
the class Say().
class Program
{
static void Main(string[] args)
{
}
}
63
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program. For items 4 and 5 you can work in a group with
maximum members of three.
Course Materials
6.1 Inheritance
Example
Below is a class that represents a person by first name and last name.
The another class Employee (of a company) is person with two additional properties in the
form of a title and salary. Below is a class that inherits the Person class.
65
Class Employee
: Person
It denotes that the Employee inherits the Person. That Employee inherits Person means
an Employee gets (inherits) all the properties that a Person has and expands with new properties.
In this case extends an Employee a Person with two new instance variables and associated
properties. The Employee class has a constructor that initializes the two new instance variables,
position and monthly, but it must also initialize the instance variables fname and lname in the
base class. This requires that the constructor in Person is called, but when as a programmer you
can’t call it directly, it is necessary to have a syntax that performs the constructor in the base
class. It happens in the following:
A Director is just a special kind of Employee, and the class can be defined as a class that
inherits Employee. A class that represent a Director will define like this:
//Class Director
}
}
The class is very simple and consists solely of a constructor, which transmit parameters
to the constructor in the Employee class. All the other services as a director does occur (inherited)
come from Employee and Person.
The class Bookkeeper can define the same way as class Director:
//Class Bookkeeper
}
}
The first statement prints the result of ToString() from the class Employee. The parameter
e has the type Employee, and you can thus especially use what is defined public in Person.
Print(d);
Print(b);
}
You should particularly note that the method calls Print() with the two objects d and b as
actual parameters. It makes sense for d have the type Director, which specifically is an Employee
Above, there are defined four classes that are linked in a hierarchy, as you can illustrate
in the following way:
When a class inherits another class, the class you inherit from is called the base class and
the inheriting class is called a derived class. For example, is Person the base class for Employee
while Employee derives from Person. Sometimes Person instead of is called a super class, while
the Employee is called a subclass. We say also that Person is a generalization of Employee and
that Employee is a specialization of Person. This saying better reflected the relationship between
Employee, Director and Bookkeeper in which Employee is a generalization of the Director and
Bookkeeper and Director are specializations of Employee. Sometimes we talk also about the
class that inherits as an extension of the base class corresponding to Employee extends Person
with new properties.
In the previous lessons, the basic access modifiers such as public, private, and internal.
This time we will cover the protected and protected internal.
68
Protected defines class members which are not visible to users of the class (those who
initialize and use it) but are visible to all inheriting classes(descendants).
using System;
namespace AccessControlExample
{
class User
{
}
class Program
{
static void Main(string[] args)
{
User u = new User();
// Complier Error
u.Location = "Hyderabad";
u.Age = 32;
69
u.GetUserDetails();
Console.ReadLine();
}
}
}
If you observe the above result, we are getting compile-time errors because
the protected modifier members of the User class referred in another class.
Below is the implementation of accessing a base class protected members in derived class
through derived class type.
Example
using System;
namespace AccessControlExample
{
class User
{
// Complier Error
Protected internal defines class members which are both internal, i.e. visible within the
entire assembly, and protected, i.e. not visible outside the assembly, but visible to classes who
inherit it (even outside the assembly).
71
Example
using System;
namespace AccessControlExample
{
class User
{
class Program
{
}
72
6.3 Method Hiding
C# also provides a concept to hide the methods of the base class from derived class, this
concept is known as Method Hiding. It is also known as Method Shadowing. In method hiding,
you can hide the implementation of the methods of a base class from the derived class using the
new keyword.
Example
using System;
namespace MethodHidingExample
{
// Base Class
public class My_Family
{
// Derived Class
public class My_Member : My_Family
{
6.4 Initialization
The derived class inherits the base class member variables and member methods.
Therefore, the super class object should be created before the subclass is created. You can give
instructions for superclass initialization in the member initialization list.
Example
using System;
namespace RectangleApplication
{
class Rectangle
{
//member variables
protected double length;
protected double width;
class Program
{
static void Main(string[] args)
{
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program. For items 3 to 5 you can work in a group with maximum
members of three.
1. Discuss the concept of Inheritance and how it benefits the coding process?
2. What are the different access controls and how it is used?
3. Based on the following UML Diagram implement the concept of Inheritance. The example
provided in lesson 6.1 is your guide.
75
Learning Outcomes
Course Materials
Dynamic Binding
A polymorphic variable can be defined in a class that is able to reference (or point to)
objects of the class and objects of any of its descendants.
When a class hierarchy includes classes that override methods and such methods are
called through a polymorphic variable, the binding to the correct method will be dynamic.
Allows software systems to be more easily extended during both development and
maintenance
77
Dynamic Binding Concepts
An abstract method is one that does not include a definition (it only defines a protocol). An
abstract classis one that includes at least one virtual method. An abstract class cannot be
instantiated
Take a simple scenario (below is the image) where we have a simple parent child class
relationship. Assume that this child class is used in lot of projects and installed in lot of places.
Now assume after the child class has been deployed across locations, after some months, there
are some changes in the parent class.
These changes can have cascading and unexpected behavior in child class as well. This
unexpected behavior on child classes is termed as “Fragile class problem”.
Consider the below scenario where we have a parent class called as “DbParent” with a virtual
method “Insert”.
class DbParent
{
public virtual void Insert()
{
Console.WriteLine("Parent insert");
}
}
Below is a simple child class with his own “Insert” implementation which is installed across
various locations.
Now let’s say after some months of deployment parent class developers without
understanding the impact on child classes go and add a new method “Add”. This “Add” method
calls the “Insert” method internally (below is the code snippet for the same).
class DbParent
{
public void Add() // Adds method without consulting
{
this.Insert();
}
public virtual void Insert()
{
Console.WriteLine("Parent insert");
}
}
Now client programs who invoke the “Add” method by creating child class objects expect that the
“Child” class “Insert” implementation should be called.
When you execute the code, you will see the parent class “Insert” is called which is not
EXPECTED.
The base class is very fragile (will change from time to time) then the inheritance should
not be allowed. By making the class sealed or the fragile methods “sealed”, this problem can be
solved.
7.3 Polymorphism
The term polymorphism (from the Greek meaning "having multiple forms") in OO is the
characteristic of being able to assign a different meaning or usage to something in different
contexts - specifically, to allow a variable to refer to more than one type of object.
Inheritance lets us inherit fields and methods from another class. Polymorphism uses
those methods to perform different tasks. This allows us to perform a single action in different
ways.
Example
For example, think of a base class called Animal that has a method called
animalSound(). Derived classes of Animals could be Pigs, Cats, Dogs, Birds - And they also
have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.):
79
class Animal // Base class (parent)
{
public void animalSound()
{
Console.WriteLine("The animal makes a sound");
}
}
Now we can create Pig and Dog objects and call the animalSound() method on both of them:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverridingExample
{
class Animal // Base class (parent)
{
public void animalSound()
{
Console.WriteLine("The animal makes a sound");
}
}
class Program
{
static void Main(string[] args)
{
Animal myAnimal = new Animal(); // Create a Animal object
Animal myPig = new Pig(); // Create a Pig object
Animal myDog = new Dog(); // Create a Dog object
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
Console.ReadKey();
}
}
}
The output from the example above was probably not what you expected. That is because
the base class method overrides the derived class method, when they share the same name.
Below is an example of Method Overriding.
C# provides an option to override the base class method, by adding the virtual keyword
to the method inside the base class, and by using the override keyword for each derived class
methods. Only if a method is declared virtual, derived classes can override this method if they are
explicitly declared to override the virtual base class method with the override keyword.
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverridingExample
{
class Animal // Base class (parent)
{
public virtual void animalSound()
{
Console.WriteLine("The animal makes a sound");
81
}
}
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
}
}
Data abstraction is the process of hiding certain details and showing only essential
information to the user. Abstraction can be achieved with either abstract classes or interfaces.
• Abstract class: is a restricted class that cannot be used to create objects (to access it, it
must be inherited from another class).
• Abstract method: can only be used in an abstract class, and it does not have a body.
The body is provided by the derived class (inherited from).
82
Example
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverridingExample
{
// Abstract class
abstract class Animal
{
// Abstract method (does not have a body)
public abstract void animalSound();
// Regular method
public void sleep()
{
Console.WriteLine("Zzz");
}
}
class Program
{
static void Main(string[] args)
{
Pig myPig = new Pig(); // Create a Pig object
myPig.animalSound(); // Call the abstract method
myPig.sleep(); // Call the regular method
Console.ReadKey();
}
}
}
Classes can be declared as sealed by putting the keyword sealed before the class definition. If
you don't want other classes to inherit from a class, use the sealed keyword:
83
Syntax
Sealed class cannot be used as a base class. For this reason, it cannot also be an
abstract class. Sealed classes prevent derivation. Because they can never be used as a base
class, some run-time optimizations can make calling sealed class members slightly faster.
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program.
1. What are Virtual Methods and Dynamic Binding? Create your own virtual method and
implement it in a class.
2. What is method overloading? Why is method overloading implemented?
3. What is fragile base class problem? How it is solved?
4. What is polymorphism?
5. Discuss the abstract classes and sealed classes
6. Answer the following machine problems:
Using the concept of Polymorphism. Create a base class named Employee with the with
method Salary that has fields numberofHours, rateperHour and tax then derive classes
such as Regular and Contractual and Part-time then they must their own implementation
of Salary method.
84
LESSON 8
INTERFACES
Learning Outcomes
Course Materials
An abstract class is a type that can contain everything that a class can have. That is
variables, constructors, methods, etc. Just may some of the methods be abstract, corresponding
to those not yet been encoded – it is deferred to the concrete classes that have the requisite
knowledge. In contrast, an interface is a type which can contain only abstract methods.
Example
Basically, it looks like a class, just stands there instead the word interface. An interface
defines the methods and properties, and in this case two properties. One can think of an interface
as a class that can only contain abstract methods. Note especially that in an interface has no
method visibility – they are by default public.
public int X
{
get { return x; }
set { x = value; }
public int Y
{
get { return y; }
set { y = value; }
}
When a class implements an interface, the class must implement the methods and
properties that are defined in the interface.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter a value for X-axis");
int x = Convert.ToInt32(Console.ReadLine());
If a class implements two interfaces that contain a member with the same signature, then
implementing that member on the class will cause both interfaces to use that member as their
implementation. In the following example, all the calls to Paint invoke the same method. This
first sample defines the types:
When two interface members don't perform the same function, it leads to an incorrect
implementation of one or both of the interfaces. It's possible to implement an interface member
explicitly — creating a class member that is only called through the interface and is specific to
that interface. Name the class member with the name of the interface and a period. For
example:
IControl c = obj;
c.Paint(); // Calls IControl.Paint on SampleClass.
ISurface s = obj;
s.Paint(); // Calls ISurface.Paint on SampleClass.
// Output:
// IControl.Paint
// ISurface.Paint
Explicit implementation is also used to resolve cases where two interfaces each declare
different members of the same name such as a property and a method. To implement both
interfaces, a class has to use explicit implementation either for the property P, or the method P,
or both, to avoid a compiler error. For example:
interface ILeft
{
int P { get; }
}
interface IRight
{
int P();
}
Beginning with C# 8.0, you can define an implementation for members declared in an
interface. If a class inherits a method implementation from an interface, that method is only
accessible through a reference of the interface type. The inherited member doesn't appear as
88
part of the public interface. The following sample defines a default implementation for an interface
method:
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program. For item 2, you can work with a pair.
Course Materials
You will be presented with a blank form. This document assumes that you have the
Toolbox pane visible on the left of the screen and the Properties on the right. These panes can
be moved around and hidden. This pane contains common controls which make up the elements
on the form.
To make a blank form, click the File tab > New > Project and choose Windows Form Applications
as shown below.
• The Forms Designer will be available any time a Windows Forms class has been added
to a project.
• It can be opened by selecting the View Designer icon from the Solution Explorer window.
The Forms Designer allows a programmer to drag and drop controls from a toolbox onto a form.
• If the toolbox isn't visible, you can select it from the View | Toolbox menu.
You can modify the properties of a control using the Properties window (shown in the lower right).
• If the Properties Window isn't visible, you can select it from the View | Properties Window
menu.
91
• The properties can be shown by category or alphabetically be selecting an icon from the
Properties Window toolbar.
9.2 Menus, Tabbed windows and Multiple document interface (MDI) programs
Demonstration
1. We begin by creating a new C# Windows Forms Application project named Calculator in the
Demos directory. Leave unchecked “Create directory for solution.”
92
2. We then rename the source file for the form to MainForm.cs. You will be asked if you want to
rename the corresponding code elements. Say yes.
3. To verify that the required code elements have been renamed, build and run the application.
You should see a bare form, which can be resized.
4. We will use the toolbox to drag a button control to the form. To make everything look nifty, we
will resize the form.
93
5. We want to make sure the following property values are set for the button and form:
6. We need to trap the Click event for the btnCalculate button. To do this, we can double-click on
the btnCalculate button. It will write the Click event handler and delegate for us and position us at
the handler function in the code window.
94
The toolbox provides a lot of object that can be used in Graphical User Interface.
95
Menus: https://www.youtube.com/watch?v=w1FYv3_asTw
Multiple-Document Interface : https://www.youtube.com/watch?v=-4EYhC9xDHo
ListView and Treeview: https://www.youtube.com/watch?v=AdelSRDZSQI
CheckBox, ListBox, ComboBox : https://www.youtube.com/watch?v=J0_9COVeT4w
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program. You can work in a group with maximum members
of 4.
1. Design a user Interface the computes the grade of the students using the Toolbox in Visual
Studio.
2. Implement command such as compute, reset and cancel and employ the event driven
programming.
96
LESSON 10
DATA CONNECTION
Learning Outcomes
Course Materials
10.1 Prerequisites
• Visual Studio.
• SQL Server Express LocalDB. If you don't have SQL Server Express LocalDB, you can
install it from the SQL Server Express download page.
Create a database name as Employee using SQL SERVER. Create a Table name as
EmployeeDetails in this table create following fields.
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
txtEmpName.Text = dr[1].ToString();
txtEmpDegn.Text = dr[2].ToString();
txtSalary.Text = dr[3].ToString();
}
dr.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
Video Tutorials
Activities/Assessments
All class assignments and activities should be submitted via google classroom website on
or before the due date. The solutions to the programming problems must include full working
code, not just an output of your program. You can work in a group with maximum members
of 4.
1. Using the Interface you designed with calculation in Activity under Lesson 9. Create a
database and connect it with the data source.
2. Now add buttons such as Save, Update, Delete and Select with necessary commands to
manipulate data in the data source created in Item number 1 of this lesson.
101
Projects
Midterm
A hospital supply company wants to market a program to assist with the calculation of intravenous
rates. Design and implement a program that interacts with the user as follows:
Problem =>1
Enter rate in ml/hr=>150
Enter tubing’s drop factor (drops/ml)=> 15
The drop rate per minute is 38.
Problem => 2
Enter number of hours=> 8
The rate in milliliters per hour is 125.
Problem => 4
Enter rate in units/hr=> 1000
Enter concentration in units/ml=> 25
The rate in milliliters per hour is 40.
Problem => 5
• get_problem – Displays the user menu, then inputs and returns as the function value the
problem number selected.
• get_rate_drop_factor – Prompts the user to enter the data required for problem 1 and
sends this data back to the calling module via output parameters.
• get_kg_rate_conc – Prompts the user to enter the data required for problem3 and sends
this data back to the calling module via output parameters.
• get_units_conc – Prompts the user to enter the data required for problem 4 and sends
this data back to the calling module via output parameters.
• fig_drops_min – Takes rate and drop factor as input parameters and returns drops/min
(rounded to nearest whole drop) as function value.
• fig_ml_hr – Takes as an input parameter the number of hours over which one liter is to
be delivered and returns ml/hr (rounded) as function value.
• by_weight – Takes as input parameters rate in mg/kg/hr, patient weight in kg, and
concentration of drug in mg/ml and returns ml/hr (rounded) as function value.
• by_units – Takes as input parameters rate in units/hr and concentration in units/ml and
returns ml/hr (rounded) as function value.
103
Finals
Create a Windows Applications for a businesses, offices or organization that uses Graphic User
Interface (GUI) objects with database. It should include the following operation:
Modules:
• Create
• Read
• Update
• Delete
• Select
• View
• Login/Logout
FIRST GRADING
Class Standing (70%): Online Quizzes, Machine Problems, Activities and Assessments,
Projects
Midterm Examination (30%)
SECOND GRADING
Class Standing (70%): Online Quizzes, Machine Problems, Activities and Assessments,
Projects
Final Examination (30%)
Abstract and Sealed Classes and Class Members (C# Programming Guide). (2015, July 20).
Retrieved from microsoft.com: https://docs.microsoft.com/en-
us/dotnet/csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-
and-class-members
C# - Encapsulation. (n.d.). Retrieved from tutorialspoint.com:
https://www.tutorialspoint.com/csharp/pdf/csharp_encapsulation.pdf
C# - Inheritance. (n.d.). Retrieved September 25, 2020, from tutorialspoint.com:
https://www.tutorialspoint.com/csharp/pdf/csharp_inheritance.pdf
C# - Static Class, Methods, Constructors, Fields. (n.d.). Retrieved September 24, 2020, from
tutorialsteacher.com: https://www.tutorialsteacher.com/csharp/csharp-static
C# Access Modifiers (Public, Private, Protected, Internal). (n.d.). Retrieved September 25, 2020,
from .tutlane.com: https://www.tutlane.com/tutorial/csharp/csharp-access-modifiers-
public-private-protected-internal
C# Classes and Objects. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_classes.asp
C# Constructors. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_constructors.asp
C# foreach loop. (n.d.). Retrieved September 24, 2020, from programiz.com:
https://www.programiz.com/csharp-programming/foreach-loop
C# Method Overloading. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_method_overloading.asp
C# Method Parameters. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_method_parameters.asp
C# Methods. (n.d.). Retrieved September 24, 2020, from tutorialspoint.com:
http://www.tutorialspoint.com/csharp/csharp_methods.htm
C# Type Casting. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_type_casting.asp
C# User Input. (n.d.). Retrieved September 24, 2020, from w3schools.com:
https://www.w3schools.com/cs/cs_user_input.asp
C#-Exception Handling. (n.d.). Retrieved September 24, 2020, from tutorialspoint.com:
https://www.tutorialspoint.com/csharp/pdf/csharp_exception_handling.pdf
Control Statements. (n.d.). Retrieved September 23, 2020, from myweb.sabanciuniv.edu:
http://myweb.sabanciuniv.edu/gulsend/files/2009/04/control.pdf
c-sharpcorner.com. (n.d.). Jagged Array in C#. Retrieved September 24, 2020, from c-
sharpcorner.com: https://www.c-sharpcorner.com/UploadFile/puranindia/jagged-arrays-
in-C-Sharp-net/
Jump Statements in C#. (n.d.). Retrieved September 24, 2020, from idc-online.com:
http://www.idc-
online.com/technical_references/pdfs/information_technology/Jump_statements_in_Csh
arp.pdf
Klousen, P. (2012). Introduction to programming and the C# language. Poul Klausen &
bookboon.com. Retrieved September 23, 2020, from bookboon.com
Method Hiding in C#. (n.d.). Retrieved from geeksforgeeks.org:
https://www.geeksforgeeks.org/method-hiding-in-c-sharp/
Polymorphism (C# Programming Guide). (n.d.). Retrieved September 27, 2020, from
microsoft.com: https://docs.microsoft.com/en-us/dotnet/csharp/programming-
guide/classes-and-structs/polymorphism
tutorialspoint.com. (n.d.). C# - Arrays. Retrieved September 24, 2020, from tutorialspoint.com:
https://www.tutorialspoint.com/csharp/csharp_arrays.htm
106
tutorialspoint.com. (n.d.). C# - Multidimensional Arrays. Retrieved September 24, 2020, from
tutorialspoint.com:
https://www.tutorialspoint.com/csharp/csharp_multi_dimensional_arrays.htm
tutorialspoint.com. (n.d.). Jagged Arrays. Retrieved September 24, 2020, from tutorialspoint.:
https://www.tutorialspoint.com/csharp/csharp_jagged_arrays.htm
Vatsa, A. K. (2019, February 24). Static Method In C#. Retrieved September 24, 2020, from .c-
sharpcorner.com: https://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/static-
methods-in-C-Sharp/