Question

The homework assignment is to write a fee invoice using C. It must follow the guidelines posted in the question and run as the sample run given. Here is the question and sample run below

Please read the sample runs carefully as this is quite different from the previous projects. In this project, the student can take as many courses as permitted. The list of courses to take are listed below. This time there is no restriction on the total credit hours.

Your code should allow the user, after you enter the student’s id, to do the following options:

1- Add a course for the student

2- Drop a course for the student

3- Print the fee invoice

For every option, you must have a separate function. Feel free to add helper functions as needed.

Additional Information It costs 120.25 dollars per credit hour in addition to $35.00 charged for health and id services.

COP 3223- UCF- Spring 2019 Project 5 Learning Outcomes: 1) Arrays and Functions Please read the sample runs carefully as this A fee invoice 3h uld 1 ok їǐke VALENCE COMMUNITY COLLEGE ORLANDO FL 10101 Fee Invoice Prepared for Student: 5959-DANIEL TAZI

Choose from the following options 1-Add a cour e f r the tudent 2- Drop a course for the student 3- Print the fee invoice 0-

Choose from the following options 1-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0-

COP 3223- UCF- Spring 2019 Project 5 Learning Outcomes: 1) Arrays and Functions Please read the sample runs carefully as this is quite different from the previous projects In this project, the student can take as many courses as permitted. The list of courses to take are listed below. This time there is no restriction on the total credit hours. Your code should allow the user, after you enter the student's id, to do the following options 1- Add a course for the student 2- Drop a course for the student 3- Print the fee invoice For every option, you must have a separate function. Feel free to add helper functions as needed. Additional Information It costs 120.25 dollars per credit hour in addition to $35.00 charged for health and id services. Valence Community College offers the following course: Credit Hours CRN 4587 4599 8997 9696 7895 9658 4287 9599 8927 7696 7890 9008 Course MAT 236 COP 220 GOL 124 COP 100 MNT 125 OPT 120 MAT 836 COP 220 GOM 124 COT 100 MOT 125 OPT 520
A fee invoice 3h uld 1 ok їǐke VALENCE COMMUNITY COLLEGE ORLANDO FL 10101 Fee Invoice Prepared for Student: 5959-DANIEL TAZI Credit Hour = 120.25 CRN CR PREFIX CR HOURS 4599 COP 220 4587 MAT 236 360-75 481.00 Health & id fees 추 35.00 Total PaymentS 876-75 Your code must use functions. Bottom line: there should be no redundant code variables segments, neatly indent you code and choose meaningful names for your Sample Run (The user s entry is in bold) Welcome! Enter the student' s id number: 5698 Choose from the following options 1- Add a course for the student 2- Drop a course for the tudent 3- Print the fee invoice 0- Exit program Enter your selection: 3 VALENCE COMMUNITY COLLEGE ORLANDO EL 10101 Fee Invoice Prepared for Student: 569B 1 Credit Hour $120.25 CRN CR PREFIX CR HOURS Health & id fees 추 35.00 Total PaymentS $ 35.00
Choose from the following options 1-Add a cour e f r the tudent 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 2 Enter the crn to delete: 5897 This crn isn' t valid Choose from the following options 1-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 2 Enter the crn to delete: 4587 The student isn't taking 4587/MAT 236/4 Choose from the following options 1-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 1 Would you like to print the list of courses? (y/n): y CRN 4587 4599 s97 9696 7895 9658 4287 9599 8927 7696 7890 9008 Course MAT 236 COP 220 GOL 124 COP 100 MNT 125 OPT 120 MAT 836 COP 220 GOM 124 COT 100 MOT 125 OPT 520 Credit Hours Enter the course number to add 4587 Course added Choose from the following options 1-Add a course for the student
Choose from the following options 1-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 1 Enter the course number to add 4587 Course already taken Choose from the following options 1-Add a cour e f r the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 1 Would you like to print the list of courses y/n)N Enter the course number to add4599 Course added Choose from the following options 1-Add a cour e f r the student 2- Drop a course for the student 3- Print the fe inv ice 0- Exit program Enter your selection: 3 VALENCE COMMUNITY COLLEGE ORLANDO EL 10101 Fee Invoice Prepared for Student: 5698 1 Credit Hour = $120.25 CRN CR PREFIX CR HOURS 4587 MAT 236 599 COP 220 후 481.00 후 360.75 Health & id fees 35.00 Total Payments 후 876.75
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The C program for the required functionalities is given below:

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

