Tải bản đầy đủ (.docx) (24 trang)

Đề cương ôn tập Cơ sở lập trình 2

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (78.51 KB, 24 trang )

VECTTO_____
#include<iostream>
using namespace std;
#include<conio.h>
//xay dung lop vt1
class VT1
{
protected:
int n; float x[100];
public:
VT1();
/*VT1(int m, x[100])
{
VT1.n=m;
for( int i=1; i<=m; i++)
a[i] = x[i];
} */
/*~VT1()
{
cout<<"dieing...";
}
*/
void nhap()
{
cout<<"\nnhap so chieu cua vecto: "; cin>>n;
for( int i=1; i<=n ; i++)
{
cout<<"\nphan tu thu "<cin>>x[i];
}
}


void in()
{
cout<<"\tVECTO\t";cout<<"(";
for(int i=1; icin>>x[i];
cout<}
VT1 cong( VT1 a)
{
VT1 kq;
if (n= a.n)
{
kq.n=n;
for(int i=1 ; i<=kq.n ; i++)
kq.x[i]= x[i] + a.x[i];
}
return kq;
}
};
class VT2: public VT1
{
public:
VT2(){}
friend istream& operator>>(istream& is, VT2 &a)
{
cout<<"\nnhap so phan tu cua vecto "; is>>a.n;
for(int i=1; i

is>>a.x[i];

return is;
}
friend ostream& operator<<(ostream& os, VT2 &a)
{
os<<"\tVECTO\t"; cout<<"(";
for(int i=1; ios<os<return os;
}
VT2 operator+(VT2 b)
{
VT2 kq;
if (n=b.n)
{
kq.n=n;
for(int i=1; i<=kq.n ; i++)
kq.x[i]= x[i]+b.x[i];
}
return kq;
}
VT2 operator-(VT2 b)
{
VT2 kq;
if(n=b.n)
{
kq.n=n;
for(int i=1; i<=kq.n; i++)
kq.x[i] = x[i] -b.x[i];
}

return kq;
}
void sx()
{
float tg;
for(int i=1; i<=n ; i++)
if(x[i]>x[i+1])
{
tg=x[i]; x[i] =x[i+1]; x[i+1]=tg;
}
void in(int k)
{
for(int i=1; i<=k; i++)
cout<}

}

};
void main()
{
VT2 a,b,c; int k;
cout<<"\nnhap vecto thu nhat: "; cin>>a;
cout<<"\nnhap vecto thu 2: "; cin>>b;
cout<<"\nveto a sau khi sap xep thu tu tang dan la: ";
a.sx(); cout<cout<<"\ntong hai vecto la: "; c=a+b; cout<cout<<"\ban muon in ra phan tu thu may cua tong hai vecto: "; cin>>k;
c.in(k);
cout<<"\nhieu hai vecto la: "; c=a-b; cout<

}


LỚP PHÂN SỐ CÓ DẤU
#include<iostream>
using namespace std;
#include<math.h>
#include<string.h>
#include<conio.h>
class PS1
{public:
int ts,ms;
PS1(){}
/*~PS1()
{
cout<<"\sap chet r day" ;
}*/
void nhap()
{
cout<<"\nnhap tu so: ";cin>>ts;
do {cout<<" mau so: "; cin>>ms;
while( ms==0);
}
void in()
{
if ((ts==0)||(ms==1)) cout<else cout<void toigian();
PS1 PS1::operator+(PS1 a)
{

PS1 k;

}

k.ts=ts*a.ms+ms*a.ts;
k.ms=ms*a.ms;
k.toigian();
return k;
}
};
void PS1::toigian()
{
int a=abs(ts);
int b=abs(ms);
if(a!=0)
{
while(a!=b)
if(a>b) a=a-b;
else
b=b-a;
ts=ts/a;
ms=ms/a;
}
}
// xây dựng lớp phân số 2:
class PS2:public PS1
{
char dau[5];
public:
PS2(){}

friend istream& operator>>(istream& is, PS2 &x);
friend ostream& operator<<(ostream& os, PS2 &x);
PS2 operator++();


PS2 operator/(PS2 x);
int operator>(PS2 x)
{
if(strcmp(dau,x.dau)!=0)
if(strcmp(dau,"a")==0) return(0);
else return (1);
else if( (float)ts/ms > (float)x.ts/x.ms ) return (1);
else return (0);
}
int operator==(PS2 x)
{
if(strcmp(dau,x.dau)==0)
if(ts*x.ms==x.ts*ms) return(1);
//không dùng đc
if(ts/ms == x.ts/x.ms)
else return (0);
}
int operator!=(PS2 x)
{
if(strcmp(dau,x.dau)!=0) return(1);
else if(ts*x.ms == ms*x.ts) return(0);
else return(1);
}
int operator<=(PS2 x)
{

if(strcmp(dau,x.dau)!=0)
if(strcmp(dau,"d")==0) return(0);
else return (1);
else if(ts*x.ms > x.ts*ms) return(0);
else return (1);
}
};
istream& operator>>(istream& is, PS2 &x)
{
cout<<" tu so "; is>>x.ts;
do{
cout<<" mau so "; is>>x.ms; }
while(x.ms==0);
cout<<"\nphan so cua ban co dau: \na.phan so <=0\nd.phan so >0) ";
is.ignore();is.get(x.dau,5);
//if(x.ts/x.ms<0) x.dau='a'; else x.dau='d';
return is;
}
ostream& operator<<( ostream& os, PS2 &x)
{
if((x.ts == 0) || (x.ms == 1)) os<else if(x.ms == -1) os<<-x.ts;
else if(x.ts*x.ms < 0) os<<-abs(x.ts)<<"/"<else os<return os;
}
PS2 PS2::operator/(PS2 x)
{
PS2 kq;
kq.ts=ts*x.ms;

kq.ms=ms*x.ts;
kq.toigian();


return kq;
}
PS2 PS2::operator++()
{
PS2 kq;
kq.ts=ts+1;
kq.ms=ms+1;
kq.toigian();
return kq;
}
//ctr chính
int main()
{
int chon; int lap=1;
do
{
cout<<"\n 1. thuc hien cong viec voi lop phan so 1";
cout<<"\n 2. thuc hien cong viec voi lop phan so 2";
cout<<"\n 3. Thoat";
cout<<"\n bam 1 so de chon cong viec cua ban !";
cin>>chon;
switch(chon)
{
case 1:
PS1 a,b;
cout<<"\nnhap 2 phan so ";

a.nhap();b.nhap();
a.toigian(); b.toigian();
a.in();
b.in();
cout<<"\ntong cua hai phan so la: ";
PS1 c;
c=a+b; c.toigian(); c.in();
break;
case 2:
PS2 x,y,z;
cout<<"\nnhap 2 phan so: ";
cin>>x; cin>>y;
x.toigian(); y.toigian();cout<cout<if((x>y)==1) cout<else if((x==y)==1) cout<else cout<break;
case 3: lap=0; break;
}
cout<<"\n\n ban co muon thuc hien tiep khong\n neu co thi bam 0,
thoat thi bam 1"; // đang ở trong lap=1;
cin>>lap;
}
while(lap==0);
getch();
}


SO PHỨC

#include<iostream>
#include<conio.h>
using namespace std;
class SP1
{protected:
float pt,pa;
public:
void nhap()
{
cout<<"nhap phan thuc ";
cin>>pt;
cout<<"nhap phan ao ";
cin>>pa;
}
void in()
{
cout<}
};
class SP2:public SP1
{public:
friend istream& operator>>(istream& is, SP2 &x);
friend ostream& operator<<(ostream& os, SP2 &x);
//toan tu so sanh
int operator>(SP2 x)
{
return(0);
if(pa>x.pa) return(1);
else if((pa=x.pa) && (pt>x.pt)) return(1);
}

int operator==(SP2 x)
{
if( (pt==x.pt) && (pa=x.pa) ) return(1);
else return(0);
}
SP2 operator+(SP2 x);
SP2 operator-(SP2 x);
SP2 operator*(SP2 x);
SP2 operator/(SP2 x);
};
istream& operator>>(istream& is, SP2 &x)
{
cout<<"\nphan thuc: "; is>>x.pt;
cout<<"\nphan ao: "; is>>x.pa;
return is;
}
ostream& operator<<(ostream& os, SP2 &x)
{
os<return os;
}
SP2 SP2::operator+(SP2 x)


{

SP2 kq;
kq.pt=pt+x.pt;
kq.pa=pa+x.pa;
return kq;


}
SP2 SP2::operator-(SP2 x)
{
SP2 kq;
kq.pt=pt-x.pt;
kq.pa=pa-x.pa;
return kq;
}
SP2 SP2::operator*(SP2 x)
{
SP2 kq;
kq.pt = pt-x.pt;
kq.pa = pa-x.pa;
return kq;
}
SP2 SP2::operator/(SP2 x)
{
SP2 kq;
kq.pt = pt/x.pt;
kq.pa = pa/x.pa;
return kq;
}
int main()
{
int chon; int lap=1;
do
{
cout<<"\n 1.thuc hien cong viec voi lop phan so 1";
cout<<"\n 1.thuc hien cong viec voi lop phan so 2";

cout<<"\n 3. Thoat !";
cout<<"\nnhap 1 so de chon cong viec cua ban";
cin>>chon;
switch(chon)
{
case 1:
SP1 a,b;
cout<<"\nnhap hai so phuc ";
a.nhap();b.in();
cout<<"\nhai so phuc vua nhap la: ";
a.in();
b.in();
break;
case 2:
SP2 x,y,z; //không được trùng vs lớp SP1
cout<<"\nnhap hai so phuc: ";
cin>>x; cin>>y;
cout<<"\nket qua so sanh la ";
if((x==y)==1) cout<else if((x>y)==1) cout<else cout<cout<<"\ntong: ("<z=x+y;cout<

cout<<"\nhieu: ("<z=x-y;cout<cout<<"\ntich: ("<z=x*y;cout<cout<<"\nthuong: ("<

z=x/y; cout<break;
case 3: lap=0;break;
default: cout<<"\nnhap sai yeu cau nhap lai !"; break;
}
cout<<"ban co muon tiep tuc??\n bam 0 de tiep tuc, bam 1 de dung
lai"; cin>>lap;
}
while(lap==0);
getch();
}

MA TRẬN
/*MT1: số dòng,cột,mảng phần tử; nhập,in,cộng 2 MT
MT2: pt cộng,trừ,
main: nhập a,b; in a+b; a-b;*/
#include<iostream>
#include<conio.h>
using namespace std;
class mt1
{
protected: int sd,sc, x[30][30];
public:
mt1(){}
mt1(int m, int n)
{
sd=m; sc=n;
}
void nhap();
void in()

{
for(int i=1; i<=sd; i++)
{
for(int j=1; j<=sc; i++)
cin>>x[i][j];
cout<<"\n";
}
}
mt1 cong(mt1 a)
{
if( (sd=a.sd) && (sc=a.sc) )
{
mt1 kq(a.sd, a.sc);
for(int i=1; i<=a.sd; i++)
for(int j=1; j<=a.sc; j++)
kq.x[i][j]=x[i][j]+a.x[i][j];
return kq;
}
}
int mt::ktra()
{
int kq=1;


for(int i=1 ; i<=m ;i++)
if(a[i][i] != 1) kq=0 ;
return kq;
}
~mt1(){
cout<<"day la ham huy";

}
};
class mt2:public mt1
{
public:
mt2(){}
mt2(int m,int n)
{
sd=m; sc=n;
}
mt2 operator+(mt2 a)
{
if( (sd=a.sd) && (sc=a.sc) )
{
mt2 kq(a.sd, a.sc);
for(int i=1; i<=a.sd; i++)
for(int j=1; j<=a.sc; j++)
kq.x[i][j]=x[i][j]+a.x[i][j];
return kq;
}
}
mt2 operator-(mt2 a)
{
if( (sd=a.sd) && (sc=a.sc) )
{
mt2 kq(a.sd, a.sc);
for(int i=1; i<=a.sd; i++)
for(int j=1; j<=a.sc; j++)
kq.x[i][j]=x[i][j]-a.x[i][j];
return kq;

}
}
mt2 operator*(mt2 a)
{
if(sc=a.sd)
{
mt2 kq(sd,a.sc);
for(int i=1; i<=sd; i++)
for(int j=1; j<=a.sc; j++)
{
kq.x[i][j]=0;
for(int k=1; k<=sc; k++)
kq.x[i][j] +=x[i][k]*a.x[k][j];
}
return kq;
}
}
};
void main()
{
mt2 a,b;
a.nhap(); b.nhap();
mt2 c=a+b; c.in();


mt2 d=a-b; d.in();
getch();
}
/* lớp người: tên,ns,gt,dc; nhập,in 1ng;
lớp sv kthừa lớp ng: lớp, đtb 3 môn, học bổng; nhập,in,tính dtb 1 sv

main: dssv<100,in đtb giảm, in 8sv có đtb>=8,0 ở HNội và đạt học bổng
#include<iostream>
#include<conio.h>
#include<string.h>
#include<iomanip>
using namespace std;
struct date{ int ngay,thang,nam;};
class nguoi
{protected:
char ht[25],gt[5],dc[30]; date ns;
public:
void nhap()
{
cout<<"\nho ten: "; cin.ignore(); cin.get(ht,25);
cout<<"\nngay sinh: "; cin>>ns.ngay>>ns.thang>>ns.nam;
cout<<"\gioi tinh: "; cin.ignore();cin.get(gt,5);
cout<<"\ndia chi: "; cin.ignore(); cin.get(dc,30);
}
void in()
{
cout<<"\nho ten: "<"<"<}
};
class sv:public nguoi
{
char lop[10]; float dt,dl,dh; float dtb;int hb;
public:
sv(){sl++;}

void nhap();
void in();
float dtbinh()
{
return(dt+dl+dh)/3;
}
void doicho(sv x)
{
strcmp(ht,x.ht); ns=x.ns; strcmp(gt,x.gt); strcmp(dc, x.dc);
strcmp(lop,x.lop); dt=x.dt; dl=x.dl; dh=x.dh; dtb=x.dtb;
}
int ktra()//ktra sv ở HNội có đtb>=8.0,có hb
{
if( (hb==1) &&(dtb>=8.0) && (strstr(dc,"Ha Noi") !=NULL) )
return(1);
else return(0);
}
static int sl;
};
int sv::sl=0;
void sv::nhap()


{

nguoi::nhap();
cout<<"\nlop: "; cin.ignore(); cin.get(lop,10);
cout<<"diem toan, ly, hoa :"; cin>>dt;cin>>dl;cin>>dh;
dtb=dtbinh();
cout<<"hoc bong\nco nhap 1,khong co nhap 0 ";cin>>hb;


}
void sv::in()
{
cout<nguoi::in();cout<<"lop"<"<if(hb==1) cout<<"sinh vien co hoc bong";
else cout<<"sinh vien khong co hoc bong";
}
//ctr
void main()
{
int n,chon; sv tg,x[100]; int k=tg.sl;
cout<do
{
cout<<"\n0. Thoat!!!";
cout<<"\n1. Nhap danh sach sinh vien ";
cout<<"\n2. In danh sach sv vua nhap theo dtb giam dan";
cout<<"\n3. Hien thi 8 sinh vien o Ha Noi co hoc bong ";
cout<<"\nLua chon cong viec cua ban!! "; cin>>chon;
switch(chon)
{
case 1:
do{ cout<<"\nnhap so luong sinh vien: ";
cin>>n; break; }
while(nfor(int i=1; i<=n; i++)
x[i].nhap();

break;
case 2:
for(int i=1; i<=n; i++)
if(x[i].dtbinh()>x[i+1].dtbinh())
{
tg.doicho(x[i]);
x[i].doicho(x[i+1]); x[i+1].doicho(tg); }
for(int i=1; i<=n; i++)
x[i].in();
break;
case 3:
for(int i=1; i<=n ; i++)
if(x[i].ktra() ==1) x[i].in();
break;
}
}
while(chon==0);
getch();
}
/* lớp người: tên,ns,gt,dc; nhập,in 1ng;
lớp sv kthừa lớp ng: lớp, đtb 3 môn, học bổng; nhập,in,tính dtb 1 sv
main: dssv<100,in đtb giảm, in 8sv có đtb>=8,0 ở HNội và đạt học bổng
*/


#include<iostream>
#include<conio.h>
#include<string>
#include<iomanip>
using namespace std;

using std::string;
struct date{ int ngay,thang,nam;};
class nguoi
{protected:
string ht,gt,dc; date ns;
public:
void nhap()
{
cout<<"\nho ten: "; cin.ignore(); getline(cin,ht);
cout<<"\nngay sinh: "; cin>>ns.ngay>>ns.thang>>ns.nam;
cout<<"\gioi tinh: "; cin.ignore(); getline(cin,gt);
cout<<"\ndia chi: "; cin.ignore(); getline(cin,dc);
}
void in()
{
cout<<"\nho ten: "<"<}
};
//lớp sv
class sv:public nguoi
{
string lop; float dt,dl,dh,dtb;string hb;
public:
sv(){sl++;}
void nhap();
void in();
float dtbinh()
{
return(dt+dl+dh)/3;

}
void doicho(sv x)
{
ht=x.ht; gt=x.gt; ns=x.ns; dc=x.dc;
lop=x.lop; dt=x.dt; dl=x.dl; dh=x.dh; dtb=x.dtb;
}
int ktra()//ktra sv ở HNội có đtb>=8.0
{
if( (hb=="co hoc bong") && (dc.substr(2,6)=="Ha Noi") )
return(1);
else return(0);
}
static int sl;
};
int sv::sl=0;
void sv::nhap()
{
nguoi::nhap();
cout<<"\nlop: "; cin.ignore(); getline(cin,lop);
cout<<"diem toan, ly, hoa :"; cin>>dt>>dl>>dh;
dtb=dtbinh();
if (dtb>=8.0) hb="co hoc bong"; else if(dtb<8.0) hb="khong co hoc
bong";


}
void sv::in()
{
cout<nguoi::in();cout<<"lop"<

"<"<}
void main()
{
int n,chon; sv tg,x[100]; int k=tg.sl;
cout<do
{
cout<<"\n0. Thoat!!!";
cout<<"\n1. Nhap danh sach sinh vien ";
cout<<"\n2. In danh sach sv vua nhap theo dtb giam dan";
cout<<"\n3. Hien thi 8 sinh vien o Ha Noi co hoc bong ";
cout<<"\nLua chon cong viec cua ban!! "; cin>>chon;
switch(chon)
{
case 1:
do{ cout<<"\nnhap so luong sinh vien: ";
cin>>n; break; }
while(n>k-2);
for(int i=1; i<=n; i++)
x[i].nhap();
break;
case 2:
for(int i=1; i<=n; i++)
if(x[i].dtbinh()>x[i+1].dtbinh())
{
tg.doicho(x[i]);
x[i].doicho(x[i+1]); x[i+1].doicho(tg); }
for(int i=1; i<=n; i++)

x[i].in();
break;
case 3:
for(int i=1; i<=n ; i++)
if(x[i].ktra() ==1) x[i].in();
break;
}
}
while(chon==0);
getch();
}
/*phiếu: sp,ngl,tkn,tkc
TMặt: ht ng nhận,đc, lý do,số tiền
Vtư: ht ng giao,nhập tại kho, địa điểm, st
main: nhập các loại phiếu, đưa ra tổng số phiếu đã lập, các phiếu chi
trong quý 1 st>20tr; phiếu nhập vtư ng giao "Ng Văn A"; tổng st chi quý 2,
2013 */
#include<iostream>
#include<conio.h>
#include<string.h>
#include<iomanip>
using namespace std;


struct date{ int ngay,thang,nam; };
class phieu
{
protected:
char sp[12],tkn[10],tkc[10]; date nl;
public:

virtual void nhap()
{
cout<<"\nso phieu: "; cin.ignore(); cin.get(sp,12);
cout<<"\nngay lap: "; cin>>nl.ngay>>nl.thang>>nl.nam;
cout<<"\nTK no: "; cin.ignore(); cin.get(tkn,10);
cout<<"\nTK co: "; cin.ignore(); cin.get(tkc,10);
}
virtual void in()
{
cout<<"\nso phieu: "<"<}
};
//xây sựng lớp phiếu thu chi
class tc:public phieu
{
char htn[25],dc[50],lydo[80];
public: float st;
void nhap();
void in()
{
cout<phieu::in(); cout<<"\tho ten ng nhan: "<"<}
int ktra()
{
if( (strstr(tkc,"111")!=NULL) && (st>20000000) && (nl.thang==1)||
(nl.thang==2)||(nl.thang==3) && (nl.nam==2012) ) return(1);
else return(0);

}
int ktra1()
{
if( (strstr(tkc,"111")!=NULL) && (nl.thang==4)||(nl.thang==5)||
(nl.thang==6) && (nl.nam==2013) ) return(1);
else return(0);
}
static int sl;
};
int tc::sl=0;
void tc::nhap()
{
phieu::nhap();
cout<<"\nho ten nguoi nhan: "; cin.ignore(); cin.get(htn,25);
cout<<"\ndia chi: "; cin.ignore(); cin.get(dc,50);
cout<<"\nly do: "; cin.ignore(); cin.get(lydo,80);
cout<<"\nso tien: "; cin>>st;
}
//lớp phiếu vật tư
class vt:public phieu
{


char htg[25],kho[10],dd[50];
public:
float st;
void nhap();
void in()
{
cout<

phieu::in();cout<<"\tho ten ng giao: "<"<}
int ktra()
{
if( (strstr(tkn,"152")!=NULL) && (strcmp(htg,"Nguyen Van
A")==0) )return(1);
else return(0);
}
static int sl;
};
int vt::sl=0;
void vt::nhap()
{
phieu::nhap();
cout<<"\nho ten nguoi giao: ";cin.ignore(); cin.get(htg,25);
cout<<"\nnhap tai kho: ";cin.ignore(); cin.get(kho,10);
cout<<"\ndia diem: ";cin.ignore(); cin.get(dd,50);
cout<<"\nso tien: "; cin>>st;
}
void main()
{
int chon,n,m,count,t,v; tc x[100]; vt a[100];
do
{
cout<<"\n0. Thoat!!!";
cout<<"\n1. Nhap cac phieu thu chi ";
cout<<"\n2. Nhap cac phieu nhap xuat vat tu";
cout<<"\n3. In tong so phieu da nhap";
cout<<"\n4. Cac phieu chi trong quy I nam 2012 co tong st >20tr";

cout<<"\n5. Cac phieu nhap vat tu cua ng giao tien co ten Nguyen
Van A ";
cout<<"\n6. Tong so tien chi trong quy II nam 2013";
cout<<"\nLua chon cong viec cua ban! "; cin>>chon;
switch(chon)
{
case 1:
cout<<"\nnhap so luong phieu thu chi: ";cin>>n;
for(int i=1; i<=n; i++)
{
x[i].nhap(); x[i].sl++; }
t=x[n].sl;
break;
case 2:
cout<<"\nnhap so luong phieu nhap xuat vat tu:
"; cin>>m;
for(int i=1; i<=m; i++)
{
a[i].nhap();a[i].sl++; }
v=a[n].sl;
break;
case 3:
count=t+v; cout<

case 4:
case 5:
case 6:

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

if(x[i].ktra()==1) x[i].in();
break;
for(int i=1; i<=m; i++)
if(a[i].ktra()==1) a[i].in();
break;
float tt=0;
for(int i=1; i<=n; i++)
if(x[i].ktra1()==1) tt+=x[i].st;
cout<
}
}
while(chon!=0);
getch();
}
#include<iostream.h>
#include<conio.h>
#include<string.h>
//xay dung lop phieu
class phieu
{
char sp[15];
public: char tkn[10],tkc[10];
int ngay,thang,nam;
virtual void nhap()
{
cout<<"\nma so phieu: ";
cin.ignore(); cin.get(sp,15);
cout<<"ngay lap phieu:";
cin>>ngay>>thang>>nam;

cout<<"dinh khoan: ";
cin.ignore(); cin.get(tkn,10);
cin.ignore();5 cin.get(tkc,10);
}
virtual void in()
{
cout<<"\nso phieu: "<cout<<"\nngay lap: "<cout<<"\nTK no: "<}
virtual int loai()
{
return(0); }
virtual int ktra()
{
return(0); }
virtual float tien()
{
return(0); }
};
//xay dung lop phieu thu chi tien mat
class tc:public phieu
{
char htn[25],diachi[50],lydo[80];
public:
float st;
void nhap()


{


phieu::nhap();
cout<<"\nho ten nguoi nop: ";
cin.ignore(); cin.get(htn,25);
cout<<"\n dia chi: ";
cin.ignore(); cin.get(diachi,50);
cout<<"\nly do: ";
cin.ignore(); cin.get(lydo,80);
cout<<"\nso tien: "; cin>>st;

}
void in()
{
phieu::in();
cout<<"\n ho ten ng nop: "<cout<<"\n dia chi: "<cout<<"\nly do: "<cout<<"\n so tien: "<}
int loai()
{
return(1); }
//ktra de hien thi cac phieu thu chi trong quy 1 nam 2014 voi tong tien
lon hon 15tr
int ktra()
{
if( (thang<=3) && (thang>=1) && (nam==2014) &&
(st>=15000000 ) )
return (1);
else return(0);

}
float tien()
{
return st; }
};
//xay dung lop phieu nhap xuat vat tu
class vt:public phieu
{
char kx[15],lydo[80];
public:
float st;
void nhap()
{
phieu::nhap();
cout<<"\ntai kho: ";cin.ignore();cin.get(kx,15);
cout<<"\nly do: "; cin.ignore(); cin.get(lydo,80);
cout<<"\nso tien: "; cin>>st;
}
void in()
{
phieu::in();
cout<<"\nkho: "<cout<<"\nly do: "<cout<<"\nso tien: "<}
int loai()
{
return(2); }
//ktra cac phieu xuat kho quy 3 nam 2014 tai kho K002
int ktra()



{
if( (strcmp(tkc,"152")==0) && (strcmp(kx,"K002")==0) &&
(thang<=9) && (thang>=6) && (nam==2014) )
return(1);
else return(0);
}
} ;
//ctr chinh
void main()
{
clrscr();
int i,n,k,chon; phieu *x[100];
do
{
cout<<"\n0.Thoat!!!";
cout<<"\n1.Nhap cac chung tu";
cout<<"\n2.In cac phieu thu chi";
cout<<"\n3.In cac phieu nhap xuat vat tu";
cout<<"\n4.Cac phieu thu chi trong quy 1 nam 2014 co tong tien
lon hon 15tr";
cout<<"\n5.Cac phieu nhap xuat trong quy 3 nam 2014 tai kho
K002";
cout<<"\n6.tong tien thu trong quy 1 nam 2014";
cout<<"\nLua chon cong viec cua ban!!!!!";
cin>>chon;
switch(chon)
{
case 1: cout<<"\nso chung tu: "; cin>>n;

for(i=1; i<=n ;i++)
{
cout<<"\n1.nhap phieu thu chi tm ";
cout<<"\n2. nhap phieu nhap xuat vat tu\t";
cin>>k;
if(k==1) x[i]=new tc;
else x[i]=new vt;
x[i]->nhap();
}
break;
case 2: cout<<"\nCac phieu thu chi tien mat: ";
for(i=1; i<=n ;i++)
if(x[i]->loai()==1) x[i]->in();
getch();
break;
case 3: cout<<"\nCac phieu nhap xuat vat tu: ";
for(i=1; i<=n ;i++)
if(x[i]->loai()==2) x[i]->in();
getch();
break;
case 4: cout<<"\nCac phieu thu chi trong quy 1 nam 2014 co tong
tien lon hon 15tr la: ";
for(i=1; i<=n ; i++)
if( (x[i]->loai()==1) && (x[i]->ktra()==1) )
x[i]->in();


getch();
break;
case 5: cout<<"\nCac phieu nhap xuat vat tu trong quy 3 nam 2014

xuat tai kho K002 la:";
for(i=1; i<=n ; i++)
if( (x[i]->loai()==2) && (x[i]->ktra()==1) )
x[i]->in();
getch();
break;
case 6: float tien=0;
cout<<"\n Tong tien thu trong quy 3 nam 2014 la: ";
for(i=1; i<=n ;i++)
if( x[i]->loai()==1 )
if( (strcmp(x[i]->tkn,"111")==0) && (x[i]>nam==2014) )
tien+=x[i]->tien();
break;
default: cout<<"\nNhap sai yeu cau nhap lai!!!";
break;
}
}
while(chon!=0);
getch();
}

#include<iostream.h>
#include<conio.h>
//xay dung lop can bo cua cong ty
class CB
{char ht[25],ma[10];
public:
//float luong;
virtual void nhap();
virtual void in();

virtual int loai()
{
return(0); }
static int dem;
virtual CB{ dem++;
}
};
int CB::dem=0;
void CB::nhap()
{
cout<<"\nnhap ho ten: ";cin.ignore();cin.get(ht,25);
cout<<"\nnhap ma can bo: "; cin.ignore(); cin.get(ma,10);
}
void CB::in()
{
cout<<"\nho ten: "<cout<<"\nma so: "<}
class BC:public CB


{
float hsl,pc;
public:
void nhap();
void in()
{
CB::in();
cout<<"\nhe so luong: "<cout<<"\ntong luong: "<

}
float luong()
{
return(105000*hsl+pc); }
int loai()
{
return(1); }
};
void BC::nhap()
{
CB::nhap();
cout<<"\nnhap he so luong: "; cin>>hsl;
cout<<"\nnhap phu cap: "; cin>>pc;
}
class HD:public CB
{
float tcong,ngay,hsv;
public:
void nhap();
void in()
{
CB::in();
cout<<"\nngay cong: "<"<cout<<"\ntong luong: "<}
float luong()
{
return(ngay*tcong*hsv); }
int loai()

{
return(2); }
};
void HD::nhap()
{
CB::nhap();
cout<<"\nnhap so ngay cong: "; cin>>ngay;
cout<<"\ntien cong huong: "; cin>>tcong;
cout<<"\nhe so vuot cua cb: "; cin>>hsv;
}
//ctr chinh
void main()
{
clrscr();
int n,i,k,chon;
CB *a[100];
a->dem;
do
{
cout<<"\n1. Nhap danh sach";
cout<<"\n2. In bang luong can bo bien che";


cout<<"\n3. In bang luong can bo hop dong";
cout<<"\n0. Thoat!!!";
cout<<"\nlua chon cong viec cua ban! ";
cin>>chon;
switch(chon)
{
case 1: cout<<"\nnhap so doi tuong muon nhap ";cin>>n;

for( i=0; i{
cout<<"\n1.nhap can bo bien che";
cout<<"\n2. nhap can bo hop dong";
cin>>k;
if(k==1) a[i]=new BC;
else a[i]=new HD;
a[i]->nhap();
}
break;
case 2: cout<<"\nBANG LUONG CAN BO BIEN CHE";
for( i=0; iif(a[i]->loai()==1) a[i]->in();
break;
case 3: cout<<"\nBANG LUONG CAN BO HOP DONG";
for( i=0; iif(a[i]->loai()==2) a[i]->in();
break;
default: cout<<"\nnhap sai yeu cau nhap lai!!!";
break;
}
}
while(chon!=0);
getch();
}
/*tknh: tên csh, số tk, pass,st =>tạo tk, thêm tiền, trừ tền,hthị thông tin
bank: ds tknh,=>tìm tk st max,âm tiền..
mở rộng: thêm vào lãi suất hàng tháng */
#include<iostream>
#include<conio.h>

#include<iomanip>
#include<string>
#include<string.h>
using namespace std;
using std::string;
class tknh
{protected:
string ht,pass;long sotk;
public:
float st;
void tao();
void hthi()
{
cout<

cout<<"\nho ten CSH: "<hien co: "<}
void rut()
{ float t;
cout<<"\nnhap so tien can rut: "; cin>>t;
st-=t;
}
void gui()
{
float t;
cout<<"\nnhap so tien can gui them: "; cin>>t;
st+=t;
}

};
void tknh::tao()
{
cout<<"\nnhap ten chu so huu: ";
cin.ignore(); getline(cin,ht);
cout<<"\nnhap so tai khoan: "; cin>>sotk;
cout<<"\nnhap password: ";
cin.ignore(); getline(cin,pass);
cout<<"\nnhap so tien muon gui: "; cin>>st;
}
class bank
{
tknh ds[100]; int n;
public:
void nhap()
{
cout<<"\nnhap so luong tk: "; cin>>n;
for(int i=1; i<=n; i++)
ds[i].tao();
}
void lonnhat()
{
int i,maxi=1; float max=ds[1].st;
for(i=1; i<=n ;i++)
if(ds[i].st>max)
{
maxi=i; max=ds[i].st;
}
cout<<"\ntai khoan co so tien lon nhat la: ";
ds[maxi].hthi();

}
void am()
{
cout<<"\nDanh sach tai khoan bi am tien la: ";
for(int i=1; i<=n; i++)
if(ds[i].st<0) ds[i].hthi();
}
};
void main()
{
int chon,n; bank a;
do
{
cout<<"\n0. Thoat!!!";
cout<<"\n1. Nhap danh sach cac tai khoan moi lap ";


cout<<"\n2. Hien thi tai khoan co so tien lon nhat trong ngan
hang";
cout<<"\n3. Danh sach cac tai khoan am tien";
cout<<"\nLua chon cong viec cua ban!!"; cin>>chon;
switch(chon)
{
case 1: a.nhap(); break;
case 2: a.lonnhat(); break;
case 3: a.am(); break;
}
}
while(chon!=0);
getch();

}
// Lop HDBH (hoa don ban hang)
#include <conio.h>
#include <iostream.h>
class HDBH
{
private:
int shd ;char *tenhang ;double tienban ;
static int tshd ;
static double tstienban ;
public:
static void in()
{
cout <<"\n" << tshd;
cout <<"\n" << tstienban;
}
} ;
int HDBH::tshd=5;
double HDBH::tstienban=20000.0;
void main()
{
HDBH::in();
getch();
}
// Lop HDBH (hoa don ban hang)
#include <conio.h>
#include <iostream.h>
class HDBH
{
char *tenhang ;double tienban ;

static int tshd ;
static double tstienban ;
public:
HDBH(char *tenhang1=NULL,double tienban1=0.0 )
{
tienban=tienban1;
tenhang=tenhang1;
++tshd;


tstienban += tienban;
}
~HDBH()
{
--tshd;
tstienban -= tienban;
}
void sua();
static void in();
} ;
int HDBH::tshd=0;
double HDBH::tstienban=0;
void HDBH::in()
{cout <<"\n\nTong so hoa don: " << tshd;
cout <<"\nTong so tien: " << tstienban;
}
void HDBH::sua()
{
cout << "\n\nTen hang: " << tenhang;
cout << "\nTien ban : " << tienban;

tstienban -= tienban;
cout << "\nSua tien ban thanh : " ;
cin >> tienban;
tstienban += tienban;
}
void main()
{
HDBH *h1 = new HDBH("Xi mang",2000);
HDBH *h2 = new HDBH("Sat thep",3000);
HDBH *h3 = new HDBH("Ti vi",4000);
HDBH::in();
delete h1;
HDBH::in();
h2->sua();
HDBH::in();
delete h3;
HDBH::in();
}



×