0% found this document useful (0 votes)
3 views30 pages

Lab Instructions Fundamentals of Software Programming

The document outlines a practice lab for the Fundamentals of Software Programming, focusing on hands-on exercises with data types and the differences between compiled and interpreted languages. Participants will complete two main exercises: using different data types in a console application and demonstrating the execution of compiled versus interpreted languages. The lab aims to equip learners with practical skills in programming concepts using Visual Studio 2017.

Uploaded by

joeyfjr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views30 pages

Lab Instructions Fundamentals of Software Programming

The document outlines a practice lab for the Fundamentals of Software Programming, focusing on hands-on exercises with data types and the differences between compiled and interpreted languages. Participants will complete two main exercises: using different data types in a console application and demonstrating the execution of compiled versus interpreted languages. The lab aims to equip learners with practical skills in programming concepts using Visual Studio 2017.

Uploaded by

joeyfjr
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Fundamentals of Software

Programming
Introduction
Objective
Welcome to the Fundamentals of Software Programming Practice Lab. In this module, you will
be provided with the instructions and devices needed to develop your hands-on skills.

Overview

Learning Outcomes:
In this module, you will complete the following exercises:

Exercise 1 - Using Different Data Types in a Console Application


Exercise 2 - Demonstrating the Difference Between Compiled and Interpreted Languages

After completing this lab, you will be able to:

Demonstrate different data types


Demonstrate compiled language
Demonstrate interpreted language

Exam Objectives:
The following exam objectives are covered in this lab:

1.2 Compare and contrast fundamental data types and their characteristics.
4.1 Compare and contrast programming language categories.
4.3 Explain the purpose and use of programming concepts.

Note: Our main focus is to cover the practical, hands-on aspects of the exam
objectives. We recommend referring to course material or a search engine to
research theoretical topics in more detail.

Exercise 1 - Using Different Data Types in a Console


Application
Basic data types used in a programming language include int, float, character, string, and
arrays.

In this exercise, you will use different data types in a console application. You will use Visual
Studio 2017 as the integrated development environment (IDE) to demonstrate the tasks in this
exercise.

Please refer to your course material or use your favorite search engine to research this topic in
more detail.

Learning Outcomes
After completing this exercise, you will be able to:

Demonstrate different data types

Your Devices
You will be using the following device in this exercise. Please power this on now.

PLABSA01 - Standalone Server (Windows Server 2019)

Task 1 - Demonstrate Different Data Types


Various data types used in an application are declared at the beginning of a program. Every
data type is further classified based on their characteristics, such as sign and memory space
required to store them.

In this task, you will demonstrate the different data types by creating a Visual C# console
application in the Visual Studio 2017 IDE.
1 Click the Start button.

2 Ensure you have powered the devices mentioned in the introduction to this module.

Note: In order to gain access to Visual Studio 2017 you will be required to
create/entering a Microsoft accepted credentials into visual studio. This can use
your credentials to sign into skype or a Microsoft account.
If you do not have a Microsoft account, you will have to create one in order to
complete this module.

Connect to PLABSA01.

Sign in with the following credentials:

Username: Administrator

Password: Passw0rd

Click the Type here to search icon on the taskbar.

On the Type here to search bar, type visual .

On the Best match pop-up menu, select Visual Studio 2017.


3 The Start Page - Microsoft Visual Studio is displayed.

Click the Create new project… link to create a new Visual C# console application project.

4 The New Project dialog box is displayed.

This dialog box lists the different default application types that Visual Studio 2017 can create.

On the Installed templates list, expand Visual C# and select Windows Desktop. Then, on the
middle pane, select Console Application.

Click OK.

Note: The New Project dialog box displays a default name for the application and
for the Solution along with a default location. The name of the Solution is usually the
same as the application name. You can change these default names and location if
required.
5 Visual Studio 2017 creates a new console application.

Notice that the name of the application appears in the title bar of the Visual Studio window
and a relevant blank Program.cs file is displayed.
6 Add the following C# code in the Main function on Program.cs.

The code displays the size of the basic data types in bytes and prompts users to input data for
these data types:
int signed_int;
uint unsigned_int;
short short_int;
ushort unsigned_short_int;
long long_int;
ulong unsigned_long_int;
float floating_Number;
double double_Number;
char character_variable;
Console.WriteLine("Size of Signed Integer : {0} ", sizeof(int));
Console.WriteLine("Size of UnSigned Integer : {0}", sizeof(uint));
Console.WriteLine("Size of Signed Short Integer : {0}", sizeof(short));
Console.WriteLine("Size of UnSigned Short Integer : {0}", sizeof(ushort));
Console.WriteLine("Size of Signed Long Integer : {0}", sizeof(long));
Console.WriteLine("Size of UnSigned Long Integer : {0}", sizeof(ulong));
Console.WriteLine("Size of float : {0}", sizeof(float));
Console.WriteLine("Size of double : {0}", sizeof(double));
Console.WriteLine("Size of Character : {0} ", sizeof(char));
Console.Write("Enter a Signed Integer : ");
signed_int = int.Parse(Console.ReadLine());
Console.Write("Enter a UnSigned Integer : ");
unsigned_int = uint.Parse(Console.ReadLine());
Console.Write("Enter a Signed Short Integer : ");
short_int = short.Parse(Console.ReadLine());
Console.Write("Enter a Unsigned Short Integer : ");
unsigned_short_int = ushort.Parse(Console.ReadLine());
Console.Write("Enter a Signed Long Integer : ");
long_int = long.Parse(Console.ReadLine());
Console.Write("Enter a Unsigned Long Integer : ");
unsigned_long_int = ulong.Parse(Console.ReadLine());
Console.Write("Enter a Float Number : ");
floating_Number = float.Parse(Console.ReadLine());
Console.Write("Enter a Double Number: ");
double_Number = double.Parse(Console.ReadLine());
Console.Write("Enter a Character: ");
character_variable = char.Parse(Console.ReadLine());
Console.WriteLine("Signed Integer value is :{0}", signed_int);
Console.WriteLine("UnSigned Integer value is :{0}", unsigned_int);
Console.WriteLine("Signed Short Integer value is :{0}", short_int);
Console.WriteLine("UnSigned Short Integer value is :{0}", unsigned_short_int);
Console.WriteLine("Signed Long Integer value is :{0}", long_int);
Console.WriteLine("UnSigned Long Integer value is :{0}", unsigned_long_int);
Console.WriteLine("Float value is :{0}", floating_Number);
Console.WriteLine("Double value is :{0}", double_Number);
Console.WriteLine("Character value is :{0}", character_variable);
Console.ReadLine();

The following table shows the keywords to represent basic data types in C#.
7 To save the program, access the File menu and then select Save Program.cs, or press

Ctrl+S.
8 To execute or run the Visual C# console application, access the Debug tab, then select

Start Debugging or press F5.

9 The output console window appears and displays the result of the program.
The output displays the memory size of the basic data types. Also, the console window
prompts you to enter inputs for the different data types.

10 Enter the number or character for each data type as the program output prompts. For

example, input the following values and press Enter after you type each input:

Enter a signed integer, type -9867453


Enter an unsigned integer, type 8765465
Enter a signed short integer, type -32456
Enter a unsigned short integer, type 64000
Enter a signed long integer, type -98765543
Enter a unsigned long integer, type 9944159844
Enter a float number, type 3.2E-28
Enter a double number, type -1.1E300
Enter a character, type t
11 The output displays the values that you entered along with their data type.

Close the console window.

12 Next, you will illustrate derived data types such as strings and arrays.
Clear the previous code in the main function and enter the following code.

The code declares and initializes a variable of string type and outputs its value. Also, it
initializes a single-dimensional and two-dimensional integer arrays, and outputs the length
and the contents of these arrays on the console:
String StringVariable;
StringVariable = "Welcome to Practice Lab";
Console.WriteLine("Content of String Variable : {0}", StringVariable);
Console.WriteLine();
int[] integer_array = { 1, 2, 3, 4, 5 }; //Single Dimensional array
Console.WriteLine("Integer Array Length : {0}", integer_array.Length);
Console.WriteLine("Integer Array Content : ");
foreach (int element in integer_array)
Console.WriteLine(element);
Console.WriteLine();
int[,] two_Dim_Array = new int[2,2];
two_Dim_Array[0,0] = 2;
two_Dim_Array [0,1] = 3;
two_Dim_Array [1,0] = 4;
two_Dim_Array [1,1]=5;
Console.WriteLine("Two Dimesional Array Length : {0}",two_Dim_Array.Length);
Console.WriteLine("Two Dimesional Array Rank : {0}", two_Dim_Array.Rank);
Console.WriteLine("Two Dimesional Array Content : ");
foreach (int i in two_Dim_Array)
Console.WriteLine(i);
Console.ReadLine();
13 To save the program, access the File tab, select Save Progam.cs or press Ctrl+S.
14 To execute or run the program, access the Debug tab, and select Start Debugging or

press F5.
15 The output console appears and displays the output of the string variable, and the

single and two-dimensional arrays.

Close the output console window and Microsoft Visual Studio.

Leave the devices you have powered on in their current state and proceed to the
next exercise.

Exercise 2 - Demonstrating the Difference between


Compiled and Interpreted Languages
Programming languages can be classified as compiled languages and interpreted languages.
A compiler reads the entire code and transforms the source code into machine language for
processing. For example, C#. An interpreter reads each line at a time and converts it into
machine language for processing. For example, JavaScript.

In this exercise, you will demonstrate the difference between a compiled and an interpreted
language.

Please refer to your course material or use your favorite search engine to research this topic in
more detail.

Learning Outcomes
After completing this exercise, you will be able to:
Demonstrate compiled language
Demonstrate interpreted language

Your Devices
You will be using the following device in this exercise. Please power this on now.

PLABSA01 - Standalone Server (Windows Server 2019)

Task 1 - Demonstrate Compiled Language


In this task, you will demonstrate the execution of a compiled language such as Visual C# by
creating and executing a Visual C# project in the Visual Studio 2017 IDE.

1 Ensure that you are connected to PLABSA01, and the desktop is displayed.

Click the Type here to search icon on the taskbar.

On the Type here to search bar, type visual .

On the Best match pop-up menu, select Visual Studio 2017.


2 The Visual Studio Start Page appears.

Click the Create new project… link to create a visual C# console application project.
3 The New Project dialog box is displayed.

On the Installed templates list, expand Visual C# and select Windows Desktop. Then, on the
middle pane, select Console App.

Click OK.
4 A new console application is created and a blank Program.cs file appears.
5 Add the following lines of code in the Main function of Program.cs:

int i;
Console.Write("Enter a Number : ");
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.Write("Entered Even Number");
Console.Read();
}
else
{
Console.Write("Entered Odd Number");
Console.Read();
}

The code gets a number as an input from the user and checks whether it is an odd or an even
number.
6 To compile the C# console application, access the Debug tab and then select Start

Debugging or press F5.

Visual Studio 2017 uses a compiler to compile the program. A compiler takes the entire
program as input and compiles it into a machine language for processing.
7 After compilation, the program is executed.

The output console displays the message - Enter a Number - prompting the user for an entry.

8 Input any even number. For example, type 10.

Press Enter.

The message Entered Even Number is displayed.

9 Run the application again. This time the already compiled code - the machine

language of the program - is executed. The compiled program runs faster.

When prompted, type:


7
The message Entered Odd Number is displayed.

Close the output window and the Program.cs window.

Task 2 - Demonstrate Interpreted Language


In this task, you will demonstrate the execution of an interpreted language such as JavaScript
by creating an ASP.NET Web application project in Visual Studio 2017.

1 On the Visual Studio 2017 window, select the File tab.

From the menu, select New > Project.

Alternatively, press Ctrl+Shift+N to create a new project.

2 In the New Project dialog box, in the Installed Templates list, expand Visual C# > Web

> Previous Versions.

Now, in the middle pane, select ASP.NET Empty Web Site.

Click OK.
3 Visual Studio 2017 creates an empty website.

4 In the Solution Explorer pane on the right, right-click WebSite1, and from the context

menu, select the Add > Add New Item options.


5 On the Add New Item dialog box, access the middle pane, select HTML Page and

click Add.
6 A new HTML page appears with default tags.

In HTMLPage.html, add the following JavaScript inside the <body> tag.


<script>
alert("Welcome to Practice Lab");
</script>

The code displays a message box with a welcome message.

7 To save the file, access the File tab, select Save HtmlPage.html or press Ctrl+S.
8 To run the Web page in Internet Explorer, access the Debug tab, select Start

Debugging or press F5.


9 The Html Page opens in Internet Explorer, and the Welcome to Practice Lab message

is displayed in a message box.

When you execute this JavaScript web application, the web browser interprets the source
code and displays the output. The process does not include any compiling and saving the
source code as a machine language. Hence, an interpreted language is easier to debug and
support cross-platform functionality. However, it is often slower as every time you run the
application, an interpreter needs to interpret the source code. Moreover, the source code is
public, and everyone can view it.

Click OK and close Internet Explorer.

10 Access the FILE menu, select Close Solution to close the WebSite1-Microsoft Visual

Studio window.
Keep all devices that you have powered on in their current state and proceed to the
next exercise.

Review
Well done, you have completed the Fundamentals of Software Programming Practice Lab.

Summary
You completed the following exercises:

Exercise 1 - Using Different Data Types in a Console Application


Exercise 2 - Demonstrating the Difference Between Compiled and Interpreted Languages

You should now be able to:

Demonstrate different data types


Demonstrate compiled language
Demonstrate interpreted language

Feedback

Shutdown all virtual machines used in this lab before proceeding to the next module.
Alternatively, you can log out of the lab platform.

You might also like