1. THÔNG BÁO TUYỂN ADMIN DIỄN ĐÀN 2013
    Tìm kiếm nhà trọ - Ở ghép
    THÔNG BÁO BÁN ÁO SPKT.NET CHO THÀNH VIÊN DIỄN ĐÀN


    HÃY TÌM KIẾM Ở ĐÂY TRƯỚC KHI ĐẶT CÂU HỎI
    {xen:phrase loading}

bai tap c++

Thảo luận trong 'Tài liệu' bắt đầu bởi hai_lua, 19 Tháng sáu 2011.

  1. hai_lua New Member

    Số bài viết: 33
    Đã được thích: 0
    Điểm thành tích: 0
    [FONT=.VnArial Narrow]BAI 6 TRANG 110[/FONT]
    [FONT=.VnArial Narrow]#include <conio.h>[/FONT]
    [FONT=.VnArial Narrow]#include <iostream.h>[/FONT]
    [FONT=.VnArial Narrow]class canbo[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] char hoten[50];[/FONT]
    [FONT=.VnArial Narrow]protected:[/FONT]
    [FONT=.VnArial Narrow] int mcb, mdv, ngay, thang, nam; [/FONT]
    [FONT=.VnArial Narrow]public:[/FONT]
    [FONT=.VnArial Narrow] void nhap()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ho ten: ";[/FONT]
    [FONT=.VnArial Narrow] cin.get();[/FONT]
    [FONT=.VnArial Narrow] cin.get(hoten,50);[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cin.ignore(1);[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ma can bo: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>mcb;[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ma don vi: ";[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cin>>mdv;[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ngay thang nam sinh: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>ngay>>thang>>nam;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"ho ten: "<<hoten<<endl;[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cout<<"ma can bo: "<<mcb<<endl;[/FONT]
    [FONT=.VnArial Narrow] cout<<"ma don vi: "<<mdv<<endl;[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cout<<"ngay "<<ngay<<" "<<"thang "<<thang<<" "<<"nam "<<nam<<endl;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow]};[/FONT]
    [FONT=.VnArial Narrow]class luong:public canbo[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] float hesoluong, phucap, baohiem;[/FONT]
    [FONT=.VnArial Narrow] float tienluong;[/FONT]
    [FONT=.VnArial Narrow] public:[/FONT]
    [FONT=.VnArial Narrow] void nhapluong_cb()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap he so luong: ";cin>>hesoluong;[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cout<<"nhap tien phu cap: ";cin>>phucap;[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]cout<<"nhap tien bao hiem: ";cin>>baohiem;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] float tinhluong()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] return(hesoluong*290000+phucap-baohiem);[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi_cb()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] hienthi();[/FONT]
    [FONT=.VnArial Narrow] cout<<"tien luong: "<<tinhluong()<<endl;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] [/FONT]
    [FONT=.VnArial Narrow]};[/FONT]
    [FONT=.VnArial Narrow]void main()[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow]luong cb[30];[/FONT]
    [FONT=.VnArial Narrow]int i,n;[/FONT]
    [FONT=.VnArial Narrow]cout<<"nhap so can bo: ";[/FONT]
    [FONT=.VnArial Narrow]cin>>n;[/FONT]
    [FONT=.VnArial Narrow]for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] cb.nhap();[/FONT]
    [FONT=.VnArial Narrow]cb.nhapluong_cb();[/FONT]
    [FONT=.VnArial Narrow]}[/FONT]
    [FONT=.VnArial Narrow]cout<<"************danh sach can bo************\n";[/FONT]
    [FONT=.VnArial Narrow]for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] cout<<"\n";[/FONT]
    [FONT=.VnArial Narrow]cb.hienthi_cb();[/FONT]
    [FONT=.VnArial Narrow]}[/FONT]
    [FONT=.VnArial Narrow] getch();[/FONT]
    [FONT=.VnArial Narrow]}[/FONT]
    [FONT=.VnArial Narrow]BAI 10 TRANG 111[/FONT]
    [FONT=.VnArial Narrow] [/FONT]
    [FONT=.VnArial Narrow]#include<conio.h>[/FONT]
    [FONT=.VnArial Narrow]#include<iostream.h>[/FONT]
    [FONT=.VnArial Narrow]class nguoi[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] [/FONT]
    [FONT=.VnArial Narrow]protected:[/FONT]
    [FONT=.VnArial Narrow] char hoten[50];[/FONT]
    [FONT=.VnArial Narrow] char ht[50];[/FONT]
    [FONT=.VnArial Narrow] int ngay, thang ,nam;[/FONT]
    [FONT=.VnArial Narrow]public:[/FONT]
    [FONT=.VnArial Narrow] void nhap_giaovien()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ho ten giao vien: ";[/FONT]
    [FONT=.VnArial Narrow] cin.get();[/FONT]
    [FONT=.VnArial Narrow] cin.get(hoten,50);[/FONT]
    [FONT=.VnArial Narrow] cin.ignore(1);[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ngay thang nam sinh: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>ngay>>thang>>nam;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi_giaovien()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"ho va ten giao vien: "<<hoten<<endl;[/FONT]
    [FONT=.VnArial Narrow] cout<<"ngay "<<ngay<<" "<<"thang "<<thang<<" "<<"nam "<<nam<<endl;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void nhap_hocsinh()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ho ten hoc sinh: ";[/FONT]
    [FONT=.VnArial Narrow] cin.get();[/FONT]
    [FONT=.VnArial Narrow] cin.get(ht,50);[/FONT]
    [FONT=.VnArial Narrow] cin.ignore(1);[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap ngay thang nam sinh: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>ngay>>thang>>nam;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi_hocsinh()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"ho va ten hoc sinh: "<<ht<<endl;[/FONT]
    [FONT=.VnArial Narrow] cout<<"ngay "<<ngay<<" "<<"thang "<<thang<<" "<<"nam "<<nam<<endl;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow]};[/FONT]
    [FONT=.VnArial Narrow]class giaovien: public nguoi[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] char bomon[50];[/FONT]
    [FONT=.VnArial Narrow] int sobai;[/FONT]
    [FONT=.VnArial Narrow]public:[/FONT]
    [FONT=.VnArial Narrow] void nhap_bm()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] nhap_giaovien();[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap bo mon: ";[/FONT]
    [FONT=.VnArial Narrow] cin.get();[/FONT]
    [FONT=.VnArial Narrow] cin.get(bomon,50);[/FONT]
    [FONT=.VnArial Narrow] cin.ignore(1);[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap so bai dang ki: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>sobai;[/FONT]
    [FONT=.VnArial Narrow] } [/FONT]
    [FONT=.VnArial Narrow] void kiemtra()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] if (sobai==0)[/FONT]
    [FONT=.VnArial Narrow] cout<<" khong duoc khen thuong\n";[/FONT]
    [FONT=.VnArial Narrow] if(sobai>=1)[/FONT]
    [FONT=.VnArial Narrow] cout<<"duoc khen thuong\n";[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi_gv()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] hienthi_giaovien();[/FONT]
    [FONT=.VnArial Narrow] cout<<"bo mon: "<<bomon<<endl;[/FONT]
    [FONT=.VnArial Narrow] cout<<"so bai bao: "<<sobai<<endl;[/FONT]
    [FONT=.VnArial Narrow] kiemtra();[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow]};[/FONT]
    [FONT=.VnArial Narrow]class hocsinh: public nguoi[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] char lop[50];[/FONT]
    [FONT=.VnArial Narrow] float dtb;[/FONT]
    [FONT=.VnArial Narrow]public:[/FONT]
    [FONT=.VnArial Narrow] void nhap_lop()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] nhap_hocsinh();[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap lop hoc: ";[/FONT]
    [FONT=.VnArial Narrow] cin.get();[/FONT]
    [FONT=.VnArial Narrow] cin.get(lop,50);[/FONT]
    [FONT=.VnArial Narrow] cin.ignore(1);[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap diem trung binh: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>dtb;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void kt()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] if (dtb<=8)[/FONT]
    [FONT=.VnArial Narrow] cout<<" khong duoc khen thuong\n";[/FONT]
    [FONT=.VnArial Narrow] if(dtb>8)[/FONT]
    [FONT=.VnArial Narrow] cout<<"duoc khen thuong\n";[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] void hienthi_hs()[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] hienthi_hocsinh();[/FONT]
    [FONT=.VnArial Narrow] cout<<"hoc lop: "<<lop<<endl;[/FONT]
    [FONT=.VnArial Narrow] cout<<"diem trung binh: "<<dtb<<endl;[/FONT]
    [FONT=.VnArial Narrow] kt();[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow]void main()[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] giaovien gv[30];[/FONT]
    [FONT=.VnArial Narrow] hocsinh hs[30];[/FONT]
    [FONT=.VnArial Narrow] int i,n,m,j;[/FONT]
    [FONT=.VnArial Narrow] do [/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] cout<<"nhap so giao vien: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>n;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] while(n <0 || n>30);[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] { cout<<"\n";[/FONT]
    [FONT=.VnArial Narrow] gv.nhap_bm();}[/FONT]
    [FONT=.VnArial Narrow] cout<<"**************danh sach giao vien*************\n";[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] { cout<<"\n"<<endl; [/FONT]
    [FONT=.VnArial Narrow] gv.hienthi_gv();}[/FONT]
    [FONT=.VnArial Narrow] do[/FONT]
    [FONT=.VnArial Narrow] {cout<<"nhap so sinh vien: ";[/FONT]
    [FONT=.VnArial Narrow] cin>>m;}[/FONT]
    [FONT=.VnArial Narrow] while(m<0||m>100);[/FONT]
    [FONT=.VnArial Narrow] for(j=0;j<m;j++)[/FONT]
    [FONT=.VnArial Narrow] {cout<<"\n";[/FONT]
    [FONT=.VnArial Narrow] hs[j].nhap_lop();}[/FONT]
    [FONT=.VnArial Narrow] cout<<"**************danh sach giao vien*************\n";[/FONT]
    [FONT=.VnArial Narrow] for(j=0;j<m;j++)[/FONT]
    [FONT=.VnArial Narrow] { cout<<"\n"<<endl; [/FONT]
    [FONT=.VnArial Narrow] hs[j].hienthi_hs();}[/FONT]
    [FONT=.VnArial Narrow] getch();[/FONT]
    [FONT=.VnArial Narrow]}[/FONT][FONT=.VnArial Narrow][/FONT]
    [FONT=.VnArial Narrow]CAU TRUC DU LIEU TU TAO[/FONT]
    [FONT=.VnArial Narrow]#include<stdio.h>[/FONT]
    [FONT=.VnArial Narrow]#include<conio.h>[/FONT]
    [FONT=.VnArial Narrow]#include<stdlib.h>[/FONT]
    [FONT=.VnArial Narrow]#include<string.h>[/FONT]
    [FONT=.VnArial Narrow]#include<ctype.h>[/FONT]
    [FONT=.VnArial Narrow]void main()[/FONT]
    [FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] struct sinhvien[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] int ms,t,l;float tb;[/FONT]
    [FONT=.VnArial Narrow] char hoten[50];[/FONT]
    [FONT=.VnArial Narrow] };[/FONT]
    [FONT=.VnArial Narrow] sinhvien sv[5];[/FONT]
    [FONT=.VnArial Narrow] char tam[50];[/FONT]
    [FONT=.VnArial Narrow] int i, n;[/FONT]
    [FONT=.VnArial Narrow] printf("nhap vao so sinh vien: ");[/FONT]
    [FONT=.VnArial Narrow] gets(tam);[/FONT]
    [FONT=.VnArial Narrow] n=atoi(tam);[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] printf("nhap sinh vien thu: %d\n",i+1);[/FONT]
    [FONT=.VnArial Narrow] printf("nhap MSSV: ");[/FONT]
    [FONT=.VnArial Narrow] gets(tam);[/FONT]
    [FONT=.VnArial Narrow] sv.ms=atoi(tam);[/FONT]
    [FONT=.VnArial Narrow] printf("nhap HO TEN: ");[/FONT]
    [FONT=.VnArial Narrow] gets(sv.hoten);[/FONT]
    [FONT=.VnArial Narrow] printf("nhap diem toan: ");[/FONT]
    [FONT=.VnArial Narrow] gets(tam);[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]sv.t=atoi(tam);[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]printf("nhap diem ly: ");[/FONT]
    [FONT=.VnArial Narrow] gets(tam);[/FONT]
    [FONT=.VnArial Narrow] sv.l=atoi(tam);[/FONT]
    [FONT=.VnArial Narrow] sv.tb=(float)(sv.t+sv.l)/2;[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] printf("**********DANH SACH SINH VIEN**********\n");[/FONT]
    [FONT=.VnArial Narrow] printf("MSSV HO TEN DIEM TOAN DIEM LY DIEM TB\n");[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] printf("%-4d %-6s %-9d %-7d %-6f\n",sv.ms,sv.hoten,sv.t,sv.l,sv.tb);[/FONT]
    [FONT=.VnArial Narrow] printf("\n\n");[/FONT]
    [FONT=.VnArial Narrow] printf("*********************************************************\n");[/FONT]
    [FONT=.VnArial Narrow] //in sinh vien diem toan cao nhat[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]{[/FONT]
    [FONT=.VnArial Narrow] int max;[/FONT]
    [FONT=.VnArial Narrow] max=sv[0].t;[/FONT]
    [FONT=.VnArial Narrow]for(i=1;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(max<sv.t)[/FONT]
    [FONT=.VnArial Narrow] max=sv.t;[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(sv.t==max)[/FONT]
    [FONT=.VnArial Narrow] printf("sinh vien: %s co diem toan cao nhat\n voi so diem:%d\n ",sv.hoten,max);[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] [/FONT]
    [FONT=.VnArial Narrow] printf("\n\n");[/FONT]
    [FONT=.VnArial Narrow] printf("*********************************************************\n");[/FONT]
    [FONT=.VnArial Narrow] // sinh vien rot 2 mon[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] int k =1;[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(sv.t<5 && sv.l<5)[/FONT]
    [FONT=.VnArial Narrow] k=1;[/FONT]
    [FONT=.VnArial Narrow] else[/FONT]
    [FONT=.VnArial Narrow] k=0;[/FONT]
    [FONT=.VnArial Narrow] if(k==1)[/FONT]
    [FONT=.VnArial Narrow] printf("sinh vien: %s rot 2 mon\n",sv.hoten);[/FONT]
    [FONT=.VnArial Narrow] else[/FONT]
    [FONT=.VnArial Narrow] printf("khong co sinh vien nao thi rot");[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] printf("\n\n");[/FONT]
    [FONT=.VnArial Narrow] printf("*********************************************************\n");[/FONT]
    [FONT=.VnArial Narrow] //in sinh vien co diem tb cao nhat[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] float max;[/FONT]
    [FONT=.VnArial Narrow] max=sv[0].tb;[/FONT]
    [FONT=.VnArial Narrow] for(i=1;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(max<sv.tb)[/FONT]
    [FONT=.VnArial Narrow] max=sv.tb;[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(sv.tb==max)[/FONT]
    [FONT=.VnArial Narrow] printf("sinh vien: %s co diem tb cao nhat.\n voi so diem:%f\n ",sv.hoten,max);[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]}[/FONT]
    [FONT=.VnArial Narrow] /* cach 2[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] sinhvien max;[/FONT]
    [FONT=.VnArial Narrow] max=sv[0];[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow]for(i=1;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(max.tb<sv.tb)[/FONT]
    [FONT=.VnArial Narrow] max=sv;[/FONT]
    [FONT=.VnArial Narrow] printf("sinh vien: %s co diem trung binh cao nhat\n voi so diem:%f\n ",max.hoten,max.tb);[/FONT]
    [FONT=.VnArial Narrow] }*/[/FONT]
    [FONT=.VnArial Narrow] printf("\n\n");[/FONT]
    [FONT=.VnArial Narrow] printf("*********************************************************\n");[/FONT]
    [FONT=.VnArial Narrow] //tim sinh vien theo ma so[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] int x;int l=1;[/FONT]
    [FONT=.VnArial Narrow] printf("ban hay nhap vao mssvn can tim: ");[/FONT]
    [FONT=.VnArial Narrow] gets(tam);[/FONT]
    [FONT=.VnArial Narrow] x=atoi(tam);[/FONT]
    [FONT=.VnArial Narrow] for(i=0;i<n;i++)[/FONT]
    [FONT=.VnArial Narrow] if(sv.ms==x)[/FONT]
    [FONT=.VnArial Narrow] l=1;[/FONT]
    [FONT=.VnArial Narrow] else[/FONT]
    [FONT=.VnArial Narrow] l=0;[/FONT]
    [FONT=.VnArial Narrow] if(l==1)[/FONT]
    [FONT=.VnArial Narrow] {[/FONT]
    [FONT=.VnArial Narrow] printf("MSSV HO TEN DIEM TOAN DIEM LY DIEM TB\n");[/FONT]
    [FONT=.VnArial Narrow] printf("%-4d %-6s %-9d %-7d %-6f\n",sv.ms,sv.hoten,sv.t,sv.l,sv.tb);[/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] else[/FONT]
    [FONT=.VnArial Narrow] printf("khong tim thay sinh vien can tim\n"); [/FONT]
    [FONT=.VnArial Narrow] [/FONT]
    [FONT=.VnArial Narrow] }[/FONT]
    [FONT=.VnArial Narrow] [/FONT][FONT=.VnArial Narrow] getch();[/FONT]
    [FONT=.VnArial Narrow]}[/FONT]
    [FONT=.VnArial Narrow]anh em tham khao cho nao sai ,sua roi post len nha\:D/:))(*)[/FONT]
  2. phonggiahuy Member

    Số bài viết: 47
    Đã được thích: 0
    Điểm thành tích: 6
  3. phonggiahuy Member

    Số bài viết: 47
    Đã được thích: 0
    Điểm thành tích: 6
    Chỉnh sửa lại vài chổ. AE tham khảo


    BAI 6 TRANG 110
    #include <conio.h>
    #include <iostream.h>
    class canbo
    {
    protected:
    char hoten[50];
    int mcb, mdv, ngay, thang, nam;
    public:
    void nhap()
    {
    cout<<"nhap ho ten: ";
    cin.get();
    cin.get(hoten,50);
    cin.ignore(1);
    cout<<"nhap ma can bo: ";
    cin>>mcb;
    cout<<"nhap ma don vi: ";
    cin>>mdv;
    cout<<"nhap ngay thang nam sinh: ";
    cin>>ngay>>thang>>nam;
    }
    void hienthi()
    {
    cout<<"ho ten: "<<hoten<<endl;
    cout<<"ma can bo: "<<mcb<<endl;
    cout<<"ma don vi: "<<mdv<<endl;
    cout<<"ngay "<<ngay<<" "<<"thang "
    <<thang<<" "<<"nam "<<nam<<endl;
    }
    };
    class luong :public canbo
    {
    float hesoluong, phucap, baohiem;
    float tienluong;
    public:
    void nhapluong_cb()
    {
    cout<<"nhap he so luong: ";cin>>hesoluong;
    cout<<"nhap tien phu cap: ";cin>>phucap;
    cout<<"nhap tien bao hiem: ";cin>>baohiem;
    }
    float tinhluong()
    {
    return(hesoluong*290000+phucap-baohiem);
    }
    void hienthi_cb()
    {
    hienthi();
    cout<<"tien luong: "<<tinhluong()<<endl;
    }
    };
    void main()
    {
    canbo cb[30];
    int i,j,tam,n;
    cout<<"nhap so can bo: ";
    cin>>n;
    for(i=0;i<n;i++)
    {
    cb.nhap();
    cb.nhapluong_cb();
    }
    cout<<"Danh sach can bo theo don vi\n";
    for(i=0;i<n-1;i++)
    for(j=i+1;j<n;j++)
    if(cb.mdv>cb[j].mdv)
    {tam=cb;
    cb=cb[j];
    cb[j]=tam;
    }
    for(i=0;i<n;i++)
    {
    cout<<"\n";
    cb.hienthi_cb();
    }
    getch();
    }









    //TIME
    #include <conio.h>
    #include <iostream.h>
    {private:
    int h,m,s;
    public:
    time (){};
    time (int h1,m1,s1)
    {h=h1;m=m1;s=s1;
    }
    void nhap()
    {
    cout<<"hh:mm:ss\n";
    cin>>h>>m>>s;
    }
    void chuanhoa()
    {
    if (s>=60)
    { s=s%60;
    m=m+(s/60);
    }
    if (m>=60)
    { m=m%60;
    h=h+(s/60);
    }
    if (h>=24)
    cout<<"nhap lai tgian";
    }
    void hienthi()
    {
    cout<<"hh:mm:ss"<<h<<m<<s<<endl;

    }
    }
















    BAI 10 TRANG 111

    #include<conio.h>
    #include<iostream.h>
    class nguoi
    {
    protected:
    char hoten[50];
    char ht[50];
    int ngay, thang ,nam;
    public:
    void nhap_giaovien()
    {
    cout<<"nhap ho ten giao vien: ";
    cin.get();
    cin.get(hoten,50);
    cin.ignore(1);
    cout<<"nhap ngay thang nam sinh: ";
    cin>>ngay>>thang>>nam;
    }
    void hienthi_giaovien()
    {
    cout<<"ho va ten giao vien: "<<hoten<<endl;
    cout<<"ngay "<<ngay<<" "<<"thang "
    <<thang<<" "<<"nam "<<nam<<endl;
    }
    void nhap_sinhvien()
    {
    cout<<"nhap ho ten sinhvien: ";
    cin.get();
    cin.get(ht,50);
    cin.ignore(1);
    cout<<"nhap ngay thang nam sinh: ";
    cin>>ngay>>thang>>nam;
    }
    void hienthi_ sinhvien ()
    {
    cout<<"ho va ten hoc sinh: "<<ht<<endl;
    cout<<"ngay "<<ngay<<" "<<"thang "
    <<thang<<" "<<"nam "<<nam<<endl;
    }
    };
    class giaovien: public nguoi
    {
    char bomon[50];
    int sobai;
    public:
    void nhap_bm()
    {
    nhap_giaovien();
    cout<<"nhap bo mon: ";
    cin.get();
    cin.get(bomon,50);
    cin.ignore(1);
    cout<<"nhap so bai dang ki: ";
    cin>>sobai;
    }
    void kiemtra_giaovien()
    {

    if(sobai>0)
    return(1);
    else
    return(0);
    }
    void hienthi_gv()
    {
    hienthi_giaovien();
    cout<<"bo mon: "<<bomon<<endl;
    cout<<"so bai bao: "<<sobai<<endl;
    kiemtra();
    }
    };
    class sinhvien: public nguoi
    {
    char lop[50];
    float dtb;
    public:
    void nhap_lop()
    {
    nhap_sinhvien();
    cout<<"nhap lop hoc: ";
    cin.get();
    cin.get(lop,50);
    cin.ignore(1);
    cout<<"nhap diem trung binh: ";
    cin>>dtb;
    }
    void kiemtra_sinhvien()
    {
    if(dtb>8)
    return(1);
    else
    return(0);
    }
    void hienthi_sv()
    {
    hienthi_sinhvien();
    cout<<"hoc lop: "<<lop<<endl;
    cout<<"diem trung binh: "<<dtb<<endl;
    kiemtra_ sinhvien ();
    }
    void main()
    {
    giaovien gv[30];
    hocsinh sv[30];
    int i,n,m,j;
    do
    {
    cout<<"nhap so giao vien: ";
    cin>>n;
    }
    while(n <0 || n>30);
    for(i=0;i<n;i++)
    { cout<<"\n";
    gv.nhap_bm();}
    cout<<"DS Giao Vien khen thuong\n";
    for(i=0;i<n;i++)
    { cout<<"\n"<<endl;
    gv.hienthi_gv();}
    do
    {cout<<"nhap so sinh vien: ";
    cin>>m;}
    while(m<0||m>100);
    for(j=0;j<m;j++)
    {cout<<"\n";
    sv[j].nhap_lop();}
    cout<<"DS Sinh Vien khen thuong\n";
    for(j=0;j<m;j++)
    { cout<<"\n"<<endl;
    sv[j].hienthi_sv();}
    getch();
    }


    CAU TRUC DU LIEU TU TAO
    #include<stdio.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<ctype.h>
    void main()
    {
    struct sinhvien
    {
    int ms,t,l;float tb;
    char hoten[50];
    };
    sinhvien sv[5];
    char tam[50];
    int i, n;
    printf("nhap vao so sinh vien: ");
    gets(tam);
    n=atoi(tam);
    for(i=0;i<n;i++)
    {
    printf("nhap sinh vien thu: %d\n",i+1);
    printf("nhap MSSV: ");
    gets(tam);
    sv.ms=atoi(tam);
    printf("nhap HO TEN: ");
    gets(sv.hoten);
    printf("nhap diem toan: ");
    gets(tam);
    sv.t=atoi(tam);
    printf("nhap diem ly: ");
    gets(tam);
    sv.l=atoi(tam);
    sv.tb=(float)(sv.t+sv.l)/2;
    }
    printf("**********DANH SACH SINH VIEN**********\n");
    printf("MSSV HO TEN DIEM TOAN DIEM LY DIEM TB\n");
    for(i=0;i<n;i++)
    printf("%-4d %-6s %-9d %-7d %-6f\n",sv.ms,sv.hoten,sv.t,sv.l,sv.tb);
    printf("\n\n");
    printf("****************************************** ***************\n");
    //in sinh vien diem toan cao nhat
    {
    int max;
    max=sv[0].t;
    for(i=1;i<n;i++)
    if(max<sv.t)
    max=sv.t;
    for(i=0;i<n;i++)
    if(sv.t==max)
    printf("sinh vien: %s co diem toan cao nhat\n voi so diem:%d\n ",sv.hoten,max);
    }

    printf("\n\n");
    printf("****************************************** ***************\n");
    // sinh vien rot 2 mon
    {
    int k =1;
    for(i=0;i<n;i++)
    if(sv.t<5 && sv.l<5)
    k=1;
    else
    k=0;
    if(k==1)
    printf("sinh vien: %s rot 2 mon\n",sv.hoten);
    else
    printf("khong co sinh vien nao thi rot");
    }
    printf("\n\n");
    printf("****************************************** ***************\n");
    //in sinh vien co diem tb cao nhat
    {
    float max;
    max=sv[0].tb;
    for(i=1;i<n;i++)
    if(max<sv.tb)
    max=sv.tb;
    for(i=0;i<n;i++)
    if(sv.tb==max)
    printf("sinh vien: %s co diem tb cao nhat.\n voi so diem:%f\n ",sv.hoten,max);
    }
    /* cach 2
    {
    sinhvien max;
    max=sv[0];
    for(i=1;i<n;i++)
    if(max.tb<sv.tb)
    max=sv;
    printf("sinh vien: %s co diem trung binh cao nhat\n voi so diem:%f\n ",max.hoten,max.tb);
    }*/
    printf("\n\n");
    printf("****************************************** ***************\n");
    //tim sinh vien theo ma so
    {
    int x;int l=1;
    printf("ban hay nhap vao mssvn can tim: ");
    gets(tam);
    x=atoi(tam);
    for(i=0;i<n;i++)
    if(sv.ms==x)
    l=1;
    else
    l=0;
    if(l==1)
    {
    printf("MSSV HO TEN DIEM TOAN DIEM LY DIEM TB\n");
    printf("%-4d %-6s %-9d %-7d %-6f\n",sv.ms,sv.hoten,sv.t,sv.l,sv.tb);
    }
    else
    printf("khong tim thay sinh vien can tim\n");
    }
    getch();
    }

Chia sẻ trang này