Question

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 integer and the course numbers. It costs 120.25 dollars per credit hour in addition to $35.00 charged for health and id services.

Here is the list of all courses Valence Community College offers:

CRN / Course Prefix / Credit Hours

4587 MAT 236 4

4599 COP 220 3

8997 GOL 124 1

9696 COP 100 5

4580 MAT 230 3

4581 MAT 231 4

4582 MAT 232 2

4583 MAT 233 2

3587 MAT 256 4

4519 COP 420 3

6997 GOL 127 1

9494 COP 101 3

After inputting all the necessary data (see sample run), a fee invoice as shown below should be printed to the screen.

VALENCE COMMUNITY COLLEGE

ORLANDO FL 10101

---------------------

Fee Invoice Prepared for Student V5656

1 Credit Hour = $120.25

CRN CR_PREFIX CR_HOURS

4587 MAT 236 4 $ 481.00

4599 COP 220 3 $ 360.75

Health & id fees $ 35.00

--------------------------------------

Total Payments $ 876.75

You may assume that the user will always enter different crns (but if you feel ambitious, you may add the code to checks for that. Please don’t ask for extra credit for that)

Sample Run 1(The user’s entry is in bold)

Enter the Students Id 5656

Enter how many courses-up to 3 2

Enter the 2 course number(s) 4587 4599

VALENCE COMMUNITY COLLEGE

ORLANDO FL 10101

---------------------

Fee Invoice Prepared for Student V5656

1 Credit Hour = $120.25

CRN CR_PREFIX CR_HOURS

4587 MAT 236 4 $ 481.00

4599 COP 220 3 $ 360.75

Health & id fees $ 35.00

--------------------------------------

Total Payments $ 876.75


Would you like to print another invoice? Y=yes, N=No

R

Invalid Entry (it has to be y or n): n

Goodbye!


Sample Run 2(The user’s entry is in bold)

Enter the Students Id

5656

Enter how many courses-up to 3

6

Invalid number of courses (up to 3)

0

VALENCE COMMUNITY COLLEGE

ORLANDO FL 10101

---------------------

Fee Invoice Prepared for Student V5656

1 Credit Hour = $120.25

CRN CR_PREFIX CR_HOURS

Health & id fees $ 35.00

--------------------------------------

Total Payments $ 35.00




Would you like to print another invoice? Y=yes, N=No

Y

Enter the Students Id

8975

Enter how many courses-up to 3

2

Enter the 2 course number(s)

4587 9696

Sorry we can’t process more than 7 credit hours!

Would you like to print another invoice? Y=yes, N=No

Y


Enter the Students Id

7892

Enter how many courses-up to 3

3

Enter the 3 course number(s)

8858 8256 4887

Sorry invalid crn(s)!

Would you like to print another invoice? Y=yes, N=No

N

Goodbye!


Sample Run 3 (The user’s entry is in bold)

Enter the Students Id

5656

Enter how many courses-up to 3

3

Enter the 3 course number(s)

8997 6997 9696

VALENCE COMMUNITY COLLEGE

ORLANDO FL 10101

---------------------

Fee Invoice Prepared for Student V5656

1 Credit Hour = $120.25

CRN CR_PREFIX CR_HOURS

8997 GOL 124 1 $ 120.25

6997 GOL 127 1 $ 120.25

9696 COP 100 5 $ 601.25

Health & id fees $ 35.00

--------------------------------------

Total Payments $ 876.75


Would you like to print another invoice? Y=yes, N=No

N

Goodbye!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

THE CODE FOR THE ABOVE QUESTION IS :

#include<stdio.h>

#include<string.h>

// structure to store the details of the courses offered by the college
typedef struct Course {
int CRN;
char course_prefix[10];
int credit_hours;
}
Course;

// storing the constants of the program as global variables
float cost_per_credit_hour = 120.25;
float health_and_id_charges = 35.00;
int maximum_credit_hours = 7;

// creating an array of Course struct to store the list of all
// courses Valence Community College offers
Course courses[12] = {
{
    4587,
    "MAT 236",
    4
},
{
    4599,
    "COP 220",
    3
},
{
    8997,
    "GOL 124",
    1
},
{
    9696,
    "COP 100",
    5
},
{
    4580,
    "MAT 230",
    3
},
{
    4581,
    "MAT 231",
    4
},
{
    4582,
    "MAT 232",
    2
},
{
    4583,
    "MAT 233",
    2
},
{
    3587,
    "MAT 256",
    4
},
{
    4519,
    "COP 420",
    3
},
{
    6997,
    "GOL 127",
    1
},
{
    9494,
    "COP 101",
    3
}
};

