Introduction - WordPress.com · 2020. 4. 13. · Fundamentals of Software Programming I n t r o d u...

42
CompTIA IT Fundamentals+ Fundamentals of Software Programming Introduction Lab Topology Exercise 1 - Using Different Data Types in a Console Application Exercise 2 - Demonstrating the Difference between Compiled and Interpreted Languages Review Introduction HTML Programming Console application Visual Studio 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. 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

Transcript of Introduction - WordPress.com · 2020. 4. 13. · Fundamentals of Software Programming I n t r o d u...

  • CompTIA IT Fundamentals+

    Fundamentals of Software Programming

    IntroductionLab TopologyExercise 1 - Using Different Data Types in a Console ApplicationExercise 2 - Demonstrating the Difference between Compiled andInterpreted LanguagesReview

    Introduction

    HTMLProgrammingConsole applicationVisual Studio

    Welcome to the Fundamentals of Software Programming Practice Lab. In thismodule, you will be provided with the instructions and devices needed to develop yourhands-on skills.

    Learning Outcomes

    In this module, you will complete the following exercises:

    Exercise 1 - Using Different Data Types in a Console ApplicationExercise 2 - Demonstrating the Difference Between Compiled and InterpretedLanguages

    After completing this lab, you will be able to:

    Demonstrate different data typesDemonstrate compiled languageDemonstrate 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 examobjectives. We recommend referring to course material or a search engine toresearch theoretical topics in more detail.

    Lab Duration

    It will take approximately 60 minutes to complete this lab.

    Help and Support

    For more information on using Practice Labs, please see our Help and Support page.You can also raise a technical support ticket from this page.

    Click Next to view the Lab topology used in this module.

    Lab Topology

    During your session, you will have access to the following lab configuration.

  • Depending on the exercises, you may or may not use all of the devices, but they areshown here in the layout to get an overall understanding of the topology of the lab.

    PLABDC01 - Domain Controller (Windows Server 2019)PLABDM01 - Domain Member (Windows Server 2019)PLABSA01 - Standalone Server (Windows Server 2019)PLABWIN10 - Workstation (Windows 10 Pro)

    Click Next to proceed to the first exercise.

    Exercise 1 - Using Different Data Types in aConsole Application

  • Basic data types used in a programming language include int, float, character, string, andarrays.

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

    Please refer to your course material or use your favorite search engine to research thistopic 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 andmemory space required to store them.

    In this task, you will demonstrate the different data types by creating a Visual C# consoleapplication in the Visual Studio 2017 IDE.

  • Step 1

    Note: In order to gain access to Visual Studio 2017 you will be required tocreate/entering a Microsoft accepted credentials into visual studio. This can useyour 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 tocomplete this module.

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

    Connect to PLABSA01.

    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.

  • Figure 1.1 Screenshot of the PLABSA01 desktop: Relevant option on the Bestmatch pop-up menu is selected.

    Step 2The Start Page - Microsoft Visual Studio is displayed.

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

  • Figure 1.2 Screenshot of the PLABSA01 desktop: Relevant option on the StartPage - Microsoft Visual Studio window is selected.

    Step 3The New Project dialog box is displayed.

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

    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 andfor 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 andlocation if required.

    Figure 1.3 Screenshot of the PLABSA01 desktop: New Project dialog box isdisplayed showing the required settings performed and the OK buttonhighlighted.

    Step 4Visual Studio 2017 creates a new console application.

    Notice that the name of the application appears in the title bar of the Visual Studiowindow and a relevant blank Program.cs file is displayed.

  • Figure 1.4 Screenshot of the PLABSA01 desktop: Program.cs file is displayed inthe ConsoleApp1 - Microsoft Visual Studio window.

    Step 5Add 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 datafor 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_varaible; 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_varaible = 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_varaible); Console.ReadLine();

    The following table shows the keywords to represent basic data types in C#.

    Figure 1.5 Table containing five columns & 9 rows, column 1 (Sl Number) lists 9rows numbers 1 to 9, column 2 (Data Type), column 3 (C# Keyword), column 4(Size in Bytes) and column 5 (Range). Each row under column 1 (Sl number) iscross referenced as follows. Sl number ("1") = Data Range ("Short int") = C#Keyword ("Short") = Size in Bytes ("2") = Range ("-32768 to +32767"). Sl

  • number ("2") = Data Range ("Unsigned short int") = C# Keyword ("ushort") =Size in Bytes ("2") = Range ("0 to 65535"). Sl number ("3") = Data Range("Signed Int") = C# Keyword ("int") = Size in Bytes ("4") = Range("2147483648 to +2147483647"). Sl number ("4") = Data Range ("Unsignedint") = C# Keyword ("unit") = Size in Bytes ("4") = Range ("0 to 4294967295".Sl number ("5") = Data Range ("Signed long Int") = C# Keyword ("Long") =Size in Bytes ("8") = Range ("-9223372036854775808 to+9223372036854775807"). Sl number ("6") = Data Range ("Unsigned longInt") = C# Keyword ("ulong") = Size in Bytes ("8") = Range ("0 to18446744073709551615"). Sl number ("7") = Data Range ("Float") = C#Keyword ("float") = Size in Bytes ("4") = Range ("-3.4 E-38 to 3.4E+38"). Slnumber ("8") = Data Range ("Double") = C# Keyword ("Double") = Size inBytes ("8") = Range ("-1.7 E--308 to 1.7E+308"). Sl number ("8") = Data Range("Character") = C# Keyword ("char") = Size in Bytes ("2") = Range (N/A).

    Figure 1.6 Screenshot of the PLABSA01 desktop: Required code is typed intothe Program.cs window.

  • Step 6To save the program, access the File menu and then select Save Program.cs, or pressCtrl+S.

    Figure 1.7 Screenshot of the PLABSA01 desktop: File > Save Program.cs menu-options are selected on the Microsoft Visual Studio window.

    Step 7To execute or run the Visual C# console application, access the Debug tab, then selectStart Debugging or press F5.

  • Figure 1.8 Screenshot of the PLABSA01 desktop: Debug > Start Debuggingmenu-options are selected on the Microsoft Visual Studio window.

    Step 8The 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 windowprompts you to enter inputs for the different data types.

  • Figure 1.9 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing results of the program typed-in earlier.

    Step 9Enter the number or character for each data type as the program output prompts. Forexample, input the following values and press Enter after you type each input:

    Enter a signed integer, type -9867453Enter an unsigned integer, type 8765465Enter a signed short integer, type -32456Enter a unsigned short integer, type 64000Enter a signed long integer, type -98765543Enter a unsigned long integer, type 9944159844Enter a float number, type 3.2E-28Enter a double number, type -1.1E300

  • Enter a character, type t

    Figure 1.10 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing the required input values entered.

    Step 10The output displays the values that you entered along with their data type.

  • Figure 1.11 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing results of the program typed-in earlier.

    Step 11Next, 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, itinitializes a single-dimensional and two-dimensional integer arrays, and outputs thelength 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();

    Step 12To save the program, access the File tab, select Save Progam.cs or press Ctrl+S.

  • Figure 1.12 Screenshot of the PLABSA01 desktop: File > Save Program.csmenu-options are selected on the Microsoft Visual Studio window.

    Step 13To execute or run the program, access the Debug tab, and select Start Debugging orpress F5.

  • Figure 1.13 Screenshot of the PLABSA01 desktop: Debug > Start Debuggingmenu-options are selected on the Microsoft Visual Studio window.

    Step 14The output console appears and displays the output of the string variable, and the singleand two-dimensional arrays.

  • Figure 1.14 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing results of the program typed-in earlier.

    Close the output console window and Microsoft Visual Studio.

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

    Exercise 2 - Demonstrating the Difference betweenCompiled and Interpreted Languages

    Programming languages can be classified as compiled languages and interpretedlanguages. 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 andconverts it into machine language for processing. For example, JavaScript.

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

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

    Learning Outcomes

    After completing this exercise, you will be able to:

    Demonstrate compiled languageDemonstrate 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.

    Step 1Ensure 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.

    Figure 2.1 Screenshot of the PLABSA01 desktop: Relevant option on the Bestmatch pop-up menu is selected.

    Step 2The Visual Studio Start Page appears.

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

  • Figure 2.2 Screenshot of the PLABSA01 desktop: Relevant option on the StartPage - Microsoft Visual Studio window is selected.

    Step 3The 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.

  • Figure 2.3 Screenshot of the PLABSA01 desktop: New Project dialog box isdisplayed showing the required settings performed and the OK buttonhighlighted.

    Step 4A new console application is created and a blank Program.cs file appears.

  • Figure 2.4 Screenshot of the PLABSA01 desktop: Program.cs file is displayed inthe ConsoleApp1 - Microsoft Visual Studio window.

    Step 5Add 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 aneven number.

    Figure 2.5 Screenshot of the PLABSA01 desktop: Required code is typed intothe Program.cs window.

    Step 6

  • To compile the C# console application, access the Debug tab and then select StartDebugging or press F5.

    Visual Studio 2017 uses a compiler to compile the program. A compiler takes the entireprogram as input and compiles it into a machine language for processing.

    Figure 2.6 Screenshot of the PLABSA01 desktop: Debug > Start Debuggingmenu-options are selected on the Microsoft Visual Studio window.

    Step 7After compilation, the program is executed.

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

  • Figure 2.7 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing results of the program typed-in earlier.

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

    Press Enter.

    The message Entered Even Number is displayed.

  • Figure 2.8 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing the required input value typed-in and the result of the code.

    Step 9Run the application again. This time the already compiled code - the machine language ofthe program - is executed. The compiled program runs faster.

    When prompted, type:

    7

    The message Entered Odd Number is displayed.

  • Figure 2.9 Screenshot of the PLABSA01 desktop: Output console window isdisplayed showing the required input value typed-in and the result of the code.

    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 asJavaScript by creating an ASP.NET Web application project in Visual Studio 2017.

    Step 1On 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.

  • Figure 2.10 Screenshot of the PLABSA01 desktop: File > New > Project menu-options are selected on the Microsoft Visual Studio window.

    Step 2In 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.

  • Figure 2.11 Screenshot of the PLABSA01 desktop: New Project dialog box isdisplayed showing the required settings performed and the OK buttonhighlighted.

    Step 3Visual Studio 2017 creates an empty website.

  • Figure 2.12 Screenshot of the PLABSA01 desktop: WebSite1 - Microsoft VisualStudio window is displayed.

    Step 4In the Solution Explorer pane on the right, right-click WebSite1, and from thecontext menu, select the Add > Add New Item options.

  • Figure 2.13 Screenshot of the PLABSA01 desktop: Context menu (that appearson right-clicking the WebSite1 option) > Add > Add New Item menu-optionsare selected on the Solution Explorer pane of the WebSite1 - Microsoft VisualStudio window.

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

  • Figure 2.14 Screenshot of the PLABSA01 desktop: Add New Item dialog box isdisplayed showing the required settings performed and the Add buttonhighlighted.

    Step 6A new HTML page appears with default tags.

    In HTMLPage.html, add the following JavaScript inside the tag.

    alert("Welcome to Practice Lab");

  • Figure 2.15 Screenshot of the PLABSA01 desktop: Required code is typed ontothe HtmlPage.html page on the Microsoft Visual Studio window.

    The code displays a message box with a welcome message.

    Step 7To save the file, access the File tab, select Save HtmlPage.html or press Ctrl+S.

  • Figure 2.16 Screenshot of the PLABSA01 desktop: File > Save HtmlPage.htmlmenu-options are selected on the Microsoft Visual Studio window.

    Step 8To run the Web page in Internet Explorer, access the Debug tab, select StartDebugging or press F5.

  • Figure 2.17 Screenshot of the PLABSA01 desktop: Debug > Start Debuggingmenu-options are selected on the Microsoft Visual Studio window.

    Step 9The Html Page opens in Internet Explorer, and the Welcome to Practice Lab messageis displayed in a message box.

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

  • Figure 2.18 Screenshot of the PLABSA01 desktop: Browser window is displayedshowing results of the program typed-in earlier.

    Click OK and close Internet Explorer.

    Step 10Access the FILE menu, select Close Solution to close the WebSite1-MicrosoftVisual Studio window.

  • Figure 2.19 Screenshot of the PLABSA01 desktop: File > Close Solution menu-options are selected on the Microsoft Visual Studio window.

    Keep all devices that you have powered on in their current state and proceed to thenext exercise.

    Review

    Well done, you have completed the Fundamentals of Software ProgrammingPractice Lab.

    Summary

  • You completed the following exercises:

    Exercise 1 - Using Different Data Types in a Console ApplicationExercise 2 - Demonstrating the Difference Between Compiled and InterpretedLanguages

    You should now be able to:

    Demonstrate different data typesDemonstrate compiled languageDemonstrate interpreted language

    Feedback

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