PDA

View Full Version : Tin hoc



ngoc thanh
22-09-2008, 10:14 PM
có ai giúp mình làm 2 bài tập này với:
bài 1:Viết 1 chương trình quản lý sinh viên trong C++.( Kiểu khai báo lớp sinh viên ấy, càng đầy đủ càng tốt hen).
bài 2: Viết 1 chương trình khai báo 1 lớp vector trong C++.
Mình xin cảm ơn rất nhiều.:proud:

haidh
23-09-2008, 10:27 AM
#include<conio.h>
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
class nguoi
{
private:
char ho[10],ten[10];
int lop,gioitinh,ns;
public:
void nhap()
{
cout<<"\n nhap ho cua sinh vien :";
cin.ignore(1);
cin.get(ho,10);
cout<<"\n nhap ten cua sinh vien :";
cin.ignore(1);
cin.get(ten,10);
cout<<"\n nhap lop sinh vien dang hoc";
cin>>lop;
cout<<"\n nhap nam sinh :";
cin>>ns;
cout<<"\n nhap gioi tinh";
while(1)//---->warning : funtion containing while are not expanded inline
//Chỗ này còn bị 1 lỗi như description ở trên
{
cin>>gioitinh;
if((gioitinh==0)||(gioitinh==1))
break;
else
cout<<"\n nhap lai gioi tinh";
}
}
void hien()
{
cout<<setw(10)<<ho<<setw(10)<<ten<<setw(5)<<gioitinh<<setw(5)<<ns<<setw(5)<<lop;
{
int traveten()
{
return ten();
}
};
class diem
{
private:
float csdl,mmt,ctdl,java,trituent,lthdt,moncs,moncn;
public:
void nhap()
{
cout<<"nhap diem mon co so du lieu";
cin>>csdl;
cout<<"nhap diem mon mang may tinh";
cin>>mmt;
cout<<"nhap diem mon cau truc du lieu";
cin>>ctdl;
cout<<"nhap diem mon java";
cin>>java;
cout<<"nhap diem mon lap trinh huong doi tuong: ";
cin>>lthdt;
cout<<"nhap diem mon tri tue nhan tao";
cin>>trituent;
*moncs=mmt+lthdt+ctdl;
*moncn=java+trituent+csdl;
}
void hiends()
{
cout<<setw(5)<<mmt<<setw(5)<<lthdt<<setw(5)<<ctdl<<moncs<<setw(5)<<java<<setw(5)<<trituent<<setw(5)<<csdl<<setw(5)<<moncn;
}
float travediemmoncs()
{
return moncs;
}
float travediemmoncn()
{
return moncn;
}
int kq()
{
if(moncs>=5)&&(moncn>=5)//--->expreesion syntax;
{
return 1;
return 0;
}
}//statament mising;
};
class sinhvien:
public nguoi,diem
{
private:
char masv[5],dieukientotnghiep[20];
public:
void nhap()
{
cout<<"\n nhap ma sinh vien";
cin.ignore(1);
cin.get(masv,5);
nguoi::nhap();
diem::nhap();
if(kq==1)
strcpy(dieukientotngiep,"tot nghiep");
else
strcpy(dieukientotngiep,"khong tot nghiep");
}
void hien()
{
cout<<setw(5)<<masv;
nguoi::hien;
diem::hien;
cout<<setw(20)<<dieukientotnghiep;
}
int timkiemten(char t[])
{
if(strcpy(traveten(),t)==0)
return 1;
return 0;
}
void sxtheoten(sinhvien *sv1,sinhvien *sv2)
{
sinhvien tam;
if(strcpy(sv1->traveten(),sv2->traveten())>0)
{
tam=*sv1;
*sv1=*sv2;
*sv2=tam;
}
}
void sapxeptheodiemmoncs(sinhvien *sv1,sinhvien *sv2)
{
sinhvien tam;
if(sv1->diem.moncs<sv2->diem.moncs)
{
tam=*sv1;
*sv1=*sv2;
*sv2=tam;
}
}
void them(sinhvien *sv,int *n,sinhvien tam)
{
sv[*n]=tam;
*n=*n+1;
}
void xoa(sinhvien *sv,int *n,int vt)
{
int i;
for(i=vt-1;i<*n;i++)//---->warning : funtion containing while are not expanded inline
sv=sv;
*n=*n-1;
}
void sua(sinhvien *sv)
{
sinhvien tam;
cout<<"\n nhap thong tin can sua";
tam.nhap();
*sv=tam;
}
void hiends(sinhvien *sv,int n)
{
int i;
for(i=0;i<n;i++)
{
cout<<"\n"<<setw(4)<<i+1;
sv.hiends();//--->funtion 'hien'should have protype
}
getch();
}
void main()
{
sinhvien *sv,tam;
int i,j,m,vt;
char t[10];
clrscr();
cout<<"\n nhap so luong sinh vien:";
cin>>m;
sv=new sinhvien[m];
cout<<"\n nhap danh sach sinh vien";
for(i=0;i<n;i++)//--->undefined symbol 'n'l
{
cout<<"\n nhap sinh vien thu :"<<i+1;
sv.nhap();
}
cout<<"\n danh sach thi sinh vua nhap : ";
for(i=0;i<n;i++)
{
cout<<"\n"<<i+1;
sv.hiends();
}
cout<<"\n nhap ten can tim : ";
cin.ignore(1;)
cin.get(i,10);
cout<<"\n danh sach thi sinh co ten "<<t<<"la : \n";
for(i=0;i<n;i++)
if(sv,timkiemten(t)==1)//-->funtion 'timkiemten' should have protype
{
cout<<"\n";
sv.hiends();
}

for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
{
sapxeptheodiemmoncs(&sv,&sv[j]);
cout<<"”\n danh sach sinh vien vua duoc sap xep theo diem mon co so: ”";
hiends(sv,m);

for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
sapxeptheodiemmoncn(&sv,&sv[j]);
cout<<"”\n danh sach sinh vien vua duoc sap xep theo diem mon chuyen nganh: ”";
hiends(sv,m);

for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)
sapxeptheoten(&sv[I],&sv[j]);
cout<<"”\n danh sach sinh vien vua duoc sap xep theo ten: ”";
hiends(sv,m);

cout<<"”\n nhap cac thong tin ve sinh vien can nhap them : ”";
tam.nhap();
them(sv,&m,tam);

cout<<"\n danh sach sinh vien vua duoc them vao : ";
hiends(sv,m);

cout<<"\n nhap vi tri can sua:";
cin>>vt;
sua(&sv[vt-1]);

cout<<"\n danh sach sinh vien vua duoc dua doi : ";
hiends(sv,m);
cout<<"\n nhap vi tri can xoa";
cin>>vt;
xoa(&sv,&m,vt);
cout<<"\n danh sach sinh vien vua xoa : ";
hiends(sv,m);
getch();
delete sv;
}
}

Khai báo lớp vector thì cứ y như sách mà làm thôi!
A ko chuyên C++ nhưng có lẽ lớp Vector trong C++ cũng giống trong Java!

Candy
27-09-2008, 09:22 PM
cái ngôn ngữ java lại khác nhiều so với C++ đấy anh ạ. pascal thì giống C++ ở cái cách lập trình chỉ khác về ngôn ngữ

haidh
27-09-2008, 10:01 PM
cái ngôn ngữ java lại khác nhiều so với C++ đấy anh ạ. pascal thì giống C++ ở cái cách lập trình chỉ khác về ngôn ngữ
Câu đầu đúng, câu sau vừa sai vừa ..chuối :d!

SevenLove
20-10-2008, 05:43 PM
ông chủ topic học trường j thế ???????..........................