1. Trang chủ
  2. » Giáo Dục - Đào Tạo

LẬP TRÌNH NÂNG CAO LÝ THUYẾT TRÒ CHƠI

4 65 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 4
Dung lượng 13,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Trang 1

#include<conio.h>

#include<stdio.h>

class ts

{

char *ma,*ten;

float toan,ly,hoa;

public:

ts();

~ts();

ts&operator=(ts &);

ts(const ts &);

friend ostream&operator<<(ostream &os,ts &); friend istream&operator>>(istream &is,ts &); float tong();

};

ts::ts()

{

ma=new char[10];

ten=new char[25];

toan=0;

ly=0;

hoa=0;

};

ts::~ts()

{

delete ma;

Trang 2

delete ten;

toan=0;

ly=0;

hoa=0;

};

ts&ts::operator=(ts &t)

{

ma=new char[10];

ten=new char[25];

strcpy(ma,t.ma);

strcpy(ten,t.ten);

toan=t.toan;

ly=t.ly;

hoa=t.hoa;

return t;

};

ts::ts(const ts &t)

{

ma=new char[10];

ten=new char[25];

strcpy(ma,t.ma);

strcpy(ten,t.ten);

toan=t.toan;

ly=t.ly;

hoa=t.hoa;

};

ostream&operator<<(ostream &os,ts &t) {

Trang 3

cout<<"\n ma thi sinh la "<<t.ma;

cout<<"\n ten thi sinh la "<<t.ten;

cout<<"\n diem toan la "<<t.toan;

cout<<"\n diem ly la "<<t.ly;

cout<<"\n diem hoa la "<<t.hoa;

return os;

};

istream&operator>>(istream &is,ts &t)

{

cout<<"\n nhap ma thi sinh ";cin>>t.ma; cout<<"\n nhap ten thi sinh ";cin>>t.ten; cout<<"\n nhap diem toan ";cin>>t.toan; cout<<"\n nhap diem ly ";cin>>t.ly;

cout<<"\n nhap diem hoa ";cin>>t.hoa; return is;

};

float ts::tong()

{

float temp;

temp=toan+ly+hoa;

return temp;

};

void nhap(ts *a,int k)

{

for(int i=0;i<k;i++)

{

cout<<"\n nhap thi sinh thu "<<i+1; cin>>a[i];

Trang 4

};

ts max(ts *a,int k)

{

ts temp;

temp=a[0];

for(int i=1;i<k;i++)

if(temp.tong()<a[i].tong())temp=a[i];

return temp;

};

int main()

{

ts *a;

int n;

cout<<"\n nhap so thi sinh ";

cin>>n;

a=new ts[n];

cout<<"\n nhap thong tin tung thi sinh ";

nhap(a,n);

//cout<<"\n sinh vien co diem cao nhat la "<<max(a,n); cout<<"\n danh sach thi sinh trung tuyen la ";

xuat(a,n,21);

getch();

};

Ngày đăng: 26/02/2019, 19:52

TỪ KHÓA LIÊN QUAN

w