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.
- Start Microsoft Visual Studio.
- Choose New Project from the File
- Select the Visual C++ template and choose Win32 Console Application.
- 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.
- When the Win32 Application Wizard starts hit the Next>
- Choose Empty Project and uncheck Security Development Lifecycle (SDL), and click
Finish.
- From the Project menu, choose Add New Item
- 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.
- The new empty file should now be open. Write a simple program (that is, a main method) that displays hello world on the console.
- 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
- 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.
- 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).
- 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).
- Modify your main function (e.g. c) so that you:
- Create a List
- Declare an int for storing input
- scanf into the int
- start a while loop that continues until your int has the value 0
- inside the while loop
- add the int to your list
- scanf a new int
- destroy the list
- Test the above version
- Now modify your main to use a simple menu for selecting functions. The new main should:
- Create a List called my_list
- Create an int called quit to that tells the program when to stop and give it the value 0 (false)
- Start a while loop that exits if quit is true (while (!quit){})
- inside the while loop
- Create an int called option
- 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)
- if option has the value 2, call a new function called option_delete(&my_list)
- if option has the value 3, call a new function called option_print(&my_list)
- destroy the list
- 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)
- Test the new version
If you have time
- Add a list function called reverse that takes a list and returns a new list that is the reverse of the given list
- Add a list function called merge that takes two ordered lists as parameters and creates a merged list that is also ordered
- See if you can do it without using insert_in_order or nested loops

![[Solved] KIT205 Week 2 Tutorial](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] KIT205 Week5 Tutorial](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.