// a utility function which takes a CRN as input and return the course details
// if no such course exist then it will return an empty result which will be used for error
// handling later when get_course is used
Course get_course_details(int CRN) {
Course result = {};
int i;
// looping through all courses
for (i = 0; i < 12; i++) {
    // when a match occurs store it in result and stop checking further
    if (courses[i].CRN == CRN) {
      result.CRN = courses[i].CRN;
      strcpy(result.course_prefix, courses[i].course_prefix);
      result.credit_hours = courses[i].credit_hours;
      break;
    }
}
// return the course
return result;
}

int main() {
// local variables to store respective values as indicated by the variable names
int i, student_id, no_of_courses, credit_hours_enrolled;
// CRNs & course_details_enrolled can store "UPTO" 3 CRN numbers & 3 course details respectively
int CRNs[3];
Course course_details_enrolled[3];
// these variables will be used as flags for indicating an invalid CRN and number of courses respectively
int invalid_CRN, invalid_no_of_courses;
// this variable is to store Yes or No for looping
char repeat;

// since we have to run it ATLEAST ONCE we use do while loop
do {
    // resetting the flags in each loop
    invalid_CRN = 0;
    invalid_no_of_courses = 0;
    credit_hours_enrolled = 0;

    // taking user input
    printf("Enter the Student's Id ");
    scanf("%d", & student_id);
    printf("\nEnter how many courses-up tp 3 ");
    scanf("%d", & no_of_courses);

    // checking for invalid input of number of courses
    if (no_of_courses > 3 || no_of_courses < 0) {
      printf("\nInvalid number of courses (up to 3)\n0\n");
      invalid_no_of_courses = 1;
      no_of_courses = 0;
    }

    // if there is a valid input for number of courses then this will execute
    if (invalid_no_of_courses != 1) {

      // taking user input
      printf("\nEnter the %d course numbers(s) ", no_of_courses);
      for (i = 0; i < no_of_courses; i++) {
        scanf("%d", & CRNs[i]);
        course_details_enrolled[i] = get_course_details(CRNs[i]);
        credit_hours_enrolled += course_details_enrolled[i].credit_hours;

        // checking if a CRN is invalid . If yes then we change the invalid flag to 1
        if (course_details_enrolled[i].CRN == 0) {
          invalid_CRN = 1;
        }
      }

      // if there is an invalid CRN input then
      if (invalid_CRN == 1) {
        printf("\nSorry invalid crn(s)!\n\n");
      }

      // if CRNs are valid then checking if total credit_hours is in limit
      if (credit_hours_enrolled > maximum_credit_hours) {
        printf("\nSorry we can't process more than maximum_credit_hours credit hours!\n\n");
      }
    }

    // if everything is fine i.e valid CRNs input and credit_hours in limit then we run
    if (invalid_CRN != 1 && credit_hours_enrolled <= maximum_credit_hours) {

      // variable to store the total payment to be paid. Health charge is always added irrespective of no of courses
      float total_payments = 0;
      total_payments += health_and_id_charges;

      // printing the details
      printf("\nVALENCE COMMUNITY COLLEGE\n");
      printf("ORLANDO FL 10101\n");
      printf("---------------------\n");
      printf("\nFee Invoice Prepared for Student V%d\n\n", student_id);
      printf("1 Credit Hour = $%.2f\n\n", cost_per_credit_hour);
      printf("CRN CR_PREFIX CR_HOURS\n");

      // printing the details of course enrolled
      for (i = 0; i < no_of_courses; i++) {
        Course c = course_details_enrolled[i];
        total_payments += c.credit_hours * cost_per_credit_hour;
        printf("%d %s %d $%.2f\n", c.CRN, c.course_prefix, c.credit_hours, c.credit_hours * cost_per_credit_hour);
      }

      // printing the total
      printf("\nHealth & id fees $ %.2f\n\n", health_and_id_charges);
      printf("--------------------------------------\n");
      printf("Total Payments $ %.2f\n\n\n", total_payments);
    }

    // asking user input if S/He wants to continue.
    printf("Would you like to print another invoice? Y=yes, N=No\n");
    scanf(" %c", & repeat);
    printf("\n");

    // if invalid input then repeatedly ask for a correct option until provided one
    while (repeat != 'Y' && repeat != 'N' && repeat != 'y' && repeat != 'n') {
      printf("Invalid Entry (it has to be y or n): ");
      scanf(" %c", & repeat);
    }

    // end of do-while loop
} while (repeat == 'Y');

// program quits !
printf("\nGoodbye!");
return 0;
}

SAMPLE RUN 1:

SAMPLE RUN 2:

SAMPLE RUN 3:

Add a comment
Know the answer?
Add Answer to:
Written in C, if you are able to provide comments so I can learn as 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
  • 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...

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

  • 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