Xem sửa hộ đoạn code

Mọi ng xem sửa hộ đoạn code này vs ạ em cảm ơn ạ!

struct sinhvien
{
   char maso[7];
   char name[30];
   char quequan[30];
   float tongdiem;
   	
};
void nhap_ds(sinhvien sv[],int n)
{
	for(int i=0;i<n;i++)
	{
		cout<<"nhap thong tin cho sinh vien thu : "<<i+1<<endl;
		cin.ignore();
		cout<<"\n nhap ma so sinh vien: ";cin.getline(sv[i].maso,7);
		cout<<"\n nhap ho va ten sinh vien: ";cin.getline(sv[i].name,30);
		cout<<"\n nhap que quan : ";cin.getline(sv[i].quequan,30);
		cout<<"\n nhap tong diem :";cin>>sv[i].tongdiem;
	}
}
void sx(sinhvien sv[],int n)
{
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(sv[i].tongdiem<sv[j].tongdiem)
			{
				int giam=sv[i].tongdiem;
				sv[i].tongdiem=sv[j].tongdiem;
				sv[j].tongdiem=giam;
			}
		}
	}
}
void voder1 (sinhvien sv[],int n)
{
	cout<<"ma so sv"<<setw(10)<<"ho va ten"<<setw(20)<<"que quan "<<setw(15)<<"tong diem"<<endl;
	for(int i=0;i<n;i++)
	{      
		cout<<sv[i].maso<<setw(10)<<sv[i].name[i]<<setw(20)<<sv[i].quequan<<setw(15)<<sv[i].tongdiem<<endl;
	}
}
void voder2(sinhvien sv[],int n)
{int dem=0;
for(int i=0;i<n;i++)
{
	if(stricmp(sv[i].quequan,"Nam dinh")==0)
	dem++;
}
	if(dem!=0)
	{
		cout<<"ma so sv"<<setw(10)<<"ho va ten"<<setw(20)<<"que quan "<<setw(15)<<"tong diem"<<endl;
	for(int i=0;i<n;i++)
	{
	if(stricmp(sv[i].quequan,"Nam dinh")==0)
 	cout<<sv[i].maso<<setw(10)<<sv[i].name[i]<<setw(20)<<sv[i].quequan<<setw(15)<<sv[i].tongdiem<<endl;

	}
	}
	else
	cout<<"ko co hoc sinh nam dinh"<<endl;

}

DNH không giúp giải bài tập hộ!

7 Likes

1/ Create an array to hold all the values which is inputed by the user.
2/ Create another array to hold all different items.
3/ Loop through the input array, each item will be compared to other then if an item isn’t equal to others then put it into the array created by step 2.
That’s the most simple solution for this problem.

3 Likes

Cách đơn giản chạy được trên mọi ngôn ngữ:

Cách pro hơn nhưng tự code tay mệt hơn: Dùng hash map (thực ra hash map là CTDL cơ bản mà coder nào cũng cần phải biết)

2 Likes

Chả biết bao nhiêu tuổi, lớn hơn ai mà nội dung bài viết cụt lủn, nói trống không. Một cái phép tắc lịch sự cơ bản nhất còn không có.

3 Likes

This topic was automatically closed after 10 hours. New replies are no longer allowed.

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?