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.
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()):
There are 5 global variables:
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.
The homework assignment is to write a fee invoice using C. It must follow the guidelines posted i...
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 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 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...