0% found this document useful (0 votes)
13 views6 pages

PBLVDD

The document defines a C program to manage a student list. It defines a student structure and array to store student data. It includes functions to add students, sort by name, assign student IDs, assign emails, and print the list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

PBLVDD

The document defines a C program to manage a student list. It defines a student structure and array to store student data. It includes functions to add students, sort by name, assign student IDs, assign emails, and print the list.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <stdio.

h>

#include <stdlib.h>

#include <string.h>

#define SINH_VIEN 100

#define TEN 50

#define NGAY_SINH 20

#define GIOI_TINH 10

#define DIA_CHI 100

#define MA_SV 10

#define EMAIL 100

#define LOP 10

#define KHOA 10

struct SinhVien {

char hovaten[TEN];

char ngaySinh[NGAY_SINH];

char gioiTinh[GIOI_TINH];

char diaChi[DIA_CHI];

char maSV[MA_SV];

char email[EMAIL];

char lop[LOP];

char khoa[KHOA];

};

struct SinhVien danhSachSinhVien[SINH_VIEN];


int soLuongSinhVien = 0;

void themSinhVien() {

if (soLuongSinhVien < SINH_VIEN) {

struct SinhVien sv;

printf("Nhap ho va ten: ");

scanf("%c", &sv.hovaten);

printf("ngay thang nam sinh: ");

scanf("%c", &sv.ngaySinh);

printf("gioi tinh: ");

scanf("%c",&sv.gioiTinh);

printf("dia chi: ");

scanf("%c",&sv.diaChi);

printf("lop: ");

scanf("%c", &sv.lop);

printf("khoa: ");

scanf("%c",&sv.khoa);

danhSachSinhVien[soLuongSinhVien++] = sv;

} else {

printf("Danh sach da day, khong the them sinh vien moi.\n");

void sapXepDanhSach() {

for (int i = 0; i < soLuongSinhVien - 1; i++) {


for (int j = i + 1; j < soLuongSinhVien; j++) {

if (strcmp(danhSachSinhVien[i].hovaten, danhSachSinhVien[j].hovaten) > 0) {

struct SinhVien temp = danhSachSinhVien[i];

danhSachSinhVien[i] = danhSachSinhVien[j];

danhSachSinhVien[j] = temp;

void capMaSinhVien() {

if (soLuongSinhVien == 0) {

printf("Danh sach sinh vien trong, khong the cap ma.\n");

return;

sapXepDanhSach();

for (int i = 0; i < soLuongSinhVien; ++i) {

sprintf(danhSachSinhVien[i].maSV, "SV%d", i + 1);

printf("Da cap ma sinh vien thanh cong.\n");

}
void capEmail() {

if (soLuongSinhVien == 0) {

printf("Danh sach sinh vien trong, khong the cap email.\n");

return;

for (int i = 0; i < soLuongSinhVien; ++i) {

if (strlen(danhSachSinhVien[i].maSV) == 0) {

printf("Sinh vien thu %d chua duoc cap ma.\n", i + 1);

return;

sprintf(danhSachSinhVien[i].email, "%s@example.com", danhSachSinhVien[i].maSV);

printf("Da cap email thanh cong.\n");

void inDanhSach() {

printf("Danh sach sinh vien:\n");

for (int i = 0; i < soLuongSinhVien; ++i) {

printf("Ma SV: %s, Ten: %s %s, Ngay sinh: %s, Gioi tinh: %s, Dia chi: %s, Email: %s\n",

danhSachSinhVien[i].maSV, danhSachSinhVien[i].hovaten, danhSachSinhVien[i].hovaten,

danhSachSinhVien[i].ngaySinh, danhSachSinhVien[i].gioiTinh,

danhSachSinhVien[i].diaChi, danhSachSinhVien[i].email);

}
int main() {

int luaChon;

do {

printf("\nMENU:\n");

printf("1-Them sinh vien.\n");

printf("2-Sap xep danh sach.\n");

printf("3-Cap Ma sinh vien.\n");

printf("4-Cap email.\n");

printf("5-In ra danh sach.\n");

printf("6-Thoat.\n");

printf("Lua chon cua ban: ");

scanf("%d", &luaChon);

getchar();

switch (luaChon) {

case 1:

themSinhVien();

break;

case 2:

sapXepDanhSach();

break;

case 3:

capMaSinhVien();

break;
case 4:

capEmail();

break;

case 5:

inDanhSach();

break;

case 6:

printf("Tam biet!\n");

break;

default:

printf("Lua chon khong hop le. Vui long chon lai.\n");

} while (luaChon != 6);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy