Question
In this stage you should read all of the data into internal structures suitable for use in the later stages and create an output representation that provides an overview of the data that was read.

Photo 1&2 - Question
Photo 3 - Input data
Photo 4 - Introduction

please write a code that will execute such function & generate a required output (as stated on the question). Input data is not required to write a code but if you need to know the headerline, please refer to photo 3.

Stage 1- Reading the Data (Marks up to 9/20) In this stage you should read all of the data into intermal structures suitable
<plus lines for the other seven years> s1, 2009: Jan Feb* Mar Apr May Jun Jul Aug Sep Oct Nov Dec where rainfall-086039-2000-
rainfall-014015-1941-2019 IDGJACO001 14015 1941 508.4 Y IDCJACO0D1 14015 1941 2 371.9 Y 14015 1941 IDCJAC0001 3 304.3 Y 27.1
#include <stdio.h> 91#include <stdlib.h> 1 l#include <assert.h> 111#include <math.h> 12 14 151#define HEADER,LINES 1 161#defi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include<stdio.h>
int main()
{
char line[512];
char *months[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
int id[11],yr,mo[11],i=0,j;
char c[11];
char str[] = "IDCJAC0001";
double r[11];
FILE *info; // create info pointer
info = fopen("val.csv","r"); // open text file called info, read
fscanf(info,"%d, %d, %d,%lf,%c" ,&id[i], &yr, &mo[i], &r[i], &c[i]);
//printf("\n%s\t,%d\t, %d\t, %d\t, %lf\t, %c\t",str,id[i],yr,mo[i],r[i],c[i]);
i++;
while(fgets(line, 512, info) != NULL)
{
fscanf(info,"%d, %d, %d,%lf,%c" ,&id[i], &yr, &mo[i], &r[i], &c[i]);
//printf("\n%s\t,%d\t, %d\t, %d\t, %lf\t, %c\t",str,id[i],yr,mo[i],r[i],c[i]);
i++;
}
printf("\n");
fclose(info);
printf("\nmac: ass2-soln < rainfall-086039-2000-2009.csv\nS1, sitenumber 086039, 115 datalines in input\n");
printf("S1, 2000: ");
for(j=0;j<i;j++)
{
if(mo[j]-mo[j-1]!=1)
{
int x = mo[j]-mo[j-1],k;
for(k=1;k<x;k++)
printf("\t...");
if(c[j]=='Y')
printf("\t%s",months[mo[j]]);
else
printf("\t%s*",months[mo[j]]);
}
else
{
if(c[j]=='Y')
printf("\t%s",months[mo[j]]);
else
printf("\t%s*",months[mo[j]]);
}
}
printf("\n");
return 0;
}

I took a sample input of what you provided:

086039,2000,01,28.2,Y
086039,2000,02,34.5,Y
086039,2000,03,22.5,Y
086039,2000,06,42.4,Y
086039,2000,07,45.1,Y
086039,2000,08,45.1,Y
086039,2000,09,45.1,Y
086039,2000,10,45.1,Y
086039,2000,11,45.1,N
086039,2000,12,45.1,Y

Output for it is:

gcc stages.c ./a.out mac: ass2-soln< rainfal1-086039-2000-2009.csv S1, sitenumber 086039, 115 datalines in input Dec S1, 2000

For another input:

086039,2000,01,28.2,Y
086039,2000,02,34.5,Y
086039,2000,03,22.5,Y
086039,2000,05,96.3,Y
086039,2000,06,42.4,Y
086039,2000,07,45.1,Y
086039,2000,08,45.1,Y
086039,2000,09,45.1,Y
086039,2000,10,45.1,Y
086039,2000,11,45.1,N
086039,2000,12,45.1,Y

gcc stages.c $./a.out mac: ass2-soln< rainfal1-086039-2000-2009.csv S1, sitenumber 086039, 115 datalines in input S1, 2000: J

Add a comment
Know the answer?
Add Answer to:
In this stage you should read all of the data into internal structures suitable for use in the later stages and create...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Code with Java using arrays and Scanner only ( input should end with 0 to terminate...

    Code with Java using arrays and Scanner only ( input should end with 0 to terminate the program) Everyone loves to be celebrated on their birthdays. Birthday celebration can encourage positive social interaction among co-workers, foster friendship among classmates or even strengthen bond between families. Birthday graph can be display in many forms. It can a creative drawing consists of cupcakes, balloons, candles with names, or it can be in the form of simple bar chart to indicate the birthday...

  • C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the r...

    C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything.     Your function should be named...

  • (Python) Write a program called sales.py that uses a list to hold the sums of the...

    (Python) Write a program called sales.py that uses a list to hold the sums of the sales for each month. The list will have 12 items with index 0 corresponds with month of “Jan”, index 1 with month “Feb”, etc. o Write a function called Convert() which is passed a string which is a month name (ex. “Jan”) and returns the matching index (ex. 0). Hint – use a list of strings to hold the months in the correct order,...

  • Capitalization JAVA In this program, you will read a file line-by-line. For each line of data...

    Capitalization JAVA In this program, you will read a file line-by-line. For each line of data (a string), you will process the words (or tokens) of that line one at a time. Your program will capitalize each word and print them to the screen separated by a single space. You will then print a single linefeed (i.e., newline character) after processing each line – thus your program will maintain the same line breaks as the input file. Your program should...

  • Using C++, create a doubly linked list data structure that stores strings. At a minimum, you...

    Using C++, create a doubly linked list data structure that stores strings. At a minimum, you must have a List class that contains the list functionality (including an insert function) and a linkable object ("link node") class. For convenience, you may include the data directly or the data may be external to the link node, connected with a reference. You may use an inner class for the LinkNode and/or include the LinkNode class with the List class file if you...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • Assignment You will be developing a speeding ticket fee calculator. This program will ask for a t...

    Assignment You will be developing a speeding ticket fee calculator. This program will ask for a ticket file, which is produced by a central police database, and your program will output to a file or to the console depending on the command line arguments. Furthermore, your program will restrict the output to the starting and ending dates given by the user. The ticket fee is calculated using four multipliers, depending on the type of road the ticket was issued: Interstate...

  • 1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please...

    1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT