Bai 1 + Bai 2 C++
#include<iostream> #include<conio.h> #include<string.h> #include<stdio.h> using namespace std; class ThiSinh{ private: char Maso[12], Hoten[32], KetQua[12]; float PointLT, PointTH, PointTB; public: ThiSinh(); char* getMaso(){ return Maso; } char* getHoten(){ return Hoten; } char* getKetQua(){ return KetQua; } float getPointLT(){ return PointLT; } float getPointTH(){ return PointTH; } float getPointTB(){ return PointTB; } void Nhap(); void Xuat(); float TinhTB(); void XepLoai(); }; class Array_ThiSinh{ private: ThiSinh arr[100]; int n; public: void Nhap(); void Arr_Xuat(); void LietKe_PointTH_PointLT_Tren_7(); float PointTBC_List(); void Search_Code(); void XapXepTenTangDan(); }; int main(){ Array_ThiSinh arr_ts; cout<<"Nhap Thong Tin Cho Cac Thi Sinh"<<endl; arr_ts.Nhap(); cout<<"======================================="<<endl; cout<<"Xuat Thong Tin Thi Sinh Da Nhap"<<endl; arr_ts.Arr_Xuat(); cout<<"======================================="<<endl; cout<<"Thi Sinh Co Diem TH Va LT Lon Hon 7"<<endl; arr_ts.LietKe_PointTH_PointLT_Tren_7(); cout<<"======================================="<<endl; cout<<"Point TBC Of List"<<endl; cout<<"Result = "<<arr_ts.PointTBC_List(); cout<<"\n\n======================================="<<endl; cout<<"Tim Thi Sinh Bang Ma So\n"<<endl; arr_ts.Search_Code(); cout<<"\n\n======================================="<<endl; cout<<"Xap Xep Ten Tang Dan"<<endl; arr_ts.XapXepTenTangDan(); arr_ts.Arr_Xuat(); _getch(); return 0; } ThiSinh::ThiSinh(){ PointLT = PointTB = PointTH = 0; strcpy(Maso,""); strcpy(Hoten,""); strcpy(KetQua,""); } void ThiSinh::Nhap(){ cin.ignore(); cout<<"Nhap Ten Thi Sinh: "; gets(Hoten); fflush(stdin); cout<<"Nhap Ma So Thi Sinh: "; gets(Maso); fflush(stdin); cout<<"Nhap Diem Ly Thuyet: "; cin>>PointLT; cout<<"Nhap Diem Thuc Hanh: "; cin>>PointTH; } float ThiSinh::TinhTB(){ PointTB = (PointLT + PointTH*2) / 3; return PointTB; } void ThiSinh::Xuat(){ cout<<"Ten: \t\t" << getHoten()<<endl; cout<<"Maso: \t\t"<<getMaso()<<endl; cout<<"PointLT= \t"<<getPointLT()<<endl; cout<<"PointTH= \t"<<getPointTH()<<endl; cout<<"PointTB= \t"<<getPointTB()<<endl; cout<<"Xep Loai: \t"<<getKetQua()<<endl; } void ThiSinh::XepLoai(){ if(getPointTB() >= 5) strcpy(KetQua,"DAT"); else strcpy(KetQua,"KHONG DAT"); } //---------------------------------------------------------- void Array_ThiSinh::Nhap(){ cout<<"Nhap So Luong Phan Tu: "; cin>>n; for(int i=0; i<n; i++){ cout<<"Nhap Thi Sinh Thu "<<i+1<<endl; arr[i].Nhap(); arr[i].TinhTB(); arr[i].XepLoai(); cout<<"\n"; } } void Array_ThiSinh::Arr_Xuat(){ for(int i=0; i<n; i++){ cout<<"Thi Sinh Thu: "<<i+1<<endl; arr[i].Xuat(); cout<<"\n"; } } void Array_ThiSinh::LietKe_PointTH_PointLT_Tren_7(){ for(int i=0; i<n; i++){ if(arr[i].getPointLT() > 7 && arr[i].getPointTH() >7) arr[i].Xuat(); cout<<"\n"; } } float Array_ThiSinh::PointTBC_List(){ float TB; for(int i=0; i<n; i++){ TB+= arr[i].getPointTB(); } return TB; } void Array_ThiSinh::Search_Code(){ char x[12]; bool a = true; cout<<("Nhap Ma So Can Tim: "); fflush(stdin); gets(x); for(int i=0; i<n; i++){ if(strcmp(arr[i].getMaso(),x) == 0){ cout<<"\nDa Tim Thay ["<<x<<"]"<<endl; arr[i].Xuat(); } //else a = false; } //if(a == false) cout<<"Khong Tim Thay ["<<x<<"]"<<endl; } void Array_ThiSinh::XapXepTenTangDan(){ ThiSinh t; for(int i=0;i<n-1;i++){ for(int j=i+1; j<n;j++){ if(strcmp(arr[i].getHoten(),arr[j].getHoten()) > 0){ t= arr[i]; arr[i]= arr[j]; arr[j]= t; } } } }
Bai 1
#include <conio.h> #include <stdio.h> #include <math.h> #include <iomanip> #include <iostream> using namespace std; class SoPhuc { private: float Thuc, Ao; public: SoPhuc(); // Constructor mac dinh SoPhuc(float R,float I); SoPhuc (const SoPhuc & Z); // Constructor sao chep SoPhuc (float R); // Constructor chuyen doi void Nhap(); //Nhap so phuc void Xuat(); // Hien thi so phuc //float getThuc(); //float getAo(); //void setThuc(int t); //void setAo(int a); // Cac tinh toan SoPhuc operator + (SoPhuc Z); //SoPhuc operator - (SoPhuc Z); //SoPhuc operator * (SoPhuc Z); //SoPhuc operator / (SoPhuc Z); //Ham tinh toan SoPhuc Cong(SoPhuc Z); //SoPhuc Tru(SoPhuc Z); //SoPhuc Nhan(SoPhuc Z); //SoPhuc Chia(SoPhuc Z); //int LonHon(SoPhuc Z); //int NhoHon(SoPhuc Z); //int Bang(SoPhuc Z); // Cac tinh toan so sanh ////int operator == (SoPhuc Z); //int operator != (SoPhuc Z); //int operator > (SoPhuc Z); //int operator >= (SoPhuc Z); //int operator < (SoPhuc Z); //int operator <= (SoPhuc Z); float Module(); // Giá tri tuyet doi cua so phuc //Cac ham kiem tra //int ThuanAo(); //int ThuanThuc(); }; class MangSoPhuc { private: SoPhuc a[100]; int n; public: void Nhap(); void Xuat(); //..cac phuong thuc cn lai }; int main() { MangSoPhuc x; //Nhap danh sach cout<<"Nhap thong tin cac So phuc trong Mang: "; x.Nhap(); cout<<"Thong tin cac So phuc trong Mang: "; x.Xuat(); //..Them code getch(); return 1; } SoPhuc::SoPhuc() { Thuc = 0.0; Ao = 0.0; } SoPhuc::SoPhuc(float R,float I) { Thuc = R; Ao = I; } SoPhuc::SoPhuc(const SoPhuc & Z) //Ham dung sao chep { Thuc = Z.Thuc; Ao = Z.Ao; } SoPhuc::SoPhuc(float R) { Thuc = R; Ao = 0.0; } void SoPhuc::Nhap() { cout<<"\n Nhap phan thuc "; cin>>Thuc; cout<<"\n Nhap phan ao "; cin>>Ao; } void SoPhuc::Xuat() { cout<<"(" << Thuc << " + " << Ao << "i)"; } /* Cho hai so phuc z = a + bi và w = c + di. Phep Cong: z+w = (a +c) + (b+d)i Phep Tru: z-w = (a +c) - (b+d)i Phep Nhan: z.w = (a * c - b * d) + (a * d + b * c)i Phep Chia: z/w = [(a * c + b * d) / (c * c + d * d)] + (b * c - a * d)i */ SoPhuc SoPhuc::Cong(SoPhuc Z) { SoPhuc Tmp; Tmp.Thuc = Thuc + Z.Thuc; Tmp.Ao = Ao + Z.Ao; return Tmp; } float SoPhuc::Module() { return sqrt(Thuc*Thuc+Ao*Ao); } //CAC PHUONG THUC THUOC LOP MangSoPhuc void MangSoPhuc::Nhap() { cout <<"\n Nhap n : "; cin >> n; for (int i=0;i<n;i++) { cout<<"Nhap a["<<i<<"]: "; a[i].Nhap(); } } void MangSoPhuc::Xuat() { for (int i=0;i<n;i++) { a[i].Xuat(); cout << " "; } }
No Comment to " Bai 1 + Bai 2 C++ "