Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Microsoft Word - A1.docx Assignment 1 – cAllocation Concepts required: Files, Command-line arguments, arrays and strings, makefile, gitlab 1.0 Contextual Situation: Course Allocation ...

1 answer below »
Microsoft Word - A1.docx

Assignment 1 – cAllocation

Concepts required: Files, Command-line arguments, a
ays and strings, makefile, gitlab

1.0 Contextual Situation: Course Allocation

Congratulations! You have been hired as a developer for the Computer Science to help the
department with course assignment for the cu
ent year. As a developer for this software
(cSchedule), you have been selected to complete the following tasks below to be used
within the system.

There are cu
ently 10 courses that are offered this year. The system tracks various info
such as the number of courses taught by a professor this year and other info that is detailed
in the next section.

1.1 Prerequisite – First things First

As the sole software developer of this product, you will create a program that will allow x
number of courses that are taught by y number of professors. All data will be read in from
external files and parsed into structs. The data files provided to you will contain data for ten
(10) courses that are taught by six (6) professors.

The software will take the parsed data and determine some statistics on the courses taught.
For example, this program will predict the professor who will teach a particular course in the
next term based on state-of-the-art (not really J) algorithms.

This assignment stresses the importance of developing software that strictly conforms to
specification—when you're in the industry, you'll face all sorts of strict clients.

There are two source (2) files that you will need to submit:

(1) You will write a .c file, lastnameFirstnameA1.c containing the function implementations
detailed below

(2) You will write a .c file, lastnameFirstnameA1Main.c with the main function
_______________________________________________________________________
Use the given header file called givenA1.h – this file contains the proper function
prototypes, constants, and structures required for this assignment, also detailed below.

You are also free to create helper functions, though if they are used by the assignment
functions below, include them in the appropriate files so they are accessible to us during
grading.

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.


struct profStruct {
char profName [MAX_STR],
int coursesTaught [NUMBER_COURSES],
};

This struct will represent a single professor. The profName field is a string that will represent
the name of the professor and the coursesTaught field is an a
ay of int that will represent
the course ids of each course taught by the professor.

For example, if Ritu teaches 1300, 1500 and 3530 this year, the profStruct used would
have profName = "Ritu" and courses taught = {1300, 1500, 3530}.

**All Function prototypes described below are also given in givenA1.h **



2.0 Your Task

Part A: Write function definitions for the following tasks.

(Task1)

FILE *openFileForReading(char fileName [MAX_STR]);

This function will take in a filename as a string and attempt to create a FILE pointer out of it.
If the file opens successfully, a FILE pointer will be returned. Otherwise, NULL. You will only
open the file for reading, not writing.

(Task 2)

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 a
ay of structs called courseInfo with course names and co
esponding 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
epresent 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 e
or 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
un without e
or, only to fail the string comparison tests in grading. This is because the
emaining functions will read and write the botched course names and assume they are
co
ect.

(Task 3)

int readProfAndCoursesTaught (char filename [MAX_STR],
XXXXXXXXXXstruct profStruct profInfo [NUMBER_PROFS],
XXXXXXXXXXstruct courseStruct courseInfo [NUMBER_COURSES]
);

The prof names and course assignments MUST be read from a text file called data.txt
(read as the second command-line argument (e.g., ./a.out courses.txt data.txt)). A sample
data.txt file is provided. The first 6 lines of the file contain the prof names (assuming that
NUMBER_PROFS is set to 6). The next 6 lines will consist of characters y or n, indicating
whether a course is taught by a prof or not. Assume that the order of the course IDs used in
this function is the same as that used in function readCourse. For example, if the first 7
lines of file data.txt are given as

Ritu
Manav
Ben
Ricardo
Cathrine
Sooraj
yynnnynnnn
……

the first 6 are prof names, and the 7th line implies that prof Ritu teaches courses 1300, 1500
and 3530. This also implies that element 0 of a
ay profInfo must be populated as {“Ritu”,
{1300, 1500, 3530}};

