码迷,mamicode.com
首页 > 其他好文 > 详细

SIT102 Introduction to Programming Working with Arrays

时间:2019-02-03 19:36:54      阅读:99      评论:0      收藏:0      [点我收藏+]

标签:first   rod   view   index   专业   div   round   nbsp   use   


SIT102 Introduction to Programming
Pass Task 6.1: Working with Arrays
Overview
In this task you will create a simple program which will create an array with a user specified size. This
array will then be populated with values, printed out to the console, and then, we‘ll use the values to
calculate some basic statistics.
Submission Details
Use the instructions on the following pages to create a small program to explore the use of arrays.
Submit the following files to OnTrack.
Lets get started.
1. Watch the Working with Arrays video as a background for this task, you will need to implement the
same logic but will read in double values rather than integers.
2. Create your own Working With Arrays project, and copy in the code of your user input functions, or
your custom terminal user input code file and header.
3. Add the following functions and procedures based on the Working with Arrays video:
Create a print_values procedure to print out a list of double values.
void print_values(double values[], int size)
Create a read_values procedure to read in a list of double values.
void read_values(double values[], int size)
Create a sum function to calculate the sum of an array of double values.
double sum(double values[], int size)
4. Use the following as main for your program - you will add to it in the next steps:
int main()
{
int count;
count = read_integer("How many values: ");
double temp[count];
read_values(temp, count);
print_values(temp, count);
write_line("Sum is:");
write_line( sum(temp, count) );
return 0;
}
Instructions
5. Extend the program with the following additions:
Add a function that calculates and returns the count of the number of negative values (those <
0) in the array.
int count_negative(const double data[], int size)
For this you will need a local result variable that starts at 0, and you add one to the result for
each element of the array that is < 0 . Print out the count of the number of negative
values at the end of the program.
Add a function that calculates and returns the largest value in the array.
double maximum(const double data[], int size)
For this you will need a local result variable that starts with the value of the first element of the
array. You can then loop over the remaining array elements (from index 1 to the last).
Finally, add a function that calculates and returns the average (mean) value in the array.
double average(const double data[], int size)
For this you will need a local result variable that starts at 0. You must then call your sum
function, passing in the required data, and returning the sum into the result variable. Lastly,
divide the result by the size of your array and return the newly calculated average.
Add some code to your main function that demonstrates the above three functions before
submitting to OnTrack.

因为专业,所以值得信赖。如有需要,请加QQ99515681 或邮箱:99515681@qq.com 

微信:codinghelp

SIT102 Introduction to Programming Working with Arrays

标签:first   rod   view   index   专业   div   round   nbsp   use   

原文地址:https://www.cnblogs.com/phphelper/p/10350839.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!