int CRN[] = {4587, 4599, 8997, 9696, 7895, 9658, 4287, 9599, 8927, 7696, 7890, 9008};
char course[][10] = {"MAT 236", "COP 220", "GOL 124", "COP 100", "MNT 125", "OPT 120",
"MAT 836", "COP 220", "GOM 124", "COT 100", "MOT 125", "OPT 520"};
int credit_hours[] = {4, 3, 1, 3, 2, 3, 4, 3, 1, 4, 3, 5};
int courses_taken[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int count = 0;

void displayCourses()
{
int i;
printf("\nCRN\tCourse\tCredit Hours\n");
for(i=0; i<12; i++)
printf("%d\t%s\t%d\n", CRN[i], course[i], credit_hours[i]);
}

int isCrnACourse(int x)
{
int i;
for(i=0; i<12; i++)
if(CRN[i]==x)
return i;
return -1;
}

int alreadyTaken(int x)
{
int i;
for(i=0; i<count; i++)
if(courses_taken[i]==x)
return i;
return -1;
}

void addCourse()
{
char ch;
int course_number, a;
printf("\nWould you like to print the list of courses? (y/n): ");
scanf("%c", &ch);
if(ch=='y' || ch=='Y')
displayCourses();
printf("\nEnter the course number to add : ");
scanf("%d", &course_number);
  
if(isCrnACourse(course_number) == -1)
printf("\nThis crn isn't valid!\n");
else
{
a = alreadyTaken(course_number);
if(a>=0)
printf("\nCourse already taken.\n");
else
{
courses_taken[count] = course_number;
count++;
printf("\nCourse added\n");
}
}
}

void dropCourse()
{
int course_number, a, b, i;
printf("\nEnter the crn to delete: ");
scanf("%d", &course_number);
  
b = isCrnACourse(course_number);
if(b == -1)
printf("\nThis crn isn't valid!\n");
else
{
a = alreadyTaken(course_number);
if(a==-1)
printf("\nThe student isn't taking %d/%s/%d\n", CRN[b], course[b], credit_hours[b]);
else
{
for (i=a; i<count-1; i++)
courses_taken[i] = courses_taken[i+1];
count--;
printf("\nCourse dropped\n");
}
}
}

void printFee(int id)
{
int i, index;
float total = 0;
printf("\n\nVALENCE COMMUNITY COLLEGE");
printf("\nORLANDO FL 10101");
printf("\n-------------------------");
printf("\n\nFee Invoice Prepared for Student:");
printf("\n%d", id);
printf("\n\n1 Credit Hour = $120.25");
printf("\nCRN\tCR_PREFIX\tCR_HOURS\n");
for(i=0; i<count; i++)
{
index = isCrnACourse(CRN[i]);
printf("%d\t%s\t%d\t$ %f\n", CRN[index], course[index], credit_hours[index], (120.25*credit_hours[index]));
total += (120.25*credit_hours[index]);
}
printf("\n\t\tHealth & id fees\t$ 35.00");
printf("\n\n-----------------------------------");
printf("\n\t\tTotal Payments\t$ %f", (total + 35.00));
}

int main(void)
{
int id, choice;
printf("Welcome!\n");
printf("Enter the student's id number: ");
scanf("%d", &id);
while(1)
{
printf("\n\nChoose from the following options:\n");
printf("\t1- Add a course for the student\n");
printf("\t2- Drop a course for the student\n");
printf("\t3- Print the fee invoice\n");
printf("\t0- Exit program\n");
printf("\nEnter your selection: ");
scanf("%d", &choice);
switch(choice)
{
case 0: printf("Exiting the program!");
exit(0);
case 1: addCourse();
break;
case 2: dropCourse();
break;
case 3: printFee(id);
break;
default: printf("Wrong choice");
break;
}
}
   return 0;
}

There are 6 functions in the program(excluding main()):

  1. addCourse(): This function is used to add a course for the student. The user is first asked whether he/she wants to print the list of the courses or not, and the appropriate action is taken depending on his/her input. Then the user is asked to enter the course number of the course to be added. If no such course exists, the statement "This crn isn't valid" is being printed on the screen. Else, if the student has already taken that course, the statement "Course already taken" is printed, else the course is added into the student's course list (in the courses_taken array), the count variable is incremented by 1, and the statement "Course added" is printed.
  2. dropCourse(): This function is used to drop a course for the student. The user is asked to enter the CRN of the course to be deleted. If the CRN isn't valid, the message "This crn isn't valid" is printed. Else, if the student hasn't taken this course, the statement "The student isn't taking <details of the course>" is printed, else the course is deleted from the courses_taken array and the count variable is decremented by 1.
  3. printFee(int): This function is used to print the fee invoice for the student in the format given in the question. It takes the id of the student as a parameter.
  4. displayCourses(): It is a helper function used to display the list of courses to the user in the format given in the question.
  5. isCrnACourse(int): It is a helper function which is used to check whether the given CRN is valid or not, i.e., the course having that CRN exists or not. If it is valid, the function returns the index of the course in the array, else it returns -1.
  6. alreadyTaken(int): It is a helper function which is used to check whether the student has already taken the course having the given CRN number. It takes the CRN number as a parameter and returns the index of the course in the array if the student has already taken it, else returns -1.

There are 5 global variables:

  1. CRN: It is an array that contains the CRNs of the 12 courses.
  2. course: It is an array that contains the name of the 12 courses.
  3. credit_hours: It is an array that contains the credit hours of the 12 courses.
  4. courses_taken: It is an array that stores the CRNs of those courses that the student currently has. All the elements have been initialized by zero, indicating that the student has taken no course yet.
  5. count: It is a variable that stores the count of the number of courses that the student currently has. It has been initialized to zero, indicating that the student has no courses currently.

The main() function takes as input the student id and displays the main menu repeatedly until the user doesn't decide to exit the program by choosing 0 in the main menu. Depending on the choice of the user, the corresponding functions are called. The switch-case is used for implementing the menu part of the program.

The above code is absolutely error-free and works in exactly the same manner as mentioned in the question, producing the same output.

Hope it helped. If you have any queries or doubts, please feel free to ask in the comments section. If it helped in any way, please consider giving positive ratings.

Add a comment
Know the answer?
Add Answer to:
The homework assignment is to write a fee invoice using C. It must follow the guidelines posted i...
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
  • Please read the sample runs carefully as this is quite different from the previous projects. In t...

    C Programming Please read the sample runs carefully as this is quite different from the previous projects. In this project, the student can take as many courses as permitted. The list of courses to take are listed below. This time there is no restriction on the total credit hours Your code should allow the user, after you enter the student' s id, to do the following options: 1- Add a course for the student 2- Drop a course for the...

  • Written in C, if you are able to provide comments so I can learn as I...

    Written in C, if you are able to provide comments so I can learn as I practice that would be amazing! Thank you! Learning Outcomes: Selection structures and Loops Read carefully before you start coding! At Valence community college, a student can’t take more than 3 courses under the constraint of having no more than 7 credit hours. The purpose of this assignment is to construct a fee invoice for a student. This requires the input of Student’s id as...

  • Please have the code run as shown in the sample run. Use as many functions as...

    Please have the code run as shown in the sample run. Use as many functions as possible and make the main function as clean as possible. Use C for language The purpose of this project is to create a fee invoice application for students attending Valence Community College. The main menu for your application must have the following options. 1- Add a new student 2- Add/Delete a course for a student 3- Search for a student 4- Print fee invoice...

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