From 21c56efbd14af99c8ecbc42cad78513c09bbf6ad Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Fri, 31 Jul 2020 17:49:59 +0700 Subject: [PATCH] Add and first inti c sbn projects ass --- data/students.txt | 37 +++++++++++++++++++++++++++++++++ data/welcome.txt | 6 ++++++ note/section1.txt | 6 ++++++ run | 6 ++++++ util/constants.h | 2 ++ util/define.h | 6 ++++++ util/utils.c | 9 ++++++++ work1/course_tag.h | 7 +++++++ work1/function.c | 27 ++++++++++++++++++++++++ work1/function.h | 9 ++++++++ work1/main.c | 36 ++++++++++++++++++++++++++++++++ work1/menu.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ work1/person_tag.h | 5 +++++ work1/student_tag.h | 9 ++++++++ 14 files changed, 215 insertions(+) create mode 100644 data/students.txt create mode 100644 data/welcome.txt create mode 100644 note/section1.txt create mode 100755 run create mode 100644 util/constants.h create mode 100644 util/define.h create mode 100644 util/utils.c create mode 100644 work1/course_tag.h create mode 100644 work1/function.c create mode 100644 work1/function.h create mode 100644 work1/main.c create mode 100644 work1/menu.c create mode 100644 work1/person_tag.h create mode 100644 work1/student_tag.h diff --git a/data/students.txt b/data/students.txt new file mode 100644 index 0000000..211c67e --- /dev/null +++ b/data/students.txt @@ -0,0 +1,37 @@ +Jon +1101825 +Computer +4 +88 +98 +52 +95 +Peter +112152 +Electrical +3 +67 +40 +59 +Mary +1201925 +Mechanical +4 +78 +55 +79 +75 +Sherin +1201925 +Civil +4 +69 +53 +34 +88 +Jose +34567 +Software +2 +34 +56 \ No newline at end of file diff --git a/data/welcome.txt b/data/welcome.txt new file mode 100644 index 0000000..d87abaf --- /dev/null +++ b/data/welcome.txt @@ -0,0 +1,6 @@ + _ _ _ _ +| || || | | | +| || || | ____ | | ____ ___ ____ ____ +| ||_|| | / _ )| | / ___) / _ \ | \ / _ ) +| |___| |( (/ / | |( (___ | |_| || | | |( (/ / + \______| \____)|_| \____) \___/ |_|_|_| \____) \ No newline at end of file diff --git a/note/section1.txt b/note/section1.txt new file mode 100644 index 0000000..fa46918 --- /dev/null +++ b/note/section1.txt @@ -0,0 +1,6 @@ +(1) Display students’ details +(2) Search for a student’s mark +(3) Find the details of student with the largest average +(4) Find the details of failed students +(5) Add new student to the record +(6) Quit program \ No newline at end of file diff --git a/run b/run new file mode 100755 index 0000000..3404d11 --- /dev/null +++ b/run @@ -0,0 +1,6 @@ +#!/bin/bash + +echo "compile the program.c file..." +gcc work1/main.c -o program +echo "run the program..." +./program \ No newline at end of file diff --git a/util/constants.h b/util/constants.h new file mode 100644 index 0000000..3457796 --- /dev/null +++ b/util/constants.h @@ -0,0 +1,2 @@ +const char *WELCOME_FILE_DATA = "./data/welcome.txt"; +const char *STUDENT_FILE_DATA = "./data/students.txt"; \ No newline at end of file diff --git a/util/define.h b/util/define.h new file mode 100644 index 0000000..e8931de --- /dev/null +++ b/util/define.h @@ -0,0 +1,6 @@ +#define MENU_1 1 +#define MENU_2 2 +#define MENU_3 3 +#define MENU_4 4 +#define MENU_5 5 +#define MENU_6 6 \ No newline at end of file diff --git a/util/utils.c b/util/utils.c new file mode 100644 index 0000000..8df69b1 --- /dev/null +++ b/util/utils.c @@ -0,0 +1,9 @@ +#include "stdlib.h" + +void clrscr() { + // for linux or unix only + // system("clear"); + + // for windows os only + // system("cls"); +} \ No newline at end of file diff --git a/work1/course_tag.h b/work1/course_tag.h new file mode 100644 index 0000000..e28cbe9 --- /dev/null +++ b/work1/course_tag.h @@ -0,0 +1,7 @@ +struct course_tag +{ + char course_name[20]; + int no_of_units; + int marks[4]; + float avg; +}; diff --git a/work1/function.c b/work1/function.c new file mode 100644 index 0000000..c516049 --- /dev/null +++ b/work1/function.c @@ -0,0 +1,27 @@ +#include "stdio.h" +#include "stdio.h" +#include "./student_tag.h" + +void display() { + printf("display..."); +} + +void search(int mark) { + printf("search mark..."); +} + +void find_largest_average() { + printf("find largest average..."); +} + +void find_failed_students() { + printf("find failed students..."); +} + +void add_new(struct student_tag student) { + printf("add new..."); +} + +void quite() { + exit(1); +} \ No newline at end of file diff --git a/work1/function.h b/work1/function.h new file mode 100644 index 0000000..dc0fdf9 --- /dev/null +++ b/work1/function.h @@ -0,0 +1,9 @@ +#include "stdlib.h" +#include "./student_tag.h" + +void display(); +void search(int mark); +void find_largest_average(); +void find_failed_students(); +void add_new(struct student_tag student); +void quite(); \ No newline at end of file diff --git a/work1/main.c b/work1/main.c new file mode 100644 index 0000000..22a05ac --- /dev/null +++ b/work1/main.c @@ -0,0 +1,36 @@ +#include "stdio.h" +#include "stdlib.h" +#include "./../util/constants.h" +#include "./../util/utils.c" +#include "./menu.c" + +int main() +{ + printf("\nInitializing program...\n"); + clrscr(); + + char c; + FILE *file; + + // check the file has load or not + // if not load correctly or file not, it must be exit the program + if ((file = fopen(WELCOME_FILE_DATA, "r")) == NULL) + { + printf("Cannot open file!\n"); + exit(1); + } + + // read the file into output screen + // if it's not meet the end of file it will run till the end of data + while ((c = getc(file)) != EOF) + { + printf("%c", c); + } + + // close the welcome file + fclose(file); + + // show menu + menu(); + +} \ No newline at end of file diff --git a/work1/menu.c b/work1/menu.c new file mode 100644 index 0000000..5efca1a --- /dev/null +++ b/work1/menu.c @@ -0,0 +1,50 @@ +#include "stdio.h" +#include "./function.c" +#include "./../util/define.h" +#include "./student_tag.h" +#include "./person_tag.h" + +void menu() +{ + printf("\n\n\n-------------------MENU-------------------\n"); + printf("\n(1) Display students’ details\n"); + printf("\n(2) Search for a student’s mark\n"); + printf("\n(3) Find the details of student with the largest average\n"); + printf("\n(4) Find the details of failed students\n"); + printf("\n(5) Add new student to the record\n"); + printf("\n(6) Quit program\n\n"); +} + + + +void choose_menu(int menu) +{ + + switch (menu) + { + case MENU_1: + display(); + break; + case MENU_2: + search(1); + break; + case MENU_3: + find_largest_average(); + break; + case MENU_4: + find_failed_students(); + break; + case MENU_5: + + struct person_tag info = {"1","Sambo"}; + struct student_tag std = {.student_info = info}; + add_new(std); + break; + case MENU_6: + quite(); + break; + default: + printf("not found!"); + break; + } +} \ No newline at end of file diff --git a/work1/person_tag.h b/work1/person_tag.h new file mode 100644 index 0000000..c60658a --- /dev/null +++ b/work1/person_tag.h @@ -0,0 +1,5 @@ +struct person_tag +{ + char name[20]; + char id[10]; +}; diff --git a/work1/student_tag.h b/work1/student_tag.h new file mode 100644 index 0000000..8599b84 --- /dev/null +++ b/work1/student_tag.h @@ -0,0 +1,9 @@ +#include "./person_tag.h" +#include "./course_tag.h" + +struct student_tag +{ + struct person_tag student_info; + struct course_tag course_info; + struct student_tag *next; +};