[ create a new paste ] login | about

Link: http://codepad.org/TRS40LFk    [ raw code | output | fork ]

C, pasted on Sep 9:
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
/*
Viết chương trình nhập vào thông tin sinh viên , biết rằng sinh viên gồm các thông tin:
Mã số :
Họ tên:
Danh sách các môn học trong học kỳ đó kèm theo số tín chỉ tương ứng 

=> yêu cầu: tính điểm trung bình và xếp loại sinh viên theo quy tắc



*/

struct monhoc
{
	char tenmon[30];
	float sodiem;
	int sochi;
};
typedef struct monhoc MONHOC; // thay vì gọi struct monhoc => rút gọn lại thành MONHOC

struct danhsachmonhoc
{
	int n;
	MONHOC *arr;
};
typedef struct danhsachmonhoc DANHSACHMONHOC;

void nhapmonhoc(MONHOC &mh)
{
	
	printf("\nNhap vao ten mon hoc: ");
	fflush(stdin); // xóa bộ nhớ đệm
	gets_s(mh.tenmon);

	do
	{
		printf("\nNhap vao so diem: ");
		scanf("%f", &mh.sodiem);

		if (mh.sodiem < 0 || mh.sodiem > 10)
		{
			printf("\nXin vui long nhap so diem phu hop!");
		}
	} while (mh.sodiem < 0 || mh.sodiem > 10);

	do {
		printf("\nNhap vao so tin chi: ");
		scanf("%d", &mh.sochi);

		if (mh.sochi < 0)
		{
			printf("\nXin vui long nhap lai so tin chi phu hop!");
		}	
	} while (mh.sochi < 0);
}

void xuatmon(MONHOC mh)
{
	printf("\nTen mon hoc: %s", mh.tenmon);
	printf("\nDiem thi: %.1f", mh.sodiem);
	printf("\nSo tin chi: %d", mh.sochi);
}

void nhapdanhsachmonhoc(DANHSACHMONHOC &ds)
{
	do {
		printf("\nNhap so luong mon hoc: ");
		scanf("%d", &ds.n);

		if (ds.n < 0)
		{
			printf("\nXin vui long nhap so mon hoc phu hop");
		}
	} while (ds.n < 0);
	ds.arr = (MONHOC *)malloc(ds.n * sizeof(MONHOC));
	for (int i = 0; i < ds.n; i++)
	{
		printf("\n------------ Nhap vao mon hoc thu %d ---------------\n", i + 1);
		nhapmonhoc(ds.arr[i]);
	}
}

void xuatdanhsachmonhoc(DANHSACHMONHOC ds)
{
	for (int i = 0; i < ds.n; i++)
	{
		printf("\n------------ Mon hoc thu %d ---------------\n", i + 1);
		xuatmon(ds.arr[i]);
	}
}

int main()
{
	DANHSACHMONHOC ds;
	nhapdanhsachmonhoc(ds);
	xuatdanhsachmonhoc(ds);
	
	free(ds.arr);
	_getch();
	return 0;
}


Output:
1
2
3
4
5
Line 18: error: conio.h: No such file or directory
Line 31: error: expected ';', ',' or ')' before '&' token
Line 67: error: expected ';', ',' or ')' before '&' token
In function 'xuatdanhsachmonhoc':
Line 88: error: 'for' loop initial declaration used outside C99 mode


Create a new paste based on this one


Comments: