Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I Need help with a C program These are the starter files... solarfunctions.c /*=======================================================*/ /*=======================================================*/ #include #include solarsystem.h /*=======================================================*/ /* Function read_solar_system opens the input

I Need help with a C program

image text in transcribed

These are the starter files...

solarfunctions.c

/*=======================================================*/ /*=======================================================*/ #include #include "solarsystem.h" /*=======================================================*/ /* Function read_solar_system opens the input file for read-only */ /* Array planet[] is an array of structures - each element of the array */ /* holds one record per planet read from the input file */ /* */ /* Input arguments: filename - input file name (char string) */ /* planet - array of structures to hold planet data */ /* Output arguments: none */ /* Function return value: integer (array size) */ int read_solar_system_data(char filename[], planet_t planet[]) { int size = 0; /* Declare a file pointer variable, open the file using the filename*/ /* that's passed as a string in read-mode. */ /* If the file open is successful read data from the file using */ /* a while loop until status is EOF from fscanf */ return(size); } /* Function print_solar_system_data prints all the planet records */ /* into an output file */ /* */ /* Input arguments: filename - output file name (char string) */ /* planet - array of structures to hold planet data */ /* size - integer for array size */ /* Output arguments: none */ /* Function return value: none */ void print_solar_system_data(char filename[], planet_t p[], int size) { /* Declare a file pointer variable, open the file using the filename*/ /* that's passed as a string in write-mode. */ /* Write one record per line into the output file using fprintf() */ return; }

solarsystem.c

/*=======================================================*/ /*=======================================================*/ #include #include #include "solarsystem.h" /*=======================================================*/

int main(void) { planet_t solar[PLANET_MAX]; char inpfilename[24]; int size = 0;

printf("Enter input file name:"); scanf("%s", inpfilename);

/* Read solar system data from data file */ size = read_solar_system_data(inpfilename, solar);

/* print solar system data onto an output file, one per line */ print_solar_system_data("solar_output", solar, size);

/* Now let's perform some queries on the solar system data */ /* Which is the planet that has the largest number of moons */ /* Write a loop to go through the array to get the record */ /* and print the name of the planet */

/* Search the array to see if there's a planet called 'Saturn' */ /* and print all of its data */ /* You can use FOR or WHILE but your loop should print the */ /* details and stop processing the rest of the data */

return(0); }

solarsystem.h

/*------------------------------------------*--------------------------------- -----------------------------------------------------------------------------*/ #define PLANET_MAX 25 #define PLANET_NAME_MAX 30

typedef struct { /* Fill in structure with proper fields */ } planet_t;

int read_solar_system_data(char filename[], planet_t s[]);

void print_solar_system_data(char filename[], planet_t s[], int size);

This is the what the data file solar_data contains: (Name, Diameter, # of Moons, Rotation time, and Revolution time)

Mercury 4879 0 58.785 87.969 Venus 12104 0 243.686 224.701 Earth 12742 1 0.9975 365.256 Mars 6779 2 1.0259 686.98 Jupiter 139822 67 0.4135 4329.63 Saturn 116464 62 0.444 10751.8 Uranus 50274 27 0.71833 30664.01 Neptune 49244 14 0.67125 60148.35 Pluto 2390 5 0.405 90403.2
Pu The pupose of this assignment is to give you practice with Structures, File LO, character strings. Problem se Our solar system consists of at least 9 planets. We want to read some basic information about these planets from a data file and store them in structures within an stored in a structure are the Name, the Diameter, the Number of Moons, the Rotation time, and the Revolution time The basic fields of interest that are Write a program that reads several records from a data file pertaining to astronomical data and stores them in an array of structures. After printing out the records in the array to an output file, you need to perform two queries on the data stored. You CANNOT use input redirection for this program -you must read the contents of the input file programmatically Solving it step by step 1. There are 3 files that need to be copied from Spublic/9L to your local directory -solarsystem.c, solarsystemh and solarfunctions.c. The main function is in solarsystem.c It calls two functions read solar_system data and print solar system_data (which need to be completed) that are coded in solarfunctions.. If you compile and run the initial copy of the files you are likely to see compiler errors about the structure not having any members so you will need to fill in the structure with its fields as discussed in class (or look above for details under Problem description) 2. [10 points] The structure holding the planet data is defined in solarsystemh (needs to be filled in with fields), which also has prototype definitions for the two functions that are used in solarfunctions.h-this file is included in both the .c source files. The main function shows the calls to the functions that need to be written. The input file name containing the data is obtained from the user. After the code for read solar svstem data and print solar_system data is written, there are two queries that need to be performed on the data in the main function. The data is saved in a file called Spublic/9L/solar data - copy this over to your local directory for this assignment (and supply this name when prompted). [20 points] The read solar system data function must read the input data using File LO techniques discussed in class. You must open the file for read-only, use fscanf to read data, and close the file before returning from the function. Each planet record is stored in one element of the array using a structure. [20 points] The print solar system data prints all the records of the array of structures onto an output file one record per line The two queries that need to be completed in the main function are 3. 4. 5. 6. 7. [25 points] Finding the planet that has the largest number of moons and displaying the a. lanet's name as well as the number of moons. b. [25 points] Searching the array for a planet called "Saturn" and printing all the fields that are in the record (if) found. 8. Submit all three files as 9L

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Principles Of Database Systems With Internet And Java Applications

Authors: Greg Riccardi

1st Edition

020161247X, 978-0201612479

More Books

Students also viewed these Databases questions