Lab Instructions Fundamentals of Software Programming
Lab Instructions Fundamentals of Software Programming
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:
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.
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:
Your Devices
You will be using the following device in this exercise. Please power this on now.
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.
Username: Administrator
Password: Passw0rd
Click the Create new project… link to create a new Visual C# console application project.
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
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:
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
Leave the devices you have powered on in their current state and proceed to the
next exercise.
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.
1 Ensure that you are connected to PLABSA01, and the desktop is displayed.
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
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.
Press Enter.
9 Run the application again. This time the already compiled code - the machine
2 In the New Project dialog box, in the Installed Templates list, expand Visual C# > Web
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
click Add.
6 A new HTML page appears with default tags.
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
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.
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:
Feedback
Shutdown all virtual machines used in this lab before proceeding to the next module.
Alternatively, you can log out of the lab platform.