For convenience, below is given a table that co
esponds to the prof names and courses
taught that are given in the data file called data.txt.


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
!\ Note: Uppercase and lowercase letters are both acceptable. Therefore, your function
should accept both “Y” and “y” for yes and “N” and “n” for no. It would be beneficial to store
the lowercase version within the a
ay for simplicity later.

!\ Hint: The ctype.h li
ary has some helpful functions such as tolower ().

(Task 4)

int nCourses (
int n,
struct profStruct profInfo [NUMBER_PROFS],
char profsNCourses [NUMBER_PROFS][MAX_STR]
);

This function populates an a
ay called profsNCourses with names of all professors who
teach n or more courses (n >= 0). It then returns the total number of professors who teach n
or more courses.

For example, if the following course assignment is as follows and n = 3, then the function
must populate profsNCourses with the following prof names: “Ritu”, “Ben”, “Ricardo” and
“Cathrine”. It also returns a value 4.



(Task 5)

int getCourseName (
int courseNum,
char cNameFound [MAX_STR],
struct courseStruct courseInfo [NUMBER_COURSES]
);

This function, takes a course number as input, searches for its course name and stores it in
a string parameter (e.g. cNameFound). It returns 1 if the course is found, 0 otherwise. Fo
example, if the course number is 1300, it will return 1 and store “Programming” in
cNameFound.



(Task 6)

int getCourseNum (
char cName [MAX_STR],
int * cNumFound,
struct courseStruct courseInfo [NUMBER_COURSES]
);

This function, takes a course name as input, searches for its course number and stores it in
an output int parameter (e.g. cNumFound). It returns 1 if the course is found, 0 otherwise.
For example, if the course number is 1300, it will return 1 and store 1300 in *cNumFound.
Remember to use fgets since some course names have multiple words. Also that fgets
includes the \n character!


(Task 7)

int profsTeachingCourse (
int courseNum,
struct profStruct profInfo [NUMBER_PROFS],
char taughtBy [NUMBER_PROFS][MAX_STR]

);

This function, takes a course number as input, searches for the profs teaching it, and
populates a
ay taughtBy with these prof names. It returns the total number of profs
teaching the course courseNum if the course is found, 0 otherwise. It also returns 0 if the
course is not taught by any prof. For example, if the course number is 1300, it will populate
taughtBy with “Ritu”, “Ben” and “Sooraj”. The function returns 3 in this case.



(Task 8)

float avgNumCourses (struct profStruct profInfo [NUMBER_PROFS]);

This function returns the average number of courses taught by a professor. Note that since the
average is typically a float value, you must round it to the next integer when you return the value.


For the above example, the average number of courses taught by a Prof is 17 / 6 = 2.83, therefore the
function must return 3.0.
Part B: You must write a main program that first uses the functions in tasks 1, 2 ad 3 to
populate the required data for this assignment. It then displays a menu for tasks 4, 5, 6, 7
and 8, prompts the user to enter a choice and performs the appropriate task based on the
user’s choice. Your program must end if the choice entered is any number other than 4, 5,
6, 7 and 8. Call this program lastnameFirstnameA1Main.c.
3.0 Compilation
Your program will be compiled using a makefile with the following flags:
-std=c99 -Wall

Files required to submit:
• lastnameFirstnameA1.c — your function implementations. You must submit this.
• givenA1.h —function definitions/prototypes, constants, li
ary imports, student info,
and declaration of academic integrity. You must submit this.
• lastnameFirstnameA1Main.c. — your testing file/driver program used to verify
outputs/test your functions. This file would contain a main(). You must submit this.
• Makefile that uses these source and header file to generate a target executable file
called lastnameFirstnameA1. You must submit this.
You may use a makefile that includes the following lines:
XXXXXXXXXXstart of makefile-----------------------
lastnameFirstnameA1: lastnameFirstnameA1.o lastnameFirstnameA1Main.o
gcc -Wall -std=c99 lastnameFirstnameA1.o lastnameFirstnameA1Main.c -o lastnameFirstnameA1
lastnameFirstnameA1.o: lastnameFirstnameA1.c givenA1.h
Answered 1 days After Jan 26, 2023

Solution

Aditi answered on Jan 28 2023
37 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here