5

profiledomngo2
      • Part 5: Pointers
  •  
    • Design the solution.
    • For the quantities, use a pointer to the first item of an array of int. An example of the declaration code may look like the following:
      • int * numbers;
      • numbers = new int [n];
    • For the products, use an array of pointers to strings, and dynamically allocate space for each of the strings. An example of the declaration code may look like the following:
      • char Temp[100]; // to hold the entry
      • char * products [100]; // to hold the products
    • To fill in the products array, read one product name from the user, check the length, and then allocate memory based on the length of the entered word. The following code is provided as an example:
      • cin >> Temp; // to get the product
      • int len = strlen(Temp) +1 ; // to determine the length of the product name
      • char* newProduct = new char[len]; // to allocate memory
      • strcpy(newProduct, Temp); // to copy the entry to a new product
      • products[0] = newProduct; // to save in the array
    • Use the previous structure to provide the same functionality that was provided in Week 4.
    • By the end of Week 5, your application should work as follows:
      • Ask the customer to enter his or her details (e.g., name and address).
      • Print a welcome message that includes the customer’s name.
      • Provide a list of available products with descriptions.
      • Ask the customer to select products and quantities.
      • Save the provided details in the new data structure.
      • Read from the arrays to print the order summary (e.g., the products, quantities, and total price for each product).
      • Calculate and print total price for the order.
      • Release the allocated memory.
      • Add comments to your code.
  • The Documentation
    • Update the project document with a new date and project name.
    • Update previously completed sections based on instructor feedback.
    • New content: Strings and Arrays
      • Summarize the changes that you implemented.

Discuss how using dynamic memory allocation changed your application structure.

    • 11 years ago
    • 3
    Answer(0)
    Bids(0)