Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************************
- * moduleMarks.c
- * Program to handle assessment marks.
- * Gerda Simkute
- * November 2017
- ***********************************************************************/
- #include <stdio.h>
- #include <string.h>
- #define MAX_NAME_LENGTH 20
- void printMenu();
- void emptybuffer();
- void displayTitle();
- int numberStudents();
- void promptNames(char pString[][MAX_NAME_LENGTH], int num);
- void
- promptMarksFor1(char names[][20], int marks[][3], int numOfstudents);
- void
- promptMarksFor2(char names[][20], int marks[][3], int numOfstudents);
- void
- promptMarksFor3(char names[][20], int marks[][3], int numOfstudents);
- int findByName(char names[][20], int marks[][3], int length);
- int main() {
- displayTitle();
- int numberOfStudents = numberStudents();
- char names[numberOfStudents][MAX_NAME_LENGTH];
- promptNames(names, numberOfStudents);
- int marks[numberOfStudents][3];
- // promptMarksFor1(names, marks, numberOfStudents);
- // promptMarksFor2(names, marks, numberOfStudents);
- // promptMarksFor3(names, marks, numberOfStudents);
- while(startMenu(names, marks, numberOfStudents)){;}
- findByName(names, marks, numberOfStudents);
- }
- /* display title function */
- void displayTitle() {
- printf
- ("===================================================="
- "=====\n");
- printf(" ASSESSMENT MARKS PROGRAM\n");
- printf
- ("===================================================="
- "=====\n");
- }
- /* number of students function */
- int numberStudents() {
- int numStudents;
- puts("Please enter the number of students taking the module: (Max"
- " 75)");
- while (scanf("%d", &numStudents) != 1 || numStudents < 1 ||
- numStudents > 75)
- {
- puts(" ERROR! the number must be in the range of 1 and 75. "
- "Please re-enter the value");
- emptybuffer();
- }
- printf("You have chosen %d students\n\n", numStudents);
- getchar();
- return numStudents;
- }
- /* student names function */
- void promptNames(char names[][MAX_NAME_LENGTH], int num) {
- int i;
- printf("Please enter the names of %d students:\n", num);
- for (i = 0; i < num; i++) {
- printf("Student Name:\n");
- scanf("%[^\n]", names[i]);
- emptybuffer();
- }
- }
- /* display the menu list */
- void printMenu() {
- printf
- ("==================================================="
- "======\n");
- printf(" MAIN MENU\n");
- printf
- ("==================================================="
- "======\n");
- printf("1. Enter marks for coursework 1\n");
- printf("2. Enter marks for coursework 2\n");
- printf("3. Enter marks for coursework 3\n");
- printf("4. Display a particular students mark\n");
- printf("5. Supervisor mode\n");
- printf("6. Exit program\n\n");
- printf("---------------------------------------------------\n");
- }
- /* select from menu */
- int startMenu (char names [][MAX_NAME_LENGTH], int marks [][3], int
- number)
- {
- int entry;
- printMenu();
- puts("Please enter option number:");
- while (scanf("%d", &entry) != 1)
- {
- puts("Error, please enter 1-6");
- emptybuffer();
- }
- emptybuffer();
- switch(entry)
- {
- case 1 : promptMarksFor1(names, marks, number);
- break;
- case 2 : promptMarksFor2(names, marks, number);
- break;
- case 3 : promptMarksFor3(names, marks, number);
- break;
- case 4:
- findByName(names, marks, number);
- break;
- case 6:
- return 0;
- default:
- puts("Incorrect number. Enter 1-6");
- }
- return 1;
- }
- /* enter the marks for coursework 1 */
- void
- promptMarksFor1(char names[][20], int marks[][3], int numOfstudents) {
- char charChoice;
- do {
- int i;
- puts("-------------------------------");
- puts("Enter marks for coursework 1:\n");
- for (i = 0; i < numOfstudents; i++) {
- char *currentName = names[i];
- printf("Enter marks for %s:\n", currentName);
- while (scanf("%d", &marks[i][0]) != 1) {
- puts("Try again. Enter a number");
- emptybuffer();
- }
- emptybuffer();
- }
- puts("Are you okay with these marks? Please enter Y or N:");
- scanf("%c", &charChoice);
- emptybuffer();
- } while (charChoice != 'y' && charChoice != 'Y');
- }
- /* Enter marks for coursework 2 */
- void
- promptMarksFor2(char names[][20], int marks[][3], int numOfstudents) {
- char charChoice;
- do {
- int i;
- puts("-------------------------------");
- puts("Enter marks for coursework 2:\n");
- for (i = 0; i < numOfstudents; i++) {
- char *currentName = names[i];
- printf("Enter marks for %s:\n", currentName);
- while (scanf("%d", &marks[i][1]) != 1) {
- puts("Try again. Enter a number");
- emptybuffer();
- }
- emptybuffer();
- }
- puts("Are you okay with these marks? Please enter Y or N:");
- scanf("%c", &charChoice);
- emptybuffer();
- } while (charChoice != 'y' && charChoice != 'Y');
- }
- /* Enter marks for coursework 3 */
- void
- promptMarksFor3(char names[][20], int marks[][3], int numOfstudents) {
- char charChoice;
- do {
- int i;
- puts("-------------------------------");
- puts("Enter marks for coursework 3:\n");
- for (i = 0; i < numOfstudents; i++) {
- char *currentName = names[i];
- printf("Enter marks for %s:\n", currentName);
- while (scanf("%d", &marks[i][2]) != 1) {
- puts("Try again. Enter a number");
- emptybuffer();
- }
- emptybuffer();
- }
- puts("Are you okay with these marks? Please enter Y or N:");
- scanf("%c", &charChoice);
- emptybuffer();
- } while (charChoice != 'y' && charChoice != 'Y');
- }
- /* selecting a student and displaying their mark */
- int findByName(char names[][20], int marks [][3], int studentNum)
- {
- int t;
- for(t=0;t<studentNum;t++)printf("We have a name: %s \n\n",names[t]);
- char selectedStudent[20];
- int i;
- puts("Enter the name of the student whose mark you wish to see:");
- scanf("%[^\n]", selectedStudent);
- emptybuffer();
- for( i = 0; i < studentNum; i ++)
- {
- int matching = !strcmp(selectedStudent, names[i]);
- if (matching) break;
- }
- printf("Index is %d\n",i);
- if(i==studentNum)
- {
- printf("Error, no name found! \n");
- }
- printf("Here are the marks from %s's coursework:\n", names[i]);
- printf("%d \n", marks[i][0]);
- printf("%d \n", marks[i][1]);
- printf("%d \n\n", marks[i][2]);
- return 0;
- }
- /* empty buffer function */
- void emptybuffer() {
- while (getchar() != '\n') { ;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement