0% found this document useful (0 votes)
16 views

Lab 1

The document provides an introduction to object oriented programming concepts in C# and .NET Framework. It discusses key OOP concepts like objects, classes, inheritance and polymorphism. It also introduces the C# programming language, data types in C#, comments, namespaces and basic programs. Finally, it discusses the .NET Framework architecture including the Common Language Runtime and layers like ASP.NET and Windows Forms. It provides exercises to write programs to calculate marks/percentage and implement a basic four function calculator.

Uploaded by

Muhammad Tuaha
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)
16 views

Lab 1

The document provides an introduction to object oriented programming concepts in C# and .NET Framework. It discusses key OOP concepts like objects, classes, inheritance and polymorphism. It also introduces the C# programming language, data types in C#, comments, namespaces and basic programs. Finally, it discusses the .NET Framework architecture including the Common Language Runtime and layers like ASP.NET and Windows Forms. It provides exercises to write programs to calculate marks/percentage and implement a basic four function calculator.

Uploaded by

Muhammad Tuaha
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/ 7

Object Oriented Programming

Lab # 1
Object:
Introduction to Object Oriented Programming with C#, .Net Framework and Visual Studio 2022.

Theory:

Introduction.
The fundamental idea behind object-oriented languages is to combine into a single unit both data and the
functions that operate on that data. Such a unit is called an object. An object’s functions, called member
functions in C#, typically provide the only way to access its data.

To read a data item in an object, member function in the object is called, which in turn will access the data
and return the value. The data cannot be accessed directly. The data is hidden, so it is safe from accidental
alteration. Data encapsulation and data hiding are key terms in object-oriented languages. This simplifies
writing, debugging, and maintaining the program.

A C# program typically consists of a number of objects, which communicate with each other by calling one
another’s member functions. Member functions are also called methods in some other object-oriented (OO)
languages. Also, data items are referred to as attributes or instance variables, features.

Characteristics of Object-Oriented Languages.


The major elements of object-oriented languages in general, and C# in particular are:
• Objects
• Classes • Inheritance.
• Reusability
• Polymorphism and Overloading.

Introduction to C#
C# is a cross-platform language that can be used to create high-performance applications. C# was developed
by Anders Hejlsberg, as an extension to the C, C++ and Java language. C# gives programmers a high level
of control over system resources and memory.

Introduction of Headers
When you use a library function in a program, you must include the library function's header. The using
declaration is used to do this.
Header files in C# include a collection of predefined standard library functions. One requests that a header
file be used in his/her program by adding it with the preprocessing directive “using". The contents of a
header file may be used in our application by including it. A header file contains:
• Function definitions
• Data type definitions

It provides the functionalities by importing them into the application using the preprocessor instruction
"using". The preprocessor directives tell the compiler that these files must be handled before compilation.

There are of 2 types of header file:


• Pre-existing header files: These are files that are already present in the C# compiler and just need
to be imported.
• User-specified header files: These files are defined by the user and can be imported using "using".

4
Object Oriented Programming

Namespaces
A namespace in C# is a way to organize a set of related objects, such as classes, interfaces, and enums. A
namespace can help to avoid name conflicts and to create globally unique types. A namespace can also contain
other namespaces, forming a namespace hierarchy.

A Basic C# Program.
using System; // Import the System namespace

Console.WriteLine("Please enter your name:"); // Write a message to the user


string name = Console.ReadLine(); // Read a line of input from the user and store it in a variable
Console.WriteLine("Hello, " + name + "!"); // Write a message to the user with the input

Data Types:

C# supports the following basic data types:

Data Type Size Description


bool 1 byte Stores true or false values
char 1 byte Stores a single character/letter/number, or ASCII
values
int 2 or 4 bytes Stores whole numbers, without decimals
float 4 bytes Stores fractional numbers, containing one or more
decimals. Sufficient for storing 7 decimal digits
double 8 bytes Stores fractional numbers, containing one or more
decimals. Sufficient for storing 15 decimal digits
String Data Type:

Apart from these basic types, C# also support ‘string’ data type to store multiple characters. i.e., a series of
characters or text. String values must be enclosed in double quotations.
string introduction = "Welcome to OOP Lab"; Console.WriteLine(introduction);

Comments in C#

A comment is text that is ignored by the compiler yet is beneficial to programmers. Normally, comments
are intended to mark code for future reference. They are treated as white space by the compiler. C# supports
two types of comments
• Single line comment – The // (two slashes) characters, followed by any character sequence. This
type of comment is terminated by a new line that is not immediately followed by a backslash.
• Multiple Line Comment – The characters /* (slash, asterisk), followed by any sequence of
characters (including new lines), followed by the characters */.

Introduction to Dot Net Framework


.NET is a collection of tools, technologies, and languages that all work together in a framework to provide
the solutions that are needed to easily build and deploy truly robust enterprise applications. These .NET
applications are also able to easily communicate with one another and provide information and application
logic, regardless of platforms and languages.

5
Object Oriented Programming

The first thing that you should notice when looking at this diagram is that the .NET Framework sits on top
of the operating system. Presently, the operating systems that can take the .NET Framework include
Window.

At the base of the .NET Framework is the Common Language Runtime (CLR). The CLR is the engine that
manages the execution of the code.

The next layer up is the .NET Framework Base Classes. This layer contains classes, value types, and
interfaces that you will use often in your development process. Most notably within the .NET Framework
Base Classes is ADO.NET, which provides access to and management of data.

The third layer of the framework is ASP.NET and Windows Forms. ASP.NET should not be viewed as the
next version of Active Server Pages after ASP 3.0, but as a dramatically new shift in Web application
development. Using ASP.NET, it’s now possible to build robust Web applications that are even more
functional than Win32 applications of the past.

The second part of the top layer of the .NET Framework is the Windows Forms section. This is where you
can build the traditional executable applications that you built with Visual Basic 6.0 in the past. There are
some new features here as well, such as a new drawing class and the capability to program these
applications in any of the available .NET languages.

Introduction to Visual Studio 2022


Microsoft Visual Studio is an integrated development environment (IDE) from Microsoft for creating,
documenting, and debugging programs written in a verity of .net programming languages.
It is used to develop console and graphical user interface applications along with Windows Forms
applications, web sites, web applications, and web services in both native code together with managed code
for all platforms supported by Microsoft Windows, Windows
Mobile, Windows CE, .NET Framework, .NET Compact Framework and Microsoft
Silverlight.

6
Object Oriented Programming
Exercise:
1. Write a program that take input of your roll number along with the marks obtained in five subjects
and display the total marks obtained and the percentage.

7
Object Oriented Programming
2. Write a program to implement four function calculators. Allow user to provide input and select the
operation to be performed

8
Object Oriented Programming

9
Object Oriented Programming

10

You might also like