Docsity

students record system, Study Guides, Projects, Research of C programming

Toggle sidebar
bg1
Sorce Code:
1
#include <stdio.h>
2
#include <conio.h>
3
#include <stdlib.h>
4
#include <string.h>
5
#include <windows.h>
6
#define NULL 0
7
struct student{
8
char ID[15];
9
char name[20];
10
char year[20];
11
char dep[20]; ///department
12
char add[30];
13
char Level[20];
14
long unsigned int phone_no; 15
16
17 };
18
19 struct student stu; 20
21
22
COORD coord = {0,0}; ///set the cordinate to 0, 0 (top-left corner of window);
23
void gotoxy(int x, int y){
24
coord.X = x; coord.Y = y; /// X and Y coordinates
25 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
26 }
27
28
void drawRectangl(){
29
int i, j;
30
gotoxy(0,0);
31 printf("%c",201);
32 for(i = 1; i < 78; i++){
33 gotoxy(i, 0);
34 printf("%c",205);
35 }
36 gotoxy(78,0);
37 printf("%c",187);
38 for(i = 1; i < 25; i++){
39 gotoxy(78, i);
40 if(i == 6){
41 printf("%c",185);
42 }else{
43 printf("%c",186);
44 }
45 }
46 gotoxy(78, 25);
47 printf("%c",188);
48 for(i = 77; i > 0; i--){
49 gotoxy(i,25);
50 if(i == 35){
51 printf("%c",202);
52 }else{
53 printf("%c",205);
54 }
55 }
56 gotoxy(0,25);
57 printf("%c",200);
58 for(i = 24; i > 0; i--){
59 gotoxy(0,i);
60 if(i == 6){
61 printf("%c",204);
62 }else{
63 printf("%c",186);
64 }
65 }
66
67 for(i = 1; i < 78; i++){
68 gotoxy(i,6);
69 if(i == 35){
70 printf("%c",203);
71 }else{
72 printf("%c",205);
73 }
74 }
75
76 for(i = 7; i < 25; i++){
77 gotoxy(35,i);
78 printf("%c",186);
79 }
80
81 }
82
83
void clearWindow(){
84
int i,j;
pf3
pf4

Partial preview of the text

Download students record system and more Study Guides, Projects, Research C programming in PDF only on Docsity!

1 #include <stdio.h> 2 #include <conio.h> 3 #include <stdlib.h> 4 #include <string.h> 5 #include <windows.h> 6 #define NULL 0 7 struct student{ 8 char ID[ 15 ]; 9 char name[ 20 ]; 10 char year[ 20 ]; 11 char dep[ 20 ]; ///department 12 char add[ 30 ]; 13 char Level[ 20 ]; 14 long unsigned int phone_no; 15 16 17 }; 18 19 struct student stu; 20 21 22 COORD coord = { 0 , 0 }; ///set the cordinate to 0, 0 (top-left corner of window); 23 void gotoxy( int x, int y){ 24 coord.X = x; coord.Y = y; /// X and Y coordinates 25 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); 26 } 27 28 void drawRectangl(){ 29 int i, j; 30 gotoxy( 0 , 0 ); 31 printf("%c", 201 ); 32 for (i = 1 ; i < 78 ; i++){ 33 gotoxy(i, 0 ); 34 printf("%c", 205 ); 35 } 36 gotoxy( 78 , 0 ); 37 printf("%c", 187 ); 38 for (i = 1 ; i < 25 ; i++){ 39 gotoxy( 78 , i); 40 if (i == 6 ){ 41 printf("%c", 185 ); 42 } else { 43 printf("%c", 186 ); 44 } 45 } 46 gotoxy( 78 , 25 ); 47 printf("%c", 188 ); 48 for (i = 77 ; i > 0 ; i--){ 49 gotoxy(i, 25 ); 50 if (i == 35 ){ 51 printf("%c", 202 ); 52 } else { 53 printf("%c", 205 ); 54 } 55 } 56 gotoxy( 0 , 25 ); 57 printf("%c", 200 ); 58 for (i = 24 ; i > 0 ; i--){ 59 gotoxy( 0 ,i); 60 if (i == 6 ){ 61 printf("%c", 204 ); 62 } else { 63 printf("%c", 186 ); 64 } 65 } 66 67 for (i = 1 ; i < 78 ; i++){ 68 gotoxy(i, 6 ); 69 if (i == 35 ){ 70 printf("%c", 203 ); 71 } else { 72 printf("%c", 205 ); 73 } 74 } 75 76 for (i = 7 ; i < 25 ; i++){ 77 gotoxy( 35 ,i); 78 printf("%c", 186 ); 79 } 80 81 } 82 83 void clearWindow(){ 84 int i,j;

85 for (i = 37 ; i < 78 ; i++){ 86 for (j = 7 ; j < 25 ; j++){ 87 gotoxy(i,j);printf(" "); 88 } 89 } 90 return ; 91 } 92 93 void window(){ 94 drawRectangl(); 95 gotoxy( 28 , 2 ); 96 printf("STUDENT RECORD SYSTEM"); 97 gotoxy( 20 , 3 ); 98 99 100 } 101 102 void print_heading( const char st[]) { 103 104 gotoxy( 45 , 8 );printf("SRS : %s",st); 105 } 106 107 108 109 110 111 112 113 void add_student(){ 114 clearWindow(); 115 print_heading("Add Record"); 116 int print = 37 ; 117 FILE *fp; 118 fp = fopen("record.txt","ab+"); 119 if (fp == NULL){ 120 printf("Error in Opening file\nMake sure your file is not write protected"); 121 122 } else { 123 fflush(stdin); 124 gotoxy(print, 10 ); 125 printf("ID: ");gets(stu.ID); 126 127 gotoxy(print, 12 );printf("Name: "); 128 gets(stu.name); 129 gotoxy(print, 14 );printf("year: "); 130 gets(stu.year); 131 gotoxy(print, 16 );printf("Department: "); 132 gets(stu.dep); 133 gotoxy(print, 18 );printf("Address: "); 134 gets(stu.add); 135 gotoxy(print, 20 );printf("Level: "); 136 gets(stu.Level); 137 gotoxy(print, 22 );printf("Phone Number: "); 138 scanf("%ld",&stu.phone_no); 139 fwrite(&stu, sizeof (stu), 1 , fp); 140 gotoxy( 40 , 22 ); printf("The record is sucessfully added"); 141 } 142 fclose(fp); 143 return ; 144 } 145 146 void search_student(){ 147 clearWindow(); 148 print_heading("Search Record"); 149 char s_id[ 15 ]; 150 int isFound = 0 ; 151 gotoxy( 37 , 10 );printf("Enter ID to Search: ");fflush(stdin); 152 gets(s_id); 153 FILE *fp; 154 fp = fopen("record.txt","rb"); 155 while (fread(&stu, sizeof (stu), 1 ,fp) == 1 ){ 156 if (strcmp(s_id,stu.ID) == 0 ){ 157 isFound = 1 ; 158 break ; 159 } 160 } 161 if (isFound == 1 ){ 162 gotoxy( 37 , 12 ); 163 printf("The record is Found"); 164 gotoxy( 37 , 14 ); 165 printf("ID: %s",stu.ID); 166 gotoxy( 37 , 15 ); 167 printf("Name: %s",stu.name); 168 gotoxy( 37 , 16 );

256 void main_window(){ 257 int choice; 258 int x = 2 ; 259 while ( 1 ){ 260 gotoxy(x, 8 );printf("1. Add Student"); 261 gotoxy(x, 10 );printf("2. Search Student"); 262 gotoxy(x, 12 );printf("3. Modify Student Record"); 263 264 gotoxy(x, 14 );printf("4. Delete Student Record"); 265 266 gotoxy(x, 16 );printf("5. Exit"); 267 gotoxy(x, 18 );printf("Enter your choice: "); 268 scanf("%d",&choice); 269 switch (choice){ 270 case 1 : 271 add_student(); 272 break ; 273 case 2 : 274 search_student(); 275 break ; 276 case 3 : 277 mod_student(); 278 break ; 279 case 4 : 280 delete_student(); 281 break ; 282 case 5 : 283 exit( 0 ); 284 break ; 285 default : 286 break ; 287 } 288 289 } 290 291 } 292 293 int main(){ 294 295 window(); 296 main_window(); 297 return 0 ; 298 } 299 300 301