Question

C Programming

Please read the sample runs carefully as this is quite different from the previous projects. In this project, the student can

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

Enter the course number to add 4587 Course added. Choose from the following options: 1- Add a course for the student 2- Drop

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

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 3

Choose from the following options: L-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 3 VALENCE COMMUNITY COLLEGE ORLANDO FL 10101 Fee Invoice Prepared for Student: 5698 1 Credit Hour -$120.25 CRN CR PREFIX CR HOURS Health &id fees $ 35.00 Total Payments $ 35.00 Choose Trom the IolLowing options: L-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 course number to add 4587 Course added. 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 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): N Enter the course number to add 4599 Course added.
Choose from the following options: L-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 3 VALENCE COMMUNITY COLLEGE ORLANDO FL 10101 Fee Invoice Prepared for Student: 5698 1 Credit Hour $120.25 CRN CR PREFIX CR HOURS 4587 MAT 236 4599COP 220 $ 481.00 360.75 Health &id fees $ 35.00 Total Payments $ 876.75 Choose from the following options: L-Add a course for the student 2- Drop a course for the student 3- Print the fee invoice 0- Exit program Enter your selection: 0 Goodbye!
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:
Please read the sample runs carefully as this is quite different from the previous projects. In t...
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
  • The homework assignment is to write a fee invoice using C. It must follow the guidelines posted i...

    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...

  • 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...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, t...

    In C++ Write a menu driven C++ program to read a file containing information for a list of Students, process the data, then present a menu to the user, and at the end print a final report shown below. You may(should) use the structures you developed for the previous assignment to make it easier to complete this assignment, but it is not required. Required Menu Operations are: Read Students’ data from a file to update the list (refer to sample...

  • Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1...

    Develop an interactive program to assist a Philosophy professor in reporting students’ grades for his PHIL-224.N1 to the Office of Registrar at the end of the semester. Display an introductory paragraph for the user then prompt the user to enter a student record (student ID number and five exam-scores – all on one line). The scores will be in the range of 0-100. The sentinel value of -1 will be used to mark the end of data. The instructor has...

  • please Code in c++ Create a new Library class. You will need both a header file...

    please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...

  • Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses:...

    Programming Project 3 See Dropbox for due date Project Outcomes: Develop a Java program that uses: Exception handling File Processing(text) Regular Expressions Prep Readings: Absolute Java, chapters 1 - 9 and Regular Expression in Java Project Overview: Create a Java program that allows a user to pick a cell phone and cell phone package and shows the cost. Inthis program the design is left up to the programmer however good object oriented design is required.    Project Requirements Develop a text...

  • HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE...

    HELLO, PLEASE TAKE TIME TO ANSWER THIS QUESTION. PLESE ENSURE ITS CORRECT AND SHOW THAT THE PROGRAM RUNS. Task 1: Enforcing const-ness throughout Your first job will be to go through all of the code and decide which functions should be declared const. You should find several places throughout the program where this makes sense. We will also make the id data member in the Customer class const , as once a customer has been created their ID will never...

  • Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview...

    Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...

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