Home / Expert Answers / Computer Science / these-constants-struct-and-function-prototypes-are-defined-in-the-given-givena1-h-header-file-de-pa245

(Solved): These constants, struct and function prototypes are defined in the given givenA1.h header file. #de ...



These constants, struct and function prototypes are defined in the given givenA1.h header file.

#define NUMBER_PROFS 6
This represents the number of professors.

#define NUMBER_COURSES 10 This represents the number of courses.

#define MAX_STR 50
This will represent the maximum length of a string.

     struct courseStruct {
           char courseName [MAX_STR],
           int courseID

};

This struct will represent a single course. The courseName field is a string that will represent the name of the course and the courseID field is an int that will represent the course id of that particular course.

For example, if course “Programming” has a course id 1300, then courseStruct used would have courseName as “Programming” and courseID as 1300.

int readCourse (
     char filename [MAX_STR],
     struct courseStruct courseInfo [NUMBER_COURSES]

)

This function must read courseNames and courseID from a text file called courses.txt to populate the array of structs called courseInfo with course names and corresponding course ids. A sample courses.txt file is provided. The text file name “courses.txt” must be read as the first command-line argument (e.g., ./a.out courses.txt data.txt) and not from standard input. Note that the first 10 lines of this file store 10 course names, and the next 10 lines store 10 course IDs, assuming that NUMBER_COURSES is set to 10. Also note that course names may have multiple words in them (e.g. Introduction to Programming). All course IDs are integers.

The function will either return 1 (to indicate successful operation) or -1 to represent abnormal exit, which can be:

Passing a NULL file pointer to the function

Passing a file that has more lines than 2 times NUMBER_COURSES

Passing a file that has less lines than 2 times NUMBER_COURSES

In normal operation, this function will read in exactly 2 times NUMBER_COURSES lines.

Make sure you test this thoroughly—this and the readProfAndCoursesTaught function represent the backbone of this application. Some implementations of line-by-line file reading may inadvertently introduce an extra newline ('\n') in the string returned to the developer, which will mess up our testing. This is an error that can become "consistent" throughout the program (for example, if you mistakenly read the strings as {"Programming\n”, ”Introductory Programming\n”, “Object Oriented Programming\n”, “Data Structures\n”, “Software Systems Development and Integration\n”, “Intro to Databases\n”, “Analysis and design of Algorithms\n”, “Advanced OO\n”,“Data Mining\n”, “Cyber SecurityProgramming\n"}, the rest of the program will likely run without error, only to fail the string comparison tests in grading. This is because the remaining functions will read and write the botched course names and assume they are correct.



We have an Answer from Expert

View Expert Answer

Expert Answer


The givenA1.h header file defines three constants: NUMBER_PROFS, NUMBER_COURSES, and MAX_STR. NUMBER_PROFS represents the number of professors, NUMBER
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe