Question

1. Create a file that contains 3 rows of data of the form: First Name Middle...

1. Create a file that contains 3 rows of data of the form:
First Name Middle Name Last Name Month Day Year Month Day Year GPA.
This file represents student data consisting of first name, middle name, last name, registration month, registration day, registration year, birth month, birth day, birth year, current gpa. ...or you may download the data file inPut.txt.

inPut.txt reads:​​​​​​​
Tsia Brian Smith 9 1 2013 2 27 1994 4.0 Harper Willis Smith 9 2 2013 9 25 1990 3.7 Phelix N Smith 8 27 2013 7 28 1992 3.9

Create a program (including code comments) that:

2. Declares a date structure consisting of month, day, year.

3. Declares a structure containing student data: first name, middle name, last name, gpa, registration date using the date structure previously declared and birth date using the date structure previously declared.

4. Places the function prototypes and structures in a header file (*.h). Include the header file in the main program.

5. Declares an array variable of the student structure that can hold 3 students.

6. Opens the file. Write code to check the file state. If the file fails to open, display a message and exit the program.

7. Write a function that accepts the file pointer and structure array as parameters and reads each row into the structure.

8. Write a function that accepts the array structure as a parameter. Ensure the array cannot be modified in the function. Output the data in the structure using appropriate labels and messages. Ensure the data is readable.

9. Call both functions from main.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* Please read all the comments and see the output*/

/* You have all the required points*/

#include <stdio.h>
#include <string.h>

struct DateType{ //Date type having day,month and year
   int day;
   int month;
   int year;
}

struct Student{ //Student sturcture with all required parameter according to file data
   char firstName[100];
   char middleName[100];
   char lastName[100];
   float gpa;
   struct DateType birthday; //Birthday of type DateType
   struct DateType registration; // registration of type DateType
}

struct Student students[3]; //Array Creation for the student structure which is total 3 as asked

void readData(){
   FILE* filePointer; //File pointer to read data from file
   int bufferLength = 255;   
   char buffer[bufferLength]; //For reading each line
  
   filePointer = fopen("inPut.txt", "r");
   int studentCounter = 0;
   while(fgets(buffer, bufferLength, filePointer)) {
       char newString[10][10];
       j=0; ctr=0;
      
       /* Reading text and setting each value */
       for(i=0;i<=(strlen(buffer));i++)
       {
           if(str1[i]==' '||str1[i]=='\0')
           {
               newString[ctr][j]='\0';
               ctr++; //for next word
               j=0; //for next word, init index to 0
           }
           else
           {
               newString[ctr][j]=str1[i];
               j++;
           }
       }
       //printf("%s\n", buffer);
       students[studentCounter].firstName=newString[0];
       students[studentCounter].middleName=newString[1];
       students[studentCounter].lastName=newString[2];
       students[studentCounter].registration.month=newString[3];
       students[studentCounter].registration.date=newString[4];
       students[studentCounter].registration.year=newString[5];
       students[studentCounter].birthday.month=newString[6];
       students[studentCounter].birthday.day=newString[7];
       students[studentCounter].birthday.year=newString[8];
       students[studentCounter].gpa=newString[9];
       studentCounter ++;
       /* Reading text and setting each value, ends here*/
   }
  
   fclose(filePointer); //Close file when file reading is over
}

void showData(){ //Function to show all data stored in structure
   printf("Reading files data from structures");
int i=0;
printf("FirstName\tMiddleName\tLastName\tDate of registration\tDate of Birth\tGPA\n");
for(int i=0;i<3;i++)
{
printf("%s\t%s\t%s\t%d-%d-%d\t%d-%d-%d\t%f\n",students[i].firstName,students[i].middleName,students[i].lastName,students[i].registration.month,students[i].registration.day,students[i].registration.year,students[i].birthday.month,students[i].birthday.day,students[i].birthday.year,students[i].gpa);
}
}


int main() { //Driver function to execute program
   //Calling the file reading function and storing data into structures
   readData();
   //Calling the function to show all data from structure
   showData();
  
   return 0;
}

