Câu 1 +2

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Câu 1

#include<stdio.h>

#include<string.h>

#include<iostream>

using namespace std;

struct hocsinh

char hoten[25], lop[10];

float toan,van, dtb ;

};

void NHAP_HS(struct hocsinh hs[] , int n )

for(int i=1; i<=5; i++){

cout<<"hoc sinh thu "<< i;

cout<<" ho ten " ;

fflush(stdin);

gets(hs[i].hoten);

cout<<"nhap diem toan : ";

cin>>hs[i].toan;

cout<<"nhap diem van : ";

cin>>hs[i].van;

void XUAT_HS(struct hocsinh hs[] , int n)

{
for(int i=1; i<=5; i++)

cout<<"hoc sinh ten " << hs[i].hoten<<endl;

cout<<"diem toan : " << hs[i].toan <<endl;

cout<<"diem van : "<< hs[i].van<<endl;

if(hs[i].toan <= 10 && hs[i].van<=10)

cout<<"diem TB "<< (float)(hs[i].toan + hs[i].van)/2 <<endl;

else

cout<<"diem hoc sinh khong hop le ten " << hs[i].hoten;

int main ()

hocsinh ds[150];

int a;

cout <<"nhap thong tin hoc sinh"<<endl;

NHAP_HS(ds, a);

cout <<endl;

cout <<" thong tinh hoc sinh sau khi tinh diem "<<endl;

XUAT_HS(ds, a);

return 0;

}
Câu 2
#include <iostream>

#include <iomanip>

using namespace std;

class hocsinh

private:

string hovaten;

string maso;

float toan;

float van;

float dtb;

public:

void nhap();

void xuat();

float tinh();

};

void hocsinh::nhap()

cout<<"ho va ten hoc sinh: "; fflush(stdin); getline(cin,hovaten);

cout<<"ma hs "; fflush(stdin); cin>>maso;

cout<<"diem toan: "; fflush(stdin); cin>>toan;

cout<<"diem van: "; fflush(stdin); cin>>van;

void hocsinh::xuat()

cout<<"ho va ten sv "<< hovaten<<endl;


cout<<"ma hs "<< maso<< endl;

cout<<"diem toan "<< toan <<endl;

cout<<"diem van "<< van <<endl;

cout<<"tb "<< dtb <<endl;

float hocsinh::tinh()

dtb=(float)(toan+van)/2;

return (dtb);

int main()

hocsinh hs[100];

int n;

int i=0;

cout<<"nhap so hoc sinh cua lop"; cin>>n;

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

hs[i].nhap();

hs[i].tinh();

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

hs[i].xuat();

system("pause");

return(0);

You might also like