Add and first inti c sbn projects ass

This commit is contained in:
Sambo Chea 2020-07-31 17:49:59 +07:00
parent e02f057a46
commit 21c56efbd1
14 changed files with 215 additions and 0 deletions

37
data/students.txt Normal file
View File

@ -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

6
data/welcome.txt Normal file
View File

@ -0,0 +1,6 @@
_ _ _ _
| || || | | |
| || || | ____ | | ____ ___ ____ ____
| ||_|| | / _ )| | / ___) / _ \ | \ / _ )
| |___| |( (/ / | |( (___ | |_| || | | |( (/ /
\______| \____)|_| \____) \___/ |_|_|_| \____)

6
note/section1.txt Normal file
View File

@ -0,0 +1,6 @@
(1) Display students details
(2) Search for a students 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

6
run Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
echo "compile the program.c file..."
gcc work1/main.c -o program
echo "run the program..."
./program

2
util/constants.h Normal file
View File

@ -0,0 +1,2 @@
const char *WELCOME_FILE_DATA = "./data/welcome.txt";
const char *STUDENT_FILE_DATA = "./data/students.txt";

6
util/define.h Normal file
View File

@ -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

9
util/utils.c Normal file
View File

@ -0,0 +1,9 @@
#include "stdlib.h"
void clrscr() {
// for linux or unix only
// system("clear");
// for windows os only
// system("cls");
}

7
work1/course_tag.h Normal file
View File

@ -0,0 +1,7 @@
struct course_tag
{
char course_name[20];
int no_of_units;
int marks[4];
float avg;
};

27
work1/function.c Normal file
View File

@ -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);
}

9
work1/function.h Normal file
View File

@ -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();

36
work1/main.c Normal file
View File

@ -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();
}

50
work1/menu.c Normal file
View File

@ -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 students 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;
}
}

5
work1/person_tag.h Normal file
View File

@ -0,0 +1,5 @@
struct person_tag
{
char name[20];
char id[10];
};

9
work1/student_tag.h Normal file
View File

@ -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;
};