Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

-------------------------------------- Total Payments $ 876.75 Sample Run 1 (The

ID: 3747915 • Letter: #

Question

-------------------------------------- Total Payments $ 876.75

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

Enter the Students Id:

5656

3

4

2

Enter the 2 course numbers separated by - :(like 2356-8954)

4587-4599

-------------------------------------- Total Payments $ 876.75

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

Enter the Students Id:

5656

2

Enter the 2 course numbers separated by - :(like 2356-8954)

4587-4592

Sorry, invalid course number(s)!


Enter the 2 course numbers separated by - :(like 2356-8954)

4587-4599

-------------------------------------- Total Payments $ 876.75

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

Enter the Students Id:

5656

1

4586

4599

-------------------------------------- Total Payments $ 395.75

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

Enter the Students Id:

5656

0

-------------------------------------- Total Payments $ 35.00

Explanation / Answer

//C Program Code:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

struct courses_data
{
int CRN;
char *course_prefix;
int credit_hours;
};

int get_credit_hour(struct courses_data obj[], int crn)
{
for(int i=0;i<4;i++)
{
if(obj[i].CRN==crn)
return obj[i].credit_hours;
}
return 0;
}

char** str_split(char* a_str, const char a_delim)
{
char** result = 0;
size_t count = 0;
char* tmp = a_str;
char* last_comma = 0;
char delim[2];
delim[0] = a_delim;
delim[1] = 0;
while (*tmp)
{
if (a_delim == *tmp)
{
count++;
last_comma = tmp;
}
tmp++;
}
count += last_comma < (a_str + strlen(a_str) - 1);
count++;
result = malloc(sizeof(char*) * count);
if (result)
{
size_t idx = 0;
char* token = strtok(a_str, delim);
while (token)
{
assert(idx < count);
*(result + idx++) = strdup(token);
token = strtok(0, delim);
}
assert(idx == count - 1);
*(result + idx) = 0;
}
return result;
}

int main()
{
struct courses_data obj[4];
obj[0].CRN=4587; obj[0].course_prefix="MAT 236";obj[0].credit_hours=4;
obj[1].CRN=4599; obj[1].course_prefix="COP 220";obj[1].credit_hours=3;
obj[2].CRN=8997; obj[2].course_prefix="GOL 124";obj[2].credit_hours=1;
obj[3].CRN=9696; obj[3].course_prefix="COP 100";obj[3].credit_hours=3;
  
int id,no_of_courses;
float credit_per_hour=120.25;
float total_amount=35.00;
int crn_id[2],crn;
char *crns;
/* get the account number */
printf("Enter the Students Id: ");
scanf("%d", &id);
printf("Enter how may courses taken(up to 2): ");
scanf("%d", &no_of_courses);
while(no_of_courses>2)
{
printf("Invalid number of courses. ");
printf("Please re-enter how many courses ( up to to 2 ): ");
scanf("%d", &no_of_courses);
}
switch(no_of_courses)
{
case 0:
printf("Thank you!");
printf(" PRESS ANY KEY TO CONTINUE . . .");
getchar();
printf(" VALENCE COMMUNITY COLLEGE");
printf(" ORLANDO FL 10101");
printf(" *************************");
printf(" Fee Invoice Prepared for Student V%d",id);
printf(" Health & id fees $ 35.00");
printf(" -------------------------------------- Total Payments $ %f",total_amount);
break;
case 1:
printf("Enter the course number: ");
scanf("%d",&crn);
while(get_credit_hour(obj,crn)==0)
{
printf("Sorry, invalid course number(s)! ");
printf("Enter the course number: ");
scanf("%d",&crn);
}
int credits=get_credit_hour(obj,crn);
printf("%d",credits);
total_amount+=credits*credit_per_hour;
printf(" Thank you!");
printf(" PRESS ANY KEY TO CONTINUE . . .");
getchar();
printf(" VALENCE COMMUNITY COLLEGE");
printf(" ORLANDO FL 10101");
printf(" *************************");
printf(" Fee Invoice Prepared for Student V%d",id);
printf(" 1 Credit Hour = $%f",credit_per_hour);
printf(" CRN CREDIT HOURS");
printf(" %d %d $ %f",crn,credits,credits*credit_per_hour);
printf(" Health & id fees $ 35.00");
printf(" -------------------------------------- Total Payments $ %f",total_amount);
break;
case 2:
printf("Enter the 2 course numbers separated by - :(like 2356-8954) ");
scanf("%s",crns);
char** tokens;
tokens = str_split(crns, '-');
int x,y;
sscanf(tokens[0], "%d", &x);  
crn_id[0]=x;
sscanf(tokens[1], "%d", &y);
crn_id[1]=y;
  
while(get_credit_hour(obj,crn_id[0])==0 || get_credit_hour(obj,crn_id[1])==0 )
{
printf("Sorry, invalid course number(s)! ");
printf("Enter the 2 course numbers separated by - :(like 2356-8954) ");
scanf("%s",crns);
tokens = str_split(crns, '-');
int x,y;
sscanf(tokens[0], "%d", &x);  
crn_id[0]=x;
sscanf(tokens[1], "%d", &y);
crn_id[1]=y;
}
int credits1=get_credit_hour(obj,crn_id[0]);
int credits2=get_credit_hour(obj,crn_id[1]);
total_amount+=(credits1*credit_per_hour)+(credits2*credit_per_hour);
printf(" Thank you!");
printf(" PRESS ANY KEY TO CONTINUE . . .");
getchar();
printf(" VALENCE COMMUNITY COLLEGE");
printf(" ORLANDO FL 10101");
printf(" *************************");
printf(" Fee Invoice Prepared for Student V%d",id);
printf(" 1 Credit Hour = $%f",credit_per_hour);
printf(" CRN CREDIT HOURS");
printf(" %d %d $ %f",crn_id[0],credits1,credits1*credit_per_hour);
printf(" %d %d $ %f",crn_id[1],credits2,credits2*credit_per_hour);
printf(" Health & id fees $ 35.00");
printf(" -------------------------------------- Total Payments $ %f",total_amount);
break;
  
}
return 0;
}