Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <stdio.h> #include <conio.h> #include <math.h> #include <string.h> struct DATE { int ngay, thang, nam; }; struct SV { char MSSV [15]; char hoTen [50]; DATE ns; float diemTB; }; void nhap1SV (SV &x); void nhapDSSV (SV x[], int &n); void xuatDSSV (SV x[], int n); void timThongTinTheoMSSV (SV x[], int n); void suaDiem(SV x[], int n); void sapXepTheoMSSV(SV x[], int n); void sapXepTheoDTB(SV x[], int &n); void timAvaXoaTheoMSSV (SV x[], int &n, char MaSo[]); int docFile(SV x[], int n, char fileName[]); void ghiFile(SV x[], int n, char fileName[]); int main() { SV x[15]; int n, chon; char maMuonXoa [15]; char fileName[] = "BT_Nhom.txt"; while (true) { printf("\n\t----CHUONG TRINH QUAN LY SINH VIEN C----"); printf("\n\t 1. Doc danh sach SV cua file"); printf("\n\t 2. Nhap danh sach SV"); printf("\n\t 3. Xuat danh sach SV"); printf("\n\t 4. Sua diem cua mot SV bat ky"); printf("\n\t 5. Tim kiem thong tin SV dua vao viec nhap MSSV"); printf("\n\t 6. Sap xep SV theo MSSV"); printf("\n\t 7. Sap xep thu hang SV theo DTB"); printf("\n\t 8. Xoa SV ra khoi danh sach dua tren MSSV"); printf("\n\t 9. Ghi danh sach SV vao file"); printf("\n\t 0. Thoat. "); printf("\n\t--------------------------------------------------"); printf("\n\nNhap tuy chon: "); fflush(stdin); scanf("%d", &chon); switch(chon) { case 1: printf("\n\t 1. DOC DANH SACH SINH VIEN"); docFile(x, n, fileName); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 2: printf("\n\t 2. NHAP DANH SACH SV\n"); do { printf("\nNhap so luong SV (0<n<=15): "); scanf("%d", &n); } while (n<=0 || n>15); printf("\n\tNHAP DANH SACH SV"); nhapDSSV(x,n); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 3: printf("\n\t 3.XUAT DANH SACH SV\n"); xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 4: printf("\n\t 4. SUA DIEM CUA MOT SINH VIEN BAT KY\n"); suaDiem(x,n); xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 5: printf("\n\t 5. TIM KIEM THONG TIN SV DUA VAO VIEC NHAP MSSV\n"); timThongTinTheoMSSV(x,n); // xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 6: printf("\n\t 6. SAP XEP SV THEO MSSV\n"); sapXepTheoMSSV(x,n); xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 7: printf("\n\t 7. SAP XEP THU HANG SV THEO DTB\n"); sapXepTheoDTB(x,n); xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 8: printf("\n\t 8. XOA SV RA KHOI DS DUA TREN MSSV\n"); timAvaXoaTheoMSSV(x,n,maMuonXoa); printf("\n"); xuatDSSV(x,n); printf("\n\nNhap them thong tin SV bang cach nhap tuy chon 1"); printf(" hoac nhap tuy chon 9 de doc DSSV co san tu file."); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); break; case 9: printf("\n\t 9. GHI DANH SACH SINH VIEN VAO FILE\n"); ghiFile(x,n,fileName); printf("\nGhi danh sach sinh vien vao file %s thanh cong!", fileName); printf("\nNhan 1 phim bat ky de tiep tuc.\n"); getch(); break; case 0: printf("\nBan da chon thoat chuong trinh!"); getch(); return 0; default: printf("\nKhong co chuc nang nay!"); printf("\nHay chon chuc nang hop le!"); break; } } return 1; } void nhap1SV (SV &x) { printf("\nMSSV: "); fflush (stdin); scanf("%s", &x.MSSV); printf("Ho ten: "); fflush (stdin); gets(x.hoTen); printf("Ngay/thang/nam sinh (.../.../...): "); scanf("%02d %*c %02d %*c %4d", &x.ns.ngay, &x.ns.thang, &x.ns.nam); printf("Diem TB: "); scanf("%f", &x.diemTB); } void nhapDSSV (SV x[], int &n) { fflush(stdin); for(int i=0; i<n; i++) { printf("\nNhap SV thu %d", i+1); nhap1SV(x[i]); } } void xuatDSSV (SV x[], int n) { printf("\nMSSV \t\t Ho ten \t\t\t Ngay sinh \t\t DiemTB"); for (int i=0; i<n; i++) { printf("\n%s \t %s \t\t %02d/%02d/%4d \t\t %f", x[i].MSSV, x[i].hoTen, x[i].ns.ngay, x[i].ns.thang, x[i].ns.nam, x[i].diemTB); printf("\n----------------------------------------------------------------------------------"); } } void timThongTinTheoMSSV (SV x[], int n) { int i=0; char MaSo [15]; printf("\nNhap MSSV: "); fflush(stdin); gets(MaSo); printf("\nDanh sach SV duoc tim thay la: "); for(int i=0; i<n; i++) if (strcmp(x[i].MSSV, MaSo) == 0) { printf("\nMSSV \t\t Ho ten \t\t\t Ngay sinh \t\t DiemTB"); printf("\n%s \t %s ", x[i].MSSV, x[i].hoTen); printf("\t\t %02d/%02d/%4d \t\t %2.1f", x[i].ns.ngay, x[i].ns.thang, x[i].ns.nam, x[i].diemTB); break; } if (i == n) printf("Khong tim thay SV nao."); } void suaDiem(SV x[], int n) { int i=0; char MaSo [15]; printf("\nNhap MSSV: "); fflush(stdin); gets(MaSo); for(int i=0; i<n; i++) if (strcmp(x[i].MSSV, MaSo) == 0) { printf("\nNhap lai diem TB: "); scanf("%f", &x[i].diemTB); } if (i==n) printf("Khong tim thay SV nao."); } void sapXepTheoMSSV(SV x[], int n) { SV a; int i,j; for (int i=0; i<n-1; i++) for (int j=i+1; j<n; j++) if (strcmp (x[i].MSSV, x[j].MSSV) > 0) { a = x[i]; x[i] = x[j]; x[j] = a; } } void sapXepTheoDTB(SV x[], int &n) { SV tmp; int i, j; for (i=0; i<n-1; i++) for (j=i+1; j<n; j++) if (x[i].diemTB < x[j].diemTB) { tmp = x[i]; x[i] = x[j]; x[j] = tmp; } } void timAvaXoaTheoMSSV (SV x[], int &n, char MaSo[]) { printf("\n"); printf("\nNhap MSSV: "); fflush(stdin); gets(MaSo); for(int i=0; i<n; i++) if (strcmp (x[i].MSSV, MaSo) == 0) { // xoa SV thu i for (int j=0; j<n-1; j++) x[i] = x[j+1]; // xoa xong printf("\nDanh sach sv con lai la: "); n--; return; } printf("\n\nTrong DSSV khong co ma A nay!"); } void ghiFile(SV x[], int n, char fileName[]) { FILE * fp; fp = fopen (fileName,"w"); fprintf(fp, "\tMSSV \t\t\t Ho ten\n"); for(int i = 0;i < n;i++) { fprintf(fp, "%20s %40s \n", x[i].MSSV, x[i].hoTen); } fclose (fp); } int docFile(SV x[], int n, char fileName[]) { FILE * fp; int i = 0; fp = fopen (fileName, "r"); printf("\nChuan bi doc file: "); puts(fileName); // doc thong tin sinh vien for(int i = 0;i < n;i++) { while (!feof(fp)) { fgets(x[i].MSSV, 15, fp); fgets(x[i].hoTen, 50, fp); printf("%s", x[i].MSSV); printf("%s", x[i].hoTen); } } fclose (fp); // tra ve so luong sinh vien duoc doc tu file return i; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत