Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #include "MYTOOLS.h"
- #define MAX_SUBJECTS 10
- #define MAX_NAME_LENGTH 50
- #define MAX_COURSE_LENGTH 10
- struct name {
- char firstName[MAX_NAME_LENGTH];
- char middleName[MAX_NAME_LENGTH];
- char lastName[MAX_NAME_LENGTH];
- };
- struct birth {
- char month[MAX_NAME_LENGTH];
- int day;
- long year;
- };
- struct mysubject {
- char subject[MAX_NAME_LENGTH];
- float unit_per_subject;
- float finalGrade_per_subject;
- };
- struct studentRec {
- long idnumber;
- struct name students_name;
- char gender;
- struct birth birthdate;
- char courseYear[MAX_COURSE_LENGTH];
- int numberOfSubjectsEnrolled;
- struct mysubject subjects[MAX_SUBJECTS];
- };
- void clearInputBuffer() {
- int c;
- while ((c = getchar()) != '\n' && c != EOF);
- }
- int main() {
- int choice;
- int i;
- struct studentRec student;
- gotoxy(34,34);
- do {
- clrscr();
- drawDBox(3,1,65,28);
- //Tung Menu Thing
- gotoxy(10, 3); printf("CEBU INSTITUTE OF UNIVERSITY");
- gotoxy(10, 4); printf("Bacalso Avenue, Cebu City");
- //Akoang Actual Code
- gotoxy(10, 6); printf("I.D. number : ");
- scanf("%ld", &student.idnumber);
- clearInputBuffer();
- gotoxy(10, 7); printf("N A M E : ");
- scanf("%s %s %s", student.students_name.firstName, student.students_name.middleName, student.students_name.lastName);
- clearInputBuffer();
- gotoxy(10, 8); printf("GENDER[M/F] : ");
- scanf(" %c", &student.gender);
- clearInputBuffer();
- gotoxy(10, 9); printf("BIRTHDATE : ");
- scanf("%s %d %ld", student.birthdate.month, &student.birthdate.day, &student.birthdate.year);
- clearInputBuffer();
- gotoxy(10, 10); printf("COURSE & YR : ");
- fgets(student.courseYear, MAX_COURSE_LENGTH, stdin);
- student.courseYear[strcspn(student.courseYear, "\n")] = 0;
- gotoxy(20, 12); printf("Total no. of subjects: ");
- scanf("%d", &student.numberOfSubjectsEnrolled);
- clearInputBuffer();
- gotoxy(10, 14); printf("[SUBJECT]");
- gotoxy(30, 14); printf("[UNIT]");
- gotoxy(50, 14); printf("[GRADE]");
- for (i = 0; i < student.numberOfSubjectsEnrolled; i++) {
- gotoxy(10, 15 + i); fgets(student.subjects[i].subject, MAX_NAME_LENGTH, stdin);
- student.subjects[i].subject[strcspn(student.subjects[i].subject, "\n")] = 0;
- gotoxy(30, 15 + i); scanf("%f", &student.subjects[i].unit_per_subject);
- clearInputBuffer();
- gotoxy(50, 15 + i); scanf("%f", &student.subjects[i].finalGrade_per_subject);
- clearInputBuffer();
- }
- float sumProduct = 0;
- float total_units = 0;
- for (i = 0; i < student.numberOfSubjectsEnrolled; i++) {
- sumProduct += (student.subjects[i].unit_per_subject * student.subjects[i].finalGrade_per_subject);
- total_units += student.subjects[i].unit_per_subject;
- }
- float gpa = sumProduct / total_units;
- gotoxy(10, 16 + student.numberOfSubjectsEnrolled); printf("GPA : %.2f\n", gpa);
- gotoxy(10, 18 + student.numberOfSubjectsEnrolled); printf("Press 1 to continue or 0 to exit... ");
- scanf("%d", &choice);
- } while (choice == 1);
- return 0;
- }
Advertisement
Comments
-
- 5/10 points
- -5 did not include "MYTOOLS.h" in submission
- see me in office hours
Add Comment
Please, Sign In to add comment
Advertisement