Project "Numbers"

Concepts Covered

  • Pointers
  • Dynamic Memory Management

Create a program that records a number of integer values entered by the user. The user should be able to add new numbers, print the numbers entered so far, and quit the program. See Figure 1 for an example of this program being executed. See image.

Notes:

  • This project does not use SwinGame, so you can start the code from scratch. Open your text editor and save the empty text file as numbers.c.
  • At the top of the file import stdio.h and stdlib.h
  • Following this, declare a int_array structure using the details in Table 1. See image.
  • Implement the functions and procedures for the Numbers program. See image.
  • Declare a read_integer function that has the following pseudocode. This function will be responsible for reading the user's input and making sure that it is an integer value. See image.
  • Declare a init_int_array procedure using the following pseudocode. This procedure will be responsible for initialising a new int_array, setting it to start with no elements in it. See image.
  • Declare the add_new_int procedure using the following pseudocode. This procedure will read a value from the user and store it in the int array. See image.
  • Declare the print_int_array procedure using the following pseudocode. This will print all of the values from the array. See image.
  • Finish the program by declaring the main function using the following pseudocode. This will create space to store an int_array, and will then loop asking the user if they want to "add", "print", or "quit”. See image.
  • Compile your program and correct any syntax errors.
  • Run your program and make sure it works correctly.

Project "Linked Numbers"

Concepts Covered

  • Pointers
  • Dynamic Memory Management
  • Linked Data Structures

Project Description

This program will demonstrate an alternate implementation of the Numbers program, using a linked data struc- ture rather than a dynamic array. Like with the Numbers program you need to create a program that records a number of integer values entered by the user. The user should be able to add new numbers, print the num- bers entered so far, and quit the program. See Figure 3 for an example of this program being executed.

Note:

  • Like the Numbers program, this project does not use SwinGame, so you can start the code from scratch. Open your text editor and save the empty text file as linked_numbers.c.
  • At the top of the file import stdio.h and stdlib.h
  • Following this, declare a node structure using the details in Table 2. See image.
  • Hint: This will require that you use the explicit structure name of the type as the node structure contains a pointer to a node. The code for this will appear as shown below: See image.
  • Next declare a int_list structure using the details in Table 3. See image.
  • Implement the functions and procedures for the Linked Numbers program as shown in Figure 4. See image.
  • Copy the read_integer function from the Numbers program. Below this implement the init_int_list procedure. This procedure will be responsible for initialising a new int_list value. The pseudocode for this is shown below: See image.
  • Implement the add_new_int procedure using the following pseudocode. This code is responsible for allocating space for a new node, and adding it to the start of the list. See image.
  • Implement the print_int_list procedure using the following pseudocode. This code is responsible for printing all of the values from the list to the Terminal. See image.
  • Finally implement the main function using the pseudocode below. This will create space to store an int_list, and will then loop asking the user if they want to "add", "print", or "quit”. See image.
  • Compile your program and correct any syntax errors.
  • Run your program and make sure it works correctly.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.