C Programming, getting data from a file and computing them into 5 parallel arrays so that they can be used for later calculation.
Also please avoid using structures at all costs for this code as they have not yet been covered.
c code:
#include <stdio.h>
#include <stdlib.h>
//structure pedestrian
struct Pedestrian
{
//variables
int yyyy;
int mm;
int dd;
int day;
int dayCount;
};
int main()
{
struct Pedestrian p[4000]; //array of struct objects
int n=0;
FILE *fptr;
char line[256];
fptr=fopen("pedestrian.tsv","r");//file
if(!fptr)
{
printf("File not found\n");
return 1;
}
//ignore first two lines
fgets(line, sizeof(line), fptr);
fgets(line, sizeof(line), fptr);
//read and store in structure
while(!feof(fptr))
{
fscanf(fptr,"%d%d%d%d%d",&p[n].yyyy, &p[n].mm,&p[n].dd,
&p[n].day, &p[n].dayCount);
n++; //line count
}
//print the results
printf("\nS1: Total data lines = %d", n);
printf("\nS1: First data line = %d/%d/%d,
%d",p[0].dd,p[0].mm,p[0].yyyy,p[0].dayCount);
printf("\nS1: last data line = %d/%d/%d,
%d",p[n-1].dd,p[n-1].mm,p[n-1].yyyy,p[n-1].dayCount);
return 0;
}
output:
//i have given the output for file with only 3 lines.. you can give n numbers in your file.. it works fine..
for any clarification, do comments, please give me thumbs up..
C Programming, getting data from a file and computing them into 5 parallel arrays so that...
Write a C++ program that will input data from a Comma-separated values (.csv) file and output some information about it. This program uses a csv file from Yahoo Finance (.csv) filename : SBUX.csv 1. Output the name of the ticker to the console screen (without the “.csv”) 2. Output the start date and end date that was found in the file 3. Output how many trading day(s) existed in the file 4. Prompt the use to input a number of...
Mountain Paths (Part 1) in C++ Objectives 2d arrays Store Use Nested Loops Parallel data structures (i.e. parallel arrays … called multiple arrays in the zyBook) Transform data Read from files Write to files structs Code Requirements Start with this code: mtnpathstart.zip Do not modify the function signatures provided. Do not #include or #include Program Flow Read the data into a 2D array Find min and max elevation to correspond to darkest and brightest color, respectively Compute the shade of...
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...
1. Write a C++ program that reads daily weather observation data from a file and writes monthly and annual summaries of the daily data to a file. a. The daily weather data will be contained in a file named wx_data.txt, with each line of the file representing the weather data for a single day. b. For each day, the date, precipitation amount, maximum temperature, and minimum temperature will be provided as tab-separated data with the following format: 20180101 0.02 37...
can someone please comment through this code to explain me specifically how the variables and arrays are working? I am just learning arrays code is below assignment C++ Programming from Problem Analysis to Program Design by D. S. Malik, 8th ed. Programming Exercise 12 on page 607 Lab9_data.txt Jason, Samantha, Ravi, Sheila, and Ankit are preparing for an upcoming marathon. Each day of the week, they run a certain number of miles and write them into a notebook. At the...
Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts an annual summer meeting. Each state sends one official delegate to the section officers’ meeting at this summer session. The national organization reimburses the official state delegates according to the scale below. Write a Java program to calculate the reimbursement values, satisfying the specifications below. Details on array and method usage follow these specs. 1. The main method should declare all the variables at...
Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...
Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...
Introduction to C Programming – COP 3223 1. To learn how to use arrays to store and retrieve data to help solving problems. 2. Reinforce use of input files. Introduction: Ninja Academy Ninjas are awesome! Your friend has not stopped talking about how cool ninjas and how they would like to become a ninja. To amuse your friend, you have decided to create a series of programs about ninjas. Problem: Mentorship (ninjamentors.c) It is time for your friend to select...
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...