### CIS DP Week 7 Assignment Complete Solution

Donate & Make a Difference
Question Details: #8905
CIS DP Week 7 Assignment Complete Solution

The Assignment:

In pseudocode and in C code, declare a 1-dimensional array of Integers called InternetHits that will hold up to 10 Integer values representing the number of hits a Web site receives.

Use a For loop to iterate through the array and input the values.

Demonstrate your code compiles and runs for a test case of your choice. Use the lab information below.

Lab:

Overview:
This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, design (using pseudocode visualization), and implementation with C code. The example provided uses sequential,repetition, selection statements and arrays.

Program Description:

This program will input and store meteorological data into an array. The program will prompt the user to enter the average monthly rainfall for a specific region and then use a loop to cycle through the array and print out each value. The program should store up 5 years of meteorological data.

Analysis:

I will use sequential, selection, and repetition programming statements and an array to store data.
I will define an array of Float number: Raindata[] to store the Float values input by the user. To store up to 5 years of monthly data, the array size should be at least 5*12 = 60 elements.
A float number (rain) will also be needed to input the individual rain data.
An integer variable (Count) is needed to keep count of how many rain data elements were entered. This will keep track to make sure we don’t go over 60 and we print only valid rain elements.
A for loop can be used to iterate through the array to enter Raindata. A for loop can also be used to print the data in the array.

Test Plan:

To verify this program is working properly the input values could be used for testing:

Test Case

Input

Expected Output

1

Raindata[0]=2.2
Raindata[0]=2.1
Raindata[0]=0.6
Raindata[0]=2.9
Raindata[0]=4.6
Raindata[0]=3.1
Raindata[0]=0.1
Raindata[0]=0.3
Raindata[0]=0.5
Raindata[0]=5.4

2.2

2.1

0.6

2.9

4.6

3.1

0.1

0.3

0.5

5.4

2

Raindata[0]=6.2
Raindata[0]=5.1
Raindata[0]=4.6

6.2
5.1

4.6

3

Raindata[0]=2.6
Raindata[0]=4.2

2.6

4.2

Pseudocode:

// This program will input and store meteorological data into an array.

// Declare variables
Declare Raindata[60] as Float
Declare Rain as Float
Declare Count, i as Integer

// Set Initial Values
Set Rain=1.0
Set Count = 0

// Input Data
While Rain > 0
print "Enter rain "
Input Rain

If Rain > 0
Set Raindata[Count]=Rain
count= count + 1
End If

End While

// Print data
For i=0; I < count; i++
print Raindata[i]
End For

C Code

The following is the C Code that will compile in execute in the online compilers.

// C code

// This program will input and store meteorological data into an array.

// Developer: Faculty CMIS102

// Date: Jan 31, 2014

#include <stdio.h>

int main ()

{

/* variable definition: */

float Raindata[60];

float Rain=1.0;

int count=0,i;

// Input Data

while (Rain > 0)

{

printf("Enter rain\n");

scanf("%f",&Rain);

// Only assign if positive

if (Rain > 0) {

Raindata[count]=Rain;

count= count + 1;

}

}

// Print data

for (i=0; i<count;i++)

printf ("Data element %d is %f\n", i,Raindata[i]);

return 0;

}

Setting up the code and the input parameters in ideone.com:

Note the Input values for this run were:
3.2
2.1
6.5
9.4
0.3
0.2
-1
You can change these values to any valid integer values to match your test cases.

Results from running the programming at ideone.com:

Learning Exercises for you to try:

How would you modify the program to sum all of the rainfall values?

What happens if you attempt to add more than 60 elements to the Raindata array?

(Hint: You can try this by changing the code to Raindata[5] and then try to enter 6 elements.)

Try to modify the code to add another Array to store Windspeed or another meteorological element.

C Code:

// C code

// This program will input and store meteorological data into an array.

// Developer: Faculty CMIS102

// Date: Jan 31, 2014

#include <stdio.h>

int main ()

{

/* variable definition: */

float Raindata[60];

float Rain=1.0;

int count=0,i;

// Input Data

while (Rain > 0)

{

printf("Enter rain\n");

scanf("%f",&Rain);

// Only assign if positive

if (Rain > 0) {

Raindata[count]=Rain;

count= count + 1;

}

}

// Print data

for (i=0; i<count;i++)

printf ("Data element %d is %f\n", i,Raindata[i]);

return 0;

}

• Posted by: Vikas
• Subjects: Computer Science Painting
• Attachments:

Solution Details: #8933
CIS DP Week 7 Assignment Complete Solution

Overview: This hands-on lab allows you to follow and experiment with the critical steps of developing a program including the program description, analysis, test plan, design (usin...
Buy now with PayPal's online protection..
• Purchased: 11 x
• Average Rating: A+
• Posted By: Vikas

Ratings

A+ - Thank you!

Vikas

Thanks for the positive feedback!

Related Solutions
Busypapers