I am getting lost in this project: -The project will read in from a file to fill
ID: 3540994 • Letter: I
Question
I am getting lost in this project:
-The project will read in from a file to fill and array of struct of student.
-The output will be a completed database to a file with a user defined number of addiltional student records.
Specification/ Problem Statement:
Using the struct data type create a student database to capture the student's first name and last name, address, city, state, zipcode, gender, major, and GPA of 25 records read in from a file and prompt the user for the number of additional records to add to the database. Please add 5 records at a minimum will be added for a minimum total of 30 records. The input file named "masterstudent.txt" contains the 25 records in comma delimiter format as shown below.
Andrews,David,1,Psycology,3.45
Gonzalez,Eduardo,1,Biology,3.15
.
.
.
Carson,Lisa,0,Biology,3.43
Adams,Kristen,0,Electrical Engineering,3.82
The output console should displau the student database sorted in ascending order by Major sub-sorted on first and last name as shown below.
First Name Last Name Gender
Lisa Carson F Major Biology
GPA 3.43
Eduardo Gonzalez M Major Biology
GPA 3.15
Kristen Adams F Major Electrical Engineering
GPA 3.82
David Andrews M Major Psycology
GPA 3.45
The output file named "studentmasterupdate.txt" should display the student database as shown above in the input file format.
I just need help with the code, mine looks a mess.
Explanation / Answer
The struct database declares that database has three variables in it, age, id_number, and salary. You can use database like a variable type like int. You can create an employee with the database type as I did above. Then, to modify it you call everything with the 'employee.' in front of it. You can also return structures from functions by defining their return type as a structure type. For instance:
I will talk only a little bit about unions as well. Unions are like structures except that all the variables share the same memory. When a union is declared the compiler allocates enough memory for the largest data-type in the union. It's like a giant storage chest where you can store one large item, or a small item, but never the both at the same time.
The '.' operator is used to access different variables inside a union also.
As a final note, if you wish to have a pointer to a structure, to actually access the information stored inside the structure that is pointed to, you use the -> operator in place of the . operator. All points about pointers still apply.
A quick example:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.