mình đang sài Dev C++, có mấy cái hàm mình rất bị rối nhất là hàm struct và các hàm cắt chuỗi
nếu ai đã hiểu hết về Dev thì cho mình hỏi mấy cái vấn đề đi ạ
nếu ai đã hiểu hết về Dev thì cho mình hỏi mấy cái vấn đề đi ạ
Nói luôn trên này đi .ban co gmail khong z
#include <iostream>#include <stdio.h>
#include <string>
struct diemthi
{
float toan;
float ly;
float hoa;
};
struct sinhvien
{
char masv[10];
char hoten[50];
char ngaysinh[20];
char sbd[20];
diemthi diem;
};
void nhap1sv(sinhvien &sv);
void xuat(sinhvien sv);
void nhapmangsv(sinhvien sv[],int n);
void xuatmang(sinhvien sv[],int n);
int timsv(sinhvien a[],int n);
int timvitrisv(sinhvien a[],int n);
void timlietketen(sinhvien a[],int n);
int main()
{
sinhvien sv[10]; int n; int z; int vt;
cout<<"Nhap n"; cin>>n;
nhapmangsv(sv,n);
xuatmang(sv,n);
cout<<"vi tri can tim la:"<<timvitrisv(sv,n);
}
void nhap1sv(sinhvien &sv)
{ cout<<"masv:";gets(sv.masv);
cout<<"hoten:";gets(sv.hoten);
cout<<"ngay sinh:"; gets(sv.ngaysinh);
cout<<"so bao danh:"; gets(sv.sbd);
cout<<"diem toan:"; cin>>sv.diem.toan;
cout<<"diem ly:"; cin>>sv.diem.ly;
cout<<"diem hoa:"; cin>>sv.diem.hoa;
}
void xuat(sinhvien sv)
{
cout<<"\n"<<"masv:"<<sv.masv<<"\n";
cout<<"\n"<<"hoten:"<<sv.hoten<<"\n";
cout<<"ngaysinh:"<<sv.ngaysinh<<"\n";
cout<<"sbd:"<<sv.sbd<<"\n";
cout<<"diem toan:"<<sv.diem.toan<<"\n";
cout<<"diem ly:"<<sv.diem.ly<<"\n";
cout<<"diem hoa:"<<sv.diem.hoa<<"\n";
}
void nhapmangsv(sinhvien sv[],int n)
{
for(int i=0;i<n;i++)
{
cout<<"-------------Nhap sv thu["<<i<<"]------------"<<"\n";
nhap1sv(sv[i]);
}
}
void xuatmang(sinhvien sv[],int n)
{
for(int i=0;i<n;i++)
{
cout<<"-------------Xuat sv thu["<<i<<"]------------"<<"\n";
xuat(sv[i]);
}
}
int timsv(sinhvien a[],int n)
{ char x[100];
int i=0;
cout<<"nhap masv"; gets(x);
while(strcmp(a[i].masv,x)!=0 &&i<n) i++;
if(i==n) return 0;
else return 1;
}
int timvitrisv(sinhvien a[],int n)
{
char f[100];
int i=0;
cout<<"nhap masv"; gets(f);
while(stricmp(a[i].masv,f)!=0 &&i<n) i++;
if(i==n) return -1;
else return i;
}
void timlietketen(sinhvien a[],int n)
{
char f[100];
int i=0;
cout<<"nhap hoten:"; gets(f);
while(i<n&& stricmp(a[i].hoten,f)==0)
{
xuat(a[i]);
i++;
}
}
thêm using namespace std vào #include<iostream>chưa gì nó bị lỗi ở cout<<"nhap n ";cin>>n;Mã:#include <iostream>#include <stdio.h> #include <string> struct diemthi { float toan; float ly; float hoa; }; struct sinhvien { char masv[10]; char hoten[50]; char ngaysinh[20]; char sbd[20]; diemthi diem; }; void nhap1sv(sinhvien &sv); void xuat(sinhvien sv); void nhapmangsv(sinhvien sv[],int n); void xuatmang(sinhvien sv[],int n); int timsv(sinhvien a[],int n); int timvitrisv(sinhvien a[],int n); void timlietketen(sinhvien a[],int n); int main() { sinhvien sv[10]; int n; int z; int vt; cout<<"Nhap n"; cin>>n; nhapmangsv(sv,n); xuatmang(sv,n); cout<<"vi tri can tim la:"<<timvitrisv(sv,n); } void nhap1sv(sinhvien &sv) { cout<<"masv:";gets(sv.masv); cout<<"hoten:";gets(sv.hoten); cout<<"ngay sinh:"; gets(sv.ngaysinh); cout<<"so bao danh:"; gets(sv.sbd); cout<<"diem toan:"; cin>>sv.diem.toan; cout<<"diem ly:"; cin>>sv.diem.ly; cout<<"diem hoa:"; cin>>sv.diem.hoa; } void xuat(sinhvien sv) { cout<<"\n"<<"masv:"<<sv.masv<<"\n"; cout<<"\n"<<"hoten:"<<sv.hoten<<"\n"; cout<<"ngaysinh:"<<sv.ngaysinh<<"\n"; cout<<"sbd:"<<sv.sbd<<"\n"; cout<<"diem toan:"<<sv.diem.toan<<"\n"; cout<<"diem ly:"<<sv.diem.ly<<"\n"; cout<<"diem hoa:"<<sv.diem.hoa<<"\n"; } void nhapmangsv(sinhvien sv[],int n) { for(int i=0;i<n;i++) { cout<<"-------------Nhap sv thu["<<i<<"]------------"<<"\n"; nhap1sv(sv[i]); } } void xuatmang(sinhvien sv[],int n) { for(int i=0;i<n;i++) { cout<<"-------------Xuat sv thu["<<i<<"]------------"<<"\n"; xuat(sv[i]); } } int timsv(sinhvien a[],int n) { char x[100]; int i=0; cout<<"nhap masv"; gets(x); while(strcmp(a[i].masv,x)!=0 &&i<n) i++; if(i==n) return 0; else return 1; } int timvitrisv(sinhvien a[],int n) { char f[100]; int i=0; cout<<"nhap masv"; gets(f); while(stricmp(a[i].masv,f)!=0 &&i<n) i++; if(i==n) return -1; else return i; } void timlietketen(sinhvien a[],int n) { char f[100]; int i=0; cout<<"nhap hoten:"; gets(f); while(i<n&& stricmp(a[i].hoten,f)==0) { xuat(a[i]); i++; } }