// This program will input and store meteorological data into an array. // Devel
ID: 3936052 • Letter: #
Question
// This program will input and store meteorological data into an array.
// Developer: Faculty CMIS102
// Date: Jan 31, XXXX
#define NUMMONTHS 12
#define NUMYEARS 5
#include <stdio.h>
// function prototypes
void inputdata();
void printdata();
// Global variables
// These are available to all functions
float Raindata[NUMYEARS][NUMMONTHS];
char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
char months[NUMMONTHS][12]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
int main ()
{
char enterData = 'y';
printf("Do you want to input Precipatation data? (y for yes) ");
scanf("%c",&enterData);
if (enterData == 'y') {
// Call Function to Input data
inputdata();
// Call Function to display data
printdata();
}
else {
printf("No data was input at this time ");
}
printf("Please try the Precipitation program again. ");
return 0;
}
// function to inputdata
void inputdata() {
int year,month;
/* variable definition: */
float Rain=1.0;
// Input Data
for (year=0;year < NUMYEARS; year++) {
for (month=0; month< NUMMONTHS; month++) {
printf("Enter rain for %d, %d: ", year+1, month+1);
scanf("%f",&Rain);
Raindata[year][month]=Rain;
}
}
}
// Function to printdata
void printdata(){
int year,month;
// Print data
printf ("year month rain ");
for (year=0;year < NUMYEARS; year++) {
for (month=0; month< NUMMONTHS; month++) {
printf("%s %s %5.2f ",
years[year],months[month],Raindata[year][month]);
}
}
}
__________________________
2. Prepare a new test table with at least 2 distinct test cases listing input and expected output for
the code you created after step 1
Explanation / Answer
Input 1:-
y
1.21114248653
8.43741701449
6.85850732548
0.995683988799
7.27943658689
1.8762185443
8.65610331859
1.23938786088
0.81204146854
1.48039485984
8.3469976884
4.70200522552
0.667864756019
3.86885696623
2.55388215353
6.44241773773
5.78551931062
4.18894174032
4.41352221542
8.68864799752
6.21974254372
4.85519475006
7.63365205048
1.79196897913
1.08563703142
8.79717486806
7.83563392463
8.5435024771
6.51764551934
7.46833690455
7.27170011196
0.737531095252
7.68995161235
4.94921282042
8.53557132211
7.75812995565
3.76629578352
8.80628532164
6.49684901294
2.76625072415
7.55318493517
3.87128907978
4.79026991095
0.523453788305
2.47784282903
3.87244209468
2.89177210891
4.14674480692
3.16663543401
0.799182405966
5.92822137176
4.87574065531
1.9555514083
0.460284873582
0.462245947568
5.28686016941
4.61405411616
2.85741173902
2.17484995916
2.13847117283
Output1
year month rain
2011 Jan 1.21
2011 Feb 8.44
2011 Mar 6.86
2011 Apr 1.00
2011 May 7.28
2011 Jun 1.88
2011 Jul 8.66
2011 Aug 1.24
2011 Sep 0.81
2011 Oct 1.48
2011 Nov 8.35
2011 Dec 4.70
2012 Jan 0.67
2012 Feb 3.87
2012 Mar 2.55
2012 Apr 6.44
2012 May 5.79
2012 Jun 4.19
2012 Jul 4.41
2012 Aug 8.69
2012 Sep 6.22
2012 Oct 4.86
2012 Nov 7.63
2012 Dec 1.79
2013 Jan 1.09
2013 Feb 8.80
2013 Mar 7.84
2013 Apr 8.54
2013 May 6.52
2013 Jun 7.47
2013 Jul 7.27
2013 Aug 0.74
2013 Sep 7.69
2013 Oct 4.95
2013 Nov 8.54
2013 Dec 7.76
2014 Jan 3.77
2014 Feb 8.81
2014 Mar 6.50
2014 Apr 2.77
2014 May 7.55
2014 Jun 3.87
2014 Jul 4.79
2014 Aug 0.52
2014 Sep 2.48
2014 Oct 3.87
2014 Nov 2.89
2014 Dec 4.15
2015 Jan 3.17
2015 Feb 0.80
2015 Mar 5.93
2015 Apr 4.88
2015 May 1.96
2015 Jun 0.46
2015 Jul 0.46
2015 Aug 5.29
2015 Sep 4.61
2015 Oct 2.86
2015 Nov 2.17
2015 Dec 2.14
----------------------------------------------------------------------------------------
input 2
y
6.18202529644
7.3558099976
3.19431769042
5.95552563308
6.94373960292
8.60204503592
6.34967703975
1.63376924928
0.924909677457
7.70968268916
7.42650319725
6.13551175446
6.33105704823
0.0745083234423
5.26860292104
5.22599401196
1.78268000664
5.12113693377
2.7402973737
8.14268530088
2.2257636221
8.58363772378
6.16299602363
3.66698073811
8.92425249479
6.35893998842
5.82501058721
7.84838536907
3.51856596346
8.38150226351
5.84839219996
7.66660840654
3.80581984809
6.43280388894
8.08555551035
2.98773078612
5.27222390853
7.92616719121
5.89802152878
8.38448587676
1.31828785678
2.85488776822
8.86504928365
1.64015207637
5.65860708919
2.41294963324
3.55193099196
3.13009334709
8.90838106924
7.17661517112
8.32252063506
6.30764717213
7.89445150626
6.15413654062
2.9404075631
3.27512350236
5.46136614407
4.08136872993
7.20180812325
1.47472079314
output 2
year month rain
2011 Jan 6.18
2011 Feb 7.36
2011 Mar 3.19
2011 Apr 5.96
2011 May 6.94
2011 Jun 8.60
2011 Jul 6.35
2011 Aug 1.63
2011 Sep 0.92
2011 Oct 7.71
2011 Nov 7.43
2011 Dec 6.14
2012 Jan 6.33
2012 Feb 0.07
2012 Mar 5.27
2012 Apr 5.23
2012 May 1.78
2012 Jun 5.12
2012 Jul 2.74
2012 Aug 8.14
2012 Sep 2.23
2012 Oct 8.58
2012 Nov 6.16
2012 Dec 3.67
2013 Jan 8.92
2013 Feb 6.36
2013 Mar 5.83
2013 Apr 7.85
2013 May 3.52
2013 Jun 8.38
2013 Jul 5.85
2013 Aug 7.67
2013 Sep 3.81
2013 Oct 6.43
2013 Nov 8.09
2013 Dec 2.99
2014 Jan 5.27
2014 Feb 7.93
2014 Mar 5.90
2014 Apr 8.38
2014 May 1.32
2014 Jun 2.85
2014 Jul 8.87
2014 Aug 1.64
2014 Sep 5.66
2014 Oct 2.41
2014 Nov 3.55
2014 Dec 3.13
2015 Jan 8.91
2015 Feb 7.18
2015 Mar 8.32
2015 Apr 6.31
2015 May 7.89
2015 Jun 6.15
2015 Jul 2.94
2015 Aug 3.28
2015 Sep 5.46
2015 Oct 4.08
2015 Nov 7.20
2015 Dec 1.47
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.