Xây dựng danh sách Sinh Viên - Lập Trình -->

Friday, 9 April 2021

Xây dựng danh sách Sinh Viên

Khôi Ròm
April 09, 2021 - Friday, 9 April 2021

 Xậy dựng 1 kiểu cấu trúc sinh viên không vượt quá 100 người gồm thông tin sau:

Ho và tên
Điểm môn 1, môn 2, môn 3, ĐTB
Sắp xếp theo điểm trung bình và có kẹp vị thứ từng người
Code:

#include <bits/stdc++.h> using namespace std; struct student { string HoTen; float mon1,mon2,mon3,dtb; }; typedef student ST; float DTB(float a, float b , float c) { return (a+b+c)/3; } void Inp_Array(ST a[],int n) { for(int i = 0 ; i < n ; i++) { cout<<"Sinh vien thu "<<i+1<<endl; cout<<"Nhap ho va ten: "; fflush(stdin); getline(cin,a[i].HoTen); cout<<"Nhap diem thi cac mon"<<endl; cout<<"Diem mon 1: "; cin>>a[i].mon1; cout<<"Diem mon 2: "; cin>>a[i].mon2; cout<<"Diem mon 3: "; cin>>a[i].mon3; a[i].dtb = DTB(a[i].mon1,a[i].mon2,a[i].mon2); } } void SapXep(ST a[],int n) { for(int i = 0 ; i < n - 1; i++) { for(int j = i + 1 ; j < n ; j++) { if(a[i].dtb > a[j].dtb) { ST t = a[i]; a[i]= a[j]; a[j] = t; } } } } int ViThu(ST a[],int n,int z) { int count = 0,temp[n],x=0; for(int i = 0 ; i < n ; i++) { if(i == 0) temp[x++] = a[i].dtb; if(i != 0) { for(int j = 0 ; j < x ; ++j) { if(a[i].dtb == temp[j]) count++; } if(count == 0) temp[x++] = a[i].dtb; else count = 0; } } for(int i = 0 ; i < x ; i++) { if(temp[i] == z) { return i + 1; break; } } } void Op_Array(ST a[], int n) { //cout<<"STT"<<"\t\t\t"<<"Ho va ten"<<"\t"<<"Diem mon 1"<<"\t"<<"Diem mon 2"<<"\t"<<"Diem mon 3"<<"\t"<<"Diem trung binh"<<"Vi Thu:"<<endl; for(int i = 0 ; i < n ; i++) { cout<<"-------------------------------"<<endl; cout<<"STT: "<<i+1<<endl; cout<<"Ho va Ten: "<<a[i].HoTen<<endl; cout<<"Diem mon 1: "<<a[i].mon1<<endl; cout<<"Diem mon 2: "<<a[i].mon2<<endl; cout<<"Diem mon 3: "<<a[i].mon3<<endl; cout<<"Diem Trung Binh: "<<a[i].dtb<<endl; cout<<"Vi Thu: "<<ViThu(a,n,a[i].dtb)<<endl; } } int main() { int n; cout<<"So luong sinh vien >= 1000 : "; cin>>n; ST a[n]; cin.ignore(); while(n >= 100) { cout<<"Moi ban nhap lai "<<endl; cout<<"So luong: "; cin>>n; } Inp_Array(a,n); Op_Array(a,n); return 0; }

Cùng tham gia bình luận bài viết này nhé!