/* This is output*/

/* That's all. Thanks*/

Add a comment
Know the answer?
Add Answer to:
1. Create a file that contains 3 rows of data of the form: First Name Middle...
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
  • Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player,...

    Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...

  • In C program Consider a file that contains employee records, called "empstat.txt." The data for each...

    In C program Consider a file that contains employee records, called "empstat.txt." The data for each employee consist of the employee’s last name (up to 20 characters), employee id number (up to 11 characters), gross pay for the week (double), taxes deducted (double) for the week, and net pay (double) for the week. Create a struct to hold the employee information. Write a void function called writeEmpFile that prompts the user to enter last name, id number, gross pay and...

  • create a C++ program which reads in a Social Security number, a first name, a middle...

    create a C++ program which reads in a Social Security number, a first name, a middle name or initial, and a last name from the file inData.dat. The name is written to file outData.dat in three different formats: Format 1: First name, middle name, last name, and Social Security number Format 2: Last name, first name, middle name, and Social Security number Format 3: Last name, first name, middle initial, and Social Security number Format 4: Last name, middle initial, last name Note: The...

  • Write a java program to create a student file which includes first name, last name, and...

    Write a java program to create a student file which includes first name, last name, and GPA. Write another Java program to open the students file. Display the students list and calculate the average GPA of the class.  

  • C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class...

    C++ Your solution will consist of the following four files: HeartRates.h (class specification file) HeartRates.cpp (class implementation file) 200_assign4.cpp (application program) 200_assign4.pdf (sample runs) For your fourth programming assignment you will be writing the following C++ program: The formula for calculating your maximum heart rate in beats per minute is 220 minus your age in years. Your target heart rate is a range that is 50-85% of your maximum heart rate. Create a class called HeartRates. The class attributes should...

  • IN C PLEASE Question 16 A. Consider “inclass2.h” header file. Define a structure which can hold...

    IN C PLEASE Question 16 A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id, first name, last name, and gpa. Use appropriate header file guards. ( Max size of first and last name is 20, id is 7 and gpa is double). B. Consider an array of student struct with the MAX_SIZE 10 and a first name. These will be provided as an input to your function. Write a function/method that using the...

  • A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id,...

    A. Consider “inclass2.h” header file. Define a structure which can hold the following student information: id, first name, last name, and gpa. Use appropriate header file guards. ( Max size of first and last name is 20, id is 7 and gpa is double). B. Consider an array of student struct with the MAX_SIZE 10 and a first name. These will be provided as an input to your function. Write a function/method that using the given inputs prints out the...

  • PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a...

    PYTHON*************** Create a Person Class that: Accepts First Name, Last Name, Age, and Gender Has a method that adds all persons Validate all input, not left empty for First Name, Last Name, Gender and numeric for age and throw an exception if it does not validate within the class. Create a Student Class that: Inherits the Person Class Accepts GPA Validate GPA (>= 0 and <= 4.0) and throw exception if it does not validate within the class. Has methods...

  • Create a program that allows a student to complete a registration form and displays a completion...

    Create a program that allows a student to complete a registration form and displays a completion message that includes the user’s full name and a temporary password. Console Registration Form First name: Bjarne Last name: Stroustrup Birth year: 1950 Welcome Bjarne! Your registration is complete. Name: Bjarne Stroustrup Temporary password: Bjarne*1950 Specifications • The user’s full name consists of the user’s first name, a space, and the user’s last name. • The temporary password consists of the user’s first name,...

  • struct nameType { string first; string last; }; struct studentType { nameType name; double gpa; };...

    struct nameType { string first; string last; }; struct studentType { nameType name; double gpa; }; a. Write a program that declares an array of the studentType structure, size 10, name of your choice, and includes the following: • Write a void function to request user input into each of the members of the studentType structure array. Be sure to include proper user prompts. Assume the entire structure array is filled. Write the prototype and the function definition. • Call...

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