[Solved] KIT205 Week 2 Tutorial

$25

File Name: KIT205_Week_2_Tutorial.zip
File Size: 207.24 KB

SKU: [Solved] KIT205 Week 2 Tutorial Category: Tag:
5/5 - (1 vote)

Creating a new project

We will be using Microsoft Visual Studio in this unit. You should follow the instructions below when creating a new project.

  1. Start Microsoft Visual Studio.
  2. Choose New Project from the File
  3. Select the Visual C++ template and choose Win32 Console Application.
  4. Enter a name for the project (e.g. Week2) and check the location at the bottom of the New Project window (you probably want to put it on your network drive in a folder for KIT205). Click OK.
  5. When the Win32 Application Wizard starts hit the Next>
  6. Choose Empty Project and uncheck Security Development Lifecycle (SDL), and click

Finish.

  1. From the Project menu, choose Add New Item
  2. Choose a new C++ File and give it a name (e.g. c). Make sure that you change the filename extension from .cpp to .c.
  3. The new empty file should now be open. Write a simple program (that is, a main method) that displays hello world on the console.
  4. Run the program without debugging (Ctrl F5) so that the console window isnt immediately closed.

Creating and Testing a Linked List

You will need to #include <stdlib.h> to be able to use NULL If you declare your list as: List my_list = new_list(); you will need to pass &my_list as the first parameter to the other list functions Depending on your project settings, you may need to use scanf_s, instead of scanf (check online for more info)

Next we are going to get a linked list up and running. You may find some of the instructions a little light on detail; that is deliberate. If you need extra help, ask your tutor but try and work it out for yourself first. J

  1. Add the linked list code from the lectures. The struct, typedef and function prototypes should go in a new header file called h and the function implementations should go in a new source file called list.c.
  2. Test the linked list by modifying your main function so that it creates a list by adding some ints (insert_at_front) and then printing the list (print_list).
  3. Test the other functions (insert_in_order, delete_from_list, destroy) as well.

Testing Infrastructure

In this unit we will be doing a lot of console-based testing. The following steps will make a start on setting up some testing code (either comment your existing code, or create a new project before continuing).

  1. Modify your main function (e.g. c) so that you:
    1. Create a List
    2. Declare an int for storing input
    3. scanf into the int
    4. start a while loop that continues until your int has the value 0
    5. inside the while loop
      1. add the int to your list
      2. scanf a new int
    6. destroy the list
  2. Test the above version
  3. Now modify your main to use a simple menu for selecting functions. The new main should:
    1. Create a List called my_list
    2. Create an int called quit to that tells the program when to stop and give it the value 0 (false)
    3. Start a while loop that exits if quit is true (while (!quit){})
    4. inside the while loop
      1. Create an int called option
      2. Print a prompt and scanf into option
  • if option has the value 0, set quit to 1 iv. if option has the value 1, call a new function called option_insert(&my_list)
  1. if option has the value 2, call a new function called option_delete(&my_list)
  2. if option has the value 3, call a new function called option_print(&my_list)
  1. destroy the list
  1. Create the option_insert, option_delete,and option_print in the same file as main and add/copy code to manipulate the list using your list functions (e.g.

option_insert will read an int and then call insert_at_front)

  1. Test the new version

If you have time

  1. Add a list function called reverse that takes a list and returns a new list that is the reverse of the given list
  2. Add a list function called merge that takes two ordered lists as parameters and creates a merged list that is also ordered
  3. See if you can do it without using insert_in_order or nested loops

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] KIT205 Week 2 Tutorial[Solved] KIT205 Week 2 Tutorial
$25