PLZ HELP ASAP. STUDENT DATA

student data

Tom Railsback 102390 Engineering Junior
Dick Chase 031294 Biology Senior
Anne White 052493 Computer Sophomore
Terry Hall 062194 Phyics Freshman
Rick James 110298 Computer Junior
Jim Tolly 090267 Biology Sophomore
Jeff Leeks 042469 Computer Senior
Mike Small 121488 Computer Senior
Lauri Left 021486 Nursing Junior
Cindy Tims 052884 Computer Freshman

 create the arrays listed below
 read in student data from "student.txt", which is provided
 the data include student name, student id, student major and student grade level
 create a loop in which the user is prompted for the following options:
a. print out all the student’s data
b.print out all Seniors student information.
c. print out all Computer major student information.
d.Exit program
 use a switch statement to perform the options tasks

I am doing something wrong. When i debug the program, it only stops at
" error student.txt "


Problem 2 -- write an application that reads in from stdin “n” persons’ name, type of car
they drive and car’s mpg. Then print the car with the greatest mpg (15 points}.

 the main function, main2.c, will read in car owner name the type of car they own and
their car’s mgp
 prompt the user to enter at least five names, car types and mpg
 store the names and car types in two dimensional arrays and the mpg in a one
dimensional array – see below
 create a function, getMaxMPG() that will determine the car with the highest mpg
 getMaxMPG() will return the index of the element in the mpg array of this maximum
value
 print out in main() the owners name, the type of car and the car’s mpg for the car with the
maximum mpg.
create only one file, main2.c, which you will turn in

Hint:
char owners[MAXPERSON][MAXCHR];
char carType[MAXPERSON][MAXCHR];
int mpg[MAXPERSON];
int getMaxMPG(int mpg[], int maxcars)
I need this done by 12 pm today!!

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

#define MAXCHR 40
#define MAXSTUDENT 15

typedef struct
{
char fName[MAXCHR];
char lName[MAXCHR];
int studentID[MAXSTUDENT];
char major[MAXSTUDENT][MAXCHR];
char classLevel[MAXCHR];
}Student;

// function prototype
void printStudents(Student[], int istudent);
void userInstructions(void);
void lowerCase(char a[], int numChar);

int main(void)
{
// declaration
FILE *fpIN;
Student students[MAXSTUDENT];
char studentName[MAXSTUDENT][MAXCHR];
char printSenior[MAXCHR] = { "senior" };
char printMajor[MAXCHR] = { "computer" };
int i = 0;
int maxstudent = 0;
int choice = 0;
int senior = 0;
int major = 0;


// open file
if ((fpIN = fopen("student.txt", "r")) == NULL)
{
printf("error student.txt");
exit(-1);
}
// read file
for (int i = 0; i < MAXSTUDENT; i++)
{
if (fscanf(fpIN, "%s %s %d %s %s", students[i].fName, students[i].lName, &students[i].studentID, students[i].major, students[i].classLevel) != 5)
{
//end reading students
maxstudent = i;
break;
}
}
//userInstructions();

while (choice != 4)
{
switch (choice)
{
case 1:
printStudents(students, MAXSTUDENT);
break;
case 2:
for (int i = 0; i < maxstudent; i++)
{
lowerCase(students[i].classLevel, MAXSTUDENT);

if (strcmp(printMajor, students[i].classLevel) == 0)
{
if (senior == 0)
{
printf("\n\t\tAll seniors\n");
printf("\nFirst Name\tLast Name\tStudent ID\tMajor\tClass Level\n");
senior++;
}
printf("\n%s\t\t%s\t%d\t\t%s\t%s\n", students[i].fName, students[i].lName, students[i].studentID, students[i].major, students[i].classLevel);
}
}
break;
case 3:
for (int i = 0; i < MAXSTUDENT; i++)
{
lowerCase(students[i].classLevel, MAXSTUDENT);

if (strcmp(printSenior, students[i].classLevel) == 0)
{
if (major == 0)
{
printf("\n\t\tAll Computer Science Majors\n");
printf("\nFirst Name\tLast Name\tStudent ID\tMajor\tClass Level\n");
major++;
}
printf("\n%s\t\t%s\t%d\t\t%s\t%s\n", students[i].fName, students[i].lName, students[i].studentID, students[i].major, students[i].classLevel);
}
}
break;
default:
userInstructions();
break;
}// end switch
}// end while loop




return 0;

}// end main
void printStudents(Student students[], int istudent)
{
printf("\nFirst Name\tLast Name\tStudent ID\tMajor\tClass Level\n");
for (int i = 0; i < istudent; i++)
printf("\n%s\t\t%s\t%d\t\t%s\t%s\n", students[i].fName, students[i].lName, students[i].studentID, students[i].major, students[i].classLevel);
printf("\n\n");
}// end printStudents

void userInstructions(void)
{
printf("Commands: 1=Display Overall Students, 2=Display All Seniors, 3=Display All Computer Science Major, 4=Exit Game");
printf("\nEnter Command\n");


} // end userInstructions

void lowerCase(char a[], int numChar)
{
int i = 0;
while (a[i] != '\0')
{
a[i] = tolower(a[i]);
i++;
}
}// end lowerCase
Last edited on
Topic archived. No new replies allowed.