BEST代写-线上编程学术专家

Best代写-最专业靠谱代写IT | CS | 留学生作业 | 编程代写Java | Python |C/C++ | PHP | Matlab | Assignment Project Homework代写

C++代写 | 数据结构 | Data Structure

C++代写 | 数据结构 | Data Structure

C++代写指针的使用

Introduction

1 design

The design does not need to be correct but must show good faith effort to create a quality design for the current assignment. It MUST address

Understanding the Problem (2 pts)

Flowchart and/or Pseudocode (must contain function details and header info) (4 pts)

Test Cases (must contain good, bad, and edge cases) (4 pts)

By default, you will receive one point for each area addressed in the design (up to 3 points for just turning in something!). The remaining points for each area will be based on how thorough and complete each section is. For example, consider section (1). Simply restating the problem will only get you one point. You must describe and justify your understanding of what the problem is asking you in order to receive full both points.

 

2 work

This work is intended to be a brief exercise to establish a better understanding of pointers. This assignment is much shorter than a typical homework and should take less time.

Your program will prompt the user to enter a number between [10 .. 20] (inclusive). After verifying that the number is within the proper range, you will generate that many random numbers and place them into a dynamically allocated array. Your program will then display the contents of the array (with 4 numbers per line). Next, you will sort the values in descending order (from largest to smallest). Lastly, you will display the sorted numbers (again, with 4 per line).

There are additional requirements that are explained throughout this document.

Example Program Operation

The following box provides an example implementation of this program in action.

Sorting Random Integers Programmed by Author Name
This program generates random numbers in the range [10 .. 20],
displays the original list, and sorts the list in
in descending order. Lastly, the sorted list is displayed
to the user.
How many numbers should be generated? [10 .. 20]: 9
Invalid input
How many numbers should be generated? [10 .. 20]: twenty
Invalid input
How many numbers should be generated? [10 .. 20]: -7
Invalid input
How many numbers should be generated? [10 .. 20]: 15
The unsorted random numbers:
680 329 279 846
123 101 427 913
255 736 431 545
984 391 626
The sorted list:
984 913 846 736
680 626 545 431
427 391 329 279
255 123 101
Thanks for using my program!

Notes

You will develop a program to mimic the functionality shown in the Example Program Operation section. You must implement and utilize the required functions (with the exact prototypes shown). This program exists to expand your knowledge of pointers, arrays, and dynamic memory allocation. If you are struggling to understand a concept, be sure to ask for help.

Here is a list of steps that will be performed in the program. Note that most of these steps are performed by functions (that you will write).

  1. Introduce the program.
  2. Get a user requestin the range [min = 10 .. max = 20].
  3. Dynamically allocate an array (of ints) with the requested size.
  4. Generate requestrandom integers in the range [lo = 100 .. hi = 999], storing them in consecutive elements of an array.
  5. Display the list of integers before sorting, 4 numbers per line.
  6. Sort the list in descending order (i.e., largest first).
  7. Display the sorted list, 4 numbers per line.
  8. Delete the dynamically allocated array

Additional notes are as follows:

  • Make sure that you use valgrind to check your program for memory leaks!
  • Review your previous lab work for a reminder of the process to generate random numbers.
  • The Selection Sort is probably the easiest sorting algorithm to implement. Here is a version of the descending order algorithm, where requestis the number of array elements being sorted, and exchange is the function that exchanges two elements of an array:

for (k=0; k<request-1; k++) {
i = k;
for (j=k+1; j<request; j++) {
if (array[j] > array[i])
i = j;
}
exchange(&(array[k]), &(array[i]));
}

Required Functions

The list below provides the exact function prototypes that must be used to implement your program. You may not change the prototypes in any way. Each function below is accompanied by a description that provides an explanation of its purpose.

  • void introduction();
    Prints the program title, author’s name, and instructions that tell the user what to do.
  • void get_num (int *num_ptr);
    Accepts a pointer to the int that will be initialized with the user’s input. This is the function which prompts the user to enter a number between [10 .. 20], validates the number (reprompts if necessary) and then places the number into the location at num_ptr.
  • void fill_array(int array_size, int *array);
    This function generates array_sizerandom numbers (in the range [100 .. 999]) and fills the array.
  • void sort_list(int array_size, int *array);
    This function rearranges the numbers inside the array so that they are sorted in descending order (from largest to smallest).
  • void exchange(int *a, int *b);
    This function will swap the values that are located at memory addresses a and b.
  • void display_list(int array_size, int *array);
    This function simply displays all integers that are located inside the array. The output must be arranged so that there are 4 numbers per line (except for the last line).

Additional Requirements

  • The title, programmer’s name, and brief instructions must be displayed on the screen.
  • The program must validate the user’s request.
  • The mainfunction must consist (mostly) of procedure calls. It should be a readable “list” of what the program will do.
  • minmaxlo, and himust be declared and used as type: const int
  • The program must be modularized into at least the following functions. Note that each task is split up into its own function.
    • main
    • introduction
    • get_num {parameters: request(pointer)}
    • fill_array {parameters: request(value), array (pointer)}
    • sort_list {parameters: request(value), array (pointer)}
    • exchange {parameters: array[i] (pointer), array[j] (pointer), where iand j are the indexes of elements to be exchanged}
    • display_list {parameters: request(value), array (pointer)}
  • Memory leaks are not allowed
  • There must be just one procedure to display the list. This procedure must be called twice: once to display the unsorted list, and once to display the sorted list.
  • Your program must utilize the required functions that were listed above. You must write your code in a modular fashion.
  • This homework (and any other homework in CS161) is not allowed to use the gotostatement in your code.
  • Each function in your code must have a copy of the function header that is described below in the program style section of this document.
  • The usual requirements regarding documentation, readability, user-friendliness, etc., apply.

Design Document

For this assignment you must design a solution and implement the design in C++ code. As a reminder, the Software Design tab contains an explanation of the design process and expectations. Your design document is worth 10 points and the homework implementation is worth 100 points.

Your design document needs to address the following areas:

  • Understanding the Problem (2 pts)
  • Flowchart and/or pseudocode (must contain function details and header info) (4 pts)
  • Test Cases (must contain good, bad, and edge cases) (4 pts)

Although the design document is only worth 10 points, remember that the designs/critiques category comprises 10% of your final grade (see the syllabus). Do not simply ignore this work! You can view an example design document here: Polya_template.pdf (Links to an external site.)

Program Style/Comments

In your implementation, make sure that you include a program header in your program, in addition to proper indentation/spacing and other comments! Below is an example header to include. Make sure you review the style guidelines for this class (Links to an external site.), and begin trying to follow them, i.e. don’t align everything on the left or put everything on one line!

/******************************************************

** Program: dynamic_mem.cpp

** Author: Your Name

** Date:

** Description:

** Input:

** Output:

******************************************************/

Don’t forget that each of your functions needs to have its own personalized header that contains the following information:

/******************************************************
** Function:
** Description:
** Parameters:
** Pre-Conditions:
** Post-Conditions:
******************************************************/

Electronically submit your C++ source code (the .cpp file) prior to the assignment due date using TEACH (Links to an external site.).

 

bestdaixie

评论已关闭。