Translate to Traditional Chinese (中文):


<< Prev   🏠 A B C D    Next >>

D. CODING QUESTION

Check your submission here: SCOREBOARD


INTRODUCTION


Statistical functions focus on calculating statistics from the data, such as min, max, sum, and average.

Your task in this PRE-FINAL is implementing 5 Statistical functions for the List: min, sum, average, count_divisible_5, sum_divisible_5.

You are provided 2 files List.cpp, Test_List.cpp. Please use these 2 files for coding.
The List.cpp file has already implemented all the requirements from HW3, including all the basic functions of a List. Please refer to HW3 for more details.

Download : Pre-Final package



List.cpp (30 pts)

Your task in this PRE-FINAL is implementing 5 Statistical functions for the List:
  1. int min (): Find and return the minimum value from the list. If the list is empty, return error code (-1).
  2. int sum(): Calculate and return the sum of all values from the list.
  3. float average(): Calculate and return the average value from the list. If the list is empty, return 0.
  4. int count_divisible_5(): counts how many numbers in the list are divisible by 5.
  5. int sum_divisible_5(): calulate and return the sum of all numbers in the list are divisible by 5.


Test_List.cpp (10 pts)

After implementing the List.cpp, implement the Test_List.cpp for testing. The testing scenario is described as follows:
  1. Append the following elements to the list: 3, 1, 5, 10, 8, 100.
  2. Print all the elements of the list.
  3. Get and print the minimum number in the list.
  4. Get and print the sum of all the numbers in the list.
  5. Get and print the average of the numbers in the list.
  6. Get and print the count of numbers divisible by 5 in the list.
  7. Get and print the sum of numbers divisible by 5 in the list.


<< Prev   🏠 A B C D    Next >>