Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #include <string.h> #include <fstream> #include <iomanip> #pragma warning(disable:4996) #define MAX 100 using namespace std; typedef struct SinhVien { char masv[10], ho[10], ten[20]; int diem; } sv; typedef struct IndexHoTen { int vitri; char ho[10], ten[20]; } idxHT; typedef struct IndexMaSV { int vitri; char masv[10]; } idxMSV; typedef struct IndexDiem { int vitri, diem; } idxDiem; int n; sv DS[MAX]; idxHT IndexHoTen[MAX]; idxMSV IndexMaSV[MAX]; idxDiem IndexDiem[MAX]; void CapNhatIndex(sv a, int i) { IndexDiem[i].diem = a.diem; IndexDiem[i].vitri = i; strcpy(IndexHoTen[i].ho, a.ho); strcpy(IndexHoTen[i].ten, a.ten); IndexHoTen[i].vitri = i; strcpy(IndexMaSV[i].masv, a.masv); IndexMaSV[i].vitri = i; } void Nhap1(sv &a) { nhaplaimsv: cout << "Nhap vao Ma Sinh Vien: "; fflush(stdin); cin >> a.masv; //if () ktra trung cout << "Nhap vao Ho: "; cin >> a.ho; cout << "Nhap vao Ten: "; cin >> a.ten; nhaplaidiem: cout << "nhap vao Diem: "; cin >> a.diem; if (a.diem < 0 || a.diem >10) goto nhaplaidiem; } void NhapNhieu(sv DS[], int n) { for (int i = 0; i < n; i++) { cout << "Nhap vao thong tin sinh vien thu " << i + 1 << endl; Nhap1(DS[i]); } } void Xuat1(sv a) { cout << left << setw(10) << a.masv << "\t"; cout << left << setw(10) << a.ho << "\t"; cout << left << setw(20) << a.ten << "\t"; cout << left << setw(4) << a.diem << endl; } void SapXepTheoTenVaDiem(sv DS[], int n) { for (int j = 0; j < n - 1; j++) { for (int k = j + 1; k < n; k++) { if (IndexDiem[k].diem < IndexDiem[j].diem) { idxDiem temp; temp = IndexDiem[k]; IndexDiem[k] = IndexDiem[j]; IndexDiem[j] = temp; } } } } int TimTheoMSV(sv DS[], int n, char masvcantim[10]) { int i = 0; for (i; i < n; i++) { if (strcmp(DS[i].masv, masvcantim) == 0) return i; } return -1; } void TimTheoTen(sv DS[], int n) { bool check = false; char tencantim[20]; cout << "Nhap vao ten sinh vien can tim: "; nhaplai: cin >> tencantim; SapXepTheoTenVaDiem(DS, n); for (int i = 0; i < n; i++) { if (strcmp(tencantim, DS[i].ten) == 0) { check = true; Xuat1(DS[i]); cout << endl; } } if (check == false) { cout << "Khong tim thay sinh vien ten: " << tencantim << endl; cout << "Vui long nhap lai: " << endl; goto nhaplai; } } void Xoa(sv DS[], int &n) { int i = 0; char macanxoa[10]; cout << "Nhap vao ma sinh vien can xoa: "; cin >> macanxoa; TimTheoMSV(DS, n, macanxoa); DS[i] = DS[i + 1]; n--; } void Them(sv DS[], int &n) { int soluongthem,k = n,j = 1; nhap: cout << "Nhap vao so luong sinh vien can them"; cin >> soluongthem; if (n + soluongthem>100 || soluongthem < 0) { cout << "Ban da nhap sai so luong. vui long nhap lai! " << endl; } else { n = n + soluongthem; for (int i = k; i < n; i++) { cout << "Nhap vao thong tin sinh vien thu " << j << endl; Nhap1(DS[i]); j++; } } } void Sua(sv DS[], int n) { char masvcan[10]; cout << "Nhap vao ma sinh vien can tim: "; nhapsvcantim: cin >> masvcan; if (TimTheoMSV(DS, n, masvcan) == -1) { cout << "Khong tim thay sinh vien can tim! vui long nhap lai:" << endl; goto nhapsvcantim; } else { int i = TimTheoMSV(DS, n, masvcan); int select; system("cls"); cout << "1. Sua ma sv \n2. Sua Ho \n3. Sua ten \n4. Sua diem \n0. Back" << endl; nhaplai: cin >> select; switch (select) { case 1: cout << "Nhap vao ma sinh vien moi: "; cin >> DS[i].masv; break; case 2: cout << "Nhap vao ho moi: "; cin >> DS[i].ho; break; case 3: cout << "Nhap vao ten moi: "; cin >> DS[i].ten; break; case 4: cout << "Nhap vao diem moi: "; cin >> DS[i].diem; break; case 0: break; default: cout << "Lua chon khong dung! vui long nhap lai: " << endl; goto nhaplai; break; } } } void Menu() { nhap: system("cls"); cout << "================================Menu================================" << endl; cout << "1.Them sv\n2.Xuat\n3.Xoa sv\n4.Sua sv\n5.Tim sv theo mssv\n6.Tim sv theo ten\n7.Luu File\n8.Doc File\n0.Thoat!" << endl; int chon; cout << "Nhap chon: "; cin >> chon; if (chon == 0) return; else if (chon == 1) { Them(DS,n); system("pause"); } else if (chon == 2) { //MenuXuat(); } else if (chon == 3) { Xoa(DS,n); system("pause"); } else if (chon == 4) { Sua(DS,n); } else if (chon == 5) { char masvcan[10]; cout << "Nhap vao ma sinh vien can tim: "; cin >> masvcan; if (TimTheoMSV(DS, n, masvcan) == -1) { cout << "Khong tim thay sinh vien co ma sinh vien la: " << masvcan << endl; } else { int i = TimTheoMSV(DS, n, masvcan); Xuat1(DS[i]); } system("pause"); } else if (chon == 6) { TimTheoTen(DS, n); system("pause"); } else if (chon == 7) { //LuuFile(); system("pause"); } else if (chon == 8) { //DocFile(); system("pause"); } else { cout << "\nban nhap sai.\nMoi ban nhap lai!\n"; system("pause"); } goto nhap; } int main() { Menu(); system("pause"); return 0; }
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
भारत