80
Bài tập ngôn ngữ lập trình Họ và tên: Mai Xuân Hòa MSSV :20111596 Lớp : Điện tử 07 1. Chương trình in ma trận #include <iostream> #include <iomanip> using namespace std; int main() { int m,n; cout<<"Nhap vao m, n "; cin>>m>>n; for(int i=0, k=1; i<=m; i++) { for(int j=0; j<=n; j++,k++) cout<<k<<'\t'; cout<<endl; } system("pause"); } ---------------------------------------------------------------------------------------------------------------------- 2. Xác định tam giác #include<iostream> #include<math.h> using namespace std; int main() { double a, b,c; while(1){ cout<<"nhap 3 canh : "; cin>>a>>b>>c; if(a>=b+c||b>=a+c||c>=a+b) break; int canh=(a==b)|((b==c)<<1)|((c==a)<<2);

[123doc.vn] - Bai Tap Ngon Ngu Lt

Embed Size (px)

Citation preview

  • Bi tp ngn ng lp trnhH v tn: Mai Xun Ha

    MSSV :20111596

    Lp : in t 07

    1. Chng trnh in ma trn#include #include using namespace std;int main(){ int m,n; coutm>>n; for(int i=0, k=1; i

  • a*=a; b*=b; c*=c; int goc=(c==a+b)|((a==b+c)
  • } else{ cout
  • }cout
  • { d.re=((this->re*c.re)+(this->im*c.im))/((c.re*c.re)+(c.im*c.im)); d.im=((c.re*this->im)-(this->re*c.im))/((c.re*c.re)+(c.im*c.im)); } return d; }int main(){ //khai bao 2 so phuc y va z, moi so dc khoi tao tu 1 hoac 2 so thuc bat ky //khai bao bien double a va khoi tao bang mot so thuc bat ky complex y(2.0,2.9), z(3.0,3.0); double a=0.3; cout
  • phanso phanso::operator / (phanso p){

    return phanso(this->a*p.b, this->b*p.a);}int main(){

    phanso x(5,6),y(7,8);cout

  • template void Matrix::CreateData(){

    data = new _T* [rows];for(int i=0; i

  • template Matrix Matrix::operator+(const Matrix& M){

    Matrix temp(rows,cols);if(rows==M.rows&&cols==M.cols){

    for(int i=0; i

  • }}

    int main(){

    Matrix A(3,3);Matrix B(3,3);A=B;cout

  • #include "iostream.h"#include "conio.h"#include "math.h"class PS{ int t,m; public: friend ostream& operator(istream& is, PS &p); friend PS rutgon(PS p); PS operator+(PS p); PS operator-(PS p); PS operator*(PS p); PS operator/(PS p);}; int USCLN(int x,int y){ if(x==0) return y; if (y==0) return x; while (x!=y) { if(x>y) x-=y; else y-=x; }}ostream& operator
  • { PS q; int x; x=uscln(p.t,p.m); q.t=p.t/x; q.m=p.m/x; return q;} PS PS::operator+(PS p){ PS q; q.t=t*p.m+p.t*m; q.m=m*p.m; return rutgon(q);} PS PS::operator-(PS p){ PS q; q.t=t*p.m-p.t*m; q.m=m*p.m; return rutgon(q);} PS PS::operator*(PS p){ PS q; q.t=t*p.t; q.m=m*p.m; return rutgon(q);} PS PS::operator/(PS p){ PS q; q.t=t*p.m; q.m=m*p.t; return rutgon(q);} void main(){

  • PS p1,p2,p; coutp1; coutp2; p=p1+p2; cout
  • complex temp; temp.real=real-c.real; temp.image=image-c.image; return temp;} complex operator+(float x, complex c){ complex temp; temp.real=c.real+x; temp.image=c.image; return temp;} ostream& operator
  • - Hm hin th xu v di xu - Hm ni xu cng hai xu (xaukytu s) - Hm hu .Vit chng trnh kim tra

    SOLUTION 3:

    File xaukytu.h#ifndef xaukytu_h#define xaukytu_hclass xaukytu{ private: int length; char * str; public: xaukytu(char * s); xaukytu(); void htxau(); xaukytu noixau(xaukytu s1); ~xaukytu();};#endifFile xaukytu.cpp #include #include "xaukytu.h"#include #include xaukytu::xaukytu(){ str=" "; length=0; cout

  • }xaukytu::~xaukytu(){ delete str; getch();}xaukytu xaukytu::noixau(xaukytu s){ char * temp = str; length+=s.length; str=new char[length]; strcpy(str,temp); //copy xau temp vao xau str strcat(str,s.str);//noi hai xau s.str va str delete temp; return *this;}void main(){ xaukytu s; s.htxau(); xaukytu s1(" Truong Dai Hoc "); xaukytu s2(" Dien Luc "); s1.noixau(s2); s1.htxau(); getch();}

    -------------------------------------------------------------------------

    PROGRAM 4: To mt lp vector gm c cc thnh phn sau: - Cc thuc tnh : float * v; int n - Hm thit lp khng tham s - Hm thit lp mt tham s - Hm thit lp hai tham s - Hm hin th - Hm huVit mt chng trnh kim tra.

    SOLUTION 4:#include #include class vector

  • { private: int n; float *v; public: vector();//ham thiet lap khong tham so vector(int size);//ham thiet lap mot tham so vector(int size,float * a);//ham thiet lap hai tham so void display(); ~vector();//ham huy}; vector::vector(){ cout
  • cout
  • cnh ca mt tam gic) + Hm tnh din tch tam gic + Hm kim tra tam gic(u, vung cn, cn, vung, thng) + Hm hin th thng tin( din tch, tnh cht tam gic) Vit mt chng trnh kim tra.

    SOLUTION 5:#include #include #include class tamgiac{ private: int a,b,c; float dientich(); int kttamgiac(); public: void nhap(); void in();};void tamgiac::nhap(){ do { couta; coutb; coutc; }while(a+b

  • return 3; else if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b) return 4; else return 5; } void tamgiac::in() { cout
  • giy.Lp Time c cc thnh phn sau:- Cc thuc tnh m t gi, pht, giy;- Cc hm thnh phn dng xc lp gi tr cho tng thnh phn

    gi, pht, giy(C kim tra iu kin gi (0->23), pht(0->59), giy(0->59);

    - Hm thnh phn setTime(int,int,int) xc lp thi gian- Hm hin th gi theo nh dng 24 ting (vd : 23:54:40);- Hm hin th gi theo nh dng 12 ting( vd : 11:54:40 PM);- Hm tngGiy() tng thi gian mi ln ln mt giy. Ch cc

    trng hp tng sang pht tip theo, tng sang gi tip theo,tng sang ngy tip theo.

    Vit chng trnh chnh khai bo mt i tng thi gian l 23:59:58 v thc hin tng thi gian 5 giy ng thi hin th thi gian cho mi ln tng.

    SOLUTION 6:#include #include class time{ private: int hour; int minute; int second; void incHour(); void incMinute(); public: void setTime(int,int=0,int=0); void setHour(int); void setMinute(int); void setSecond(int); void print12h(); void print24h(); void incSecond();};

    void time::incHour(){ hour++; if(hour==24) hour=0;}void time::incMinute(){ minute++; if(minute==60) { minute=0; incHour(); }} void time::incSecond(){ second++; if(second==60) {

  • second=0; incMinute(); } }void time::setHour(int h){ hour=(h>=0 &&h=0 &&m=0 &&s
  • PROGRAM 7: Vit mt chng trnh xy dng hai lp: mt lp th sinh v mt lp danh sch th sinh. Trong lp th sinh c d liu bao gm cc thng tin: s bo danh, im ton, im ho, im l. Lp danh sch th sinh c d liu mt mng cc th sinh v s lng phn t thuc mng . Vit chng trnh thc hin cc cng vic sau:1. Nhp v hin th mt danh sch cc th sinh t bn phm2. Sp xp danh sch cc th sinh theo th t tng dn v im s3. Hin th thng tin ca cc sinh vin c tng im trn 18

    SOLUTION 7:#include #include class thisinh{ private: char sbd[25]; float dtoan,dly,dhoa; public: void nhap(); void in(); float tdiem();};void thisinh::nhap(){ coutsbd; coutdtoan; coutdly; coutdhoa;}void thisinh::in(){ cout

  • class dsts{ private: int n; thisinh dsts[100]; public: void nhapds(); void inds(); void sapxep(); void tdtren18();}; void dsts::nhapds(){ coutn; for(int i=0;i
  • if(dsts[i].tdiem()>18) dsts[i].in();} void main(){ dsts ds; ds.nhapds(); cout
  • { coutr;} float hinhtron::chuvi(){ return (2*PI*r);} float hinhtron::dientich(){ return (PI*pow(r,2));} void hinhtron::in(){ cout
  • float diem;};void nhap(sinhvien *sv, int n );void hienthi(sinhvien *sv, int n );void sapxep(sinhvien *sv, int n);void swap(sinhvien *x,sinhvien *y);sinhvien * tron_ds(sinhvien * sv1,sinhvien * sv2,int n1,int n2);void main(){ int n1,n2; sinhvien sv1[20],sv2[20]; printf("\n Ban hay nhap danh sach sinh vien vao 2 mang!"); printf("\n Nhap so luong sinh vien vao danh sach thu nhat n1:"); scanf("%d%*c",&n1); nhap(sv1,n1 ); sapxep(sv1,n1); printf("\n DSSV thuoc ds1 sap xep giam dan theo diem la:"); hienthi(sv1,n1); printf("\n Nhap so luong sinh vien vao danh sach thu hai n2:"); scanf("%d%*c",&n2); nhap(sv2,n2 ); sapxep(sv2,n2); printf("\n DSSV thuoc ds2 sap xep giam dan theo diem la:"); hienthi(sv2,n2); printf("\n Tron 2 ds sap xep giam dan theo diem la:"); hienthi(tron_ds(sv1,sv2,n1,n2),n1+n2); getch();}void nhap(sinhvien *sv, int n ){ float diem; for(int i=0;i
  • swap(&sv[i],&sv[j]);}void swap(sinhvien *x,sinhvien *y){ sinhvien temp; temp=*x; *x=*y; *y=temp;}sinhvien * tron_ds(sinhvien * sv1,sinhvien * sv2,int n1,int n2){ sinhvien * sv=new(sinhvien[20*2]); int i1,i2,i; i1=i2=0; for (i=0;i=n1 ||i2>=n2) break; if(sv1[i1].diem>sv2[i2].diem) { sv[i]=sv1[i1]; i1++; } else { sv[i]=sv2[i2]; i2++; } } if(i1
  • { private: int day; int month; int year; int checkday(int day); public: date1(int=1,int=1,int=1990); void print();};#endif #include #include #include "date1.h" date1::date1(int dy,int mn,int yr){ if(mn>0 && mn
  • cout
  • { setdate(d,m,y);} void date1::setdate(int d,int m,int y){ month=(m>=1 && m=1900 && y=1 && d=1 && d
  • } else ++day;} date1 &date1::operator++(){ helpIncrement(); return * this;} date1 & date1::operator+=(int addday){ for(int i=0;i
  • PROGRAM 12:

    To lp im (point) c thuc tnh l cc to x, y.Xy dng cc hm cn thit nh nhp v hin th cc to , tnh khong cch gia hai im.Vit chng trnh nhp vo n im t bn phm.Tm v hin th khong cch ln nht gia hai im trong n im .

    SOLUTION 12:

    #include "conio.h"#include "math.h"class point{ int x,y; public: void nhap(){ coutx; couty;}void in(){ cout

  • } cout
  • File employee.cpp #include #include #include "employee1.h"#include #include "date1.h" employee1::employee1(char * fn,char *ln,int bd,int bm,int by,int hd,int hm,int hy){ firstname=new char[strlen(fn)+1]; strcpy(firstname,fn); lastname=new char[strlen(fn)+1]; strcpy(lastname,ln); birthdate=new date1(bd,bm,by); hiredate=new date1(hd,hm,hy); }char *employee1::get_firstname(){ return firstname;} char *employee1::get_lastname(){ return lastname;} employee1::~employee1(){ cout
  • cout
  • { public: virtual float chuvi()=0; void in() { cout
  • class hinhvuong:public haichieu{ float a; public: hinhvuong(float a1) { a=a1; } float chuvi() { return 4*a; } float dientich() { return a*a; } char *ten() { return " hinh vuong "; }}; class tamgiacdeu:public haichieu{ float a; public: tamgiacdeu(float a1) { a=a1; } float chuvi() { return 3*a; } float dientich() { return a*a*sqrt(3)/2; } char *ten() {

  • return " hinh tam giac deu"; }}; class hinhcau:public bachieu{ float r; public: hinhcau(float r1) { r=r1; } float thetich() { return(r*r*r*M_PI/4) ; } float dientich() { return r*r*4*M_PI; } char *ten() { return " hinh cau "; }}; class lapphuong:public bachieu{ float a; public: lapphuong(float a1) { a=a1; } float thetich() { return(a*a*a) ; } float dientich() { return a*a*6; }

  • char *ten() { return " hinh lap phuong "; }}; void main(){ hinhvuong hv(3); hv.in(); hinhtron ht(4); ht.in(); tamgiacdeu tgd(5); tgd.in(); lapphuong lp(3); lp.in(); hinhcau hc(2); hc.in(); getch();}PROGRAM 15: Khun hnh (template)(C++20) (02/11/2006) Chng trnh s dng khun hnh (template) thc hin vic tm phn s nh nht, sau a kt qu ln mn hnh.

    #include "iostream.h"#include "conio.h"template T min(T a, T b){ if (a

  • PS p1(1,2),p2(3,3); min(p1,p2).display();getch();}

    PROGRAM 16:

    Khun mu lp C++(24) (15/11/2006) S dng khun hnh lp xy dng lp List c cc tnh cht sau:- Cc thuc tnh :T a[max], int size;- Cc phng thc : Chn, xo , tm kim, sp xp cc phn

    t ca mt mng#include #include templateclass list{ private: T a[max]; int size; public: list(); int get_size(); bool is_empty(); void insert(int index, T &itemp); void remove(int index); T retrieve(int index); int find_max(int start,int end); int search(T & itemp); void append(T &itemp); void sort(int start,int end); }; templatelist::list(){ size=0;} templatevoid list::append(T &itemp)

  • { a[size]=itemp; size++;}templatevoid list::insert(int index,T & itemp){ if(is_empty()) { append(itemp); } else if(index>=0 && index=0 && index
  • bool list::is_empty(){ return size==0;} templateint list::get_size(){ return size;} templateint list::find_max(int start,int end){ int m=start; for(int i=start+1;ia[m]) m=i; return m;} template int list::search(T& itemp){ for(int i=0;i
  • a[j]=temp; } }} void main(){ list ds; for(int i=0;i
  • templateclass stack{ private: T a[n]; int top; public: stack(); bool is_empty(); void push(T itemp); T pop(); T get_top();}; templatestack::stack(){ top=-1;} templatebool stack::is_empty(){ return (top==-1);} templatevoid stack::push(T itemp){ if(top>=max-1) cout
  • cout
  • itemp=s1.pop(); cout
  • { return (ts*p.ms
  • { int a[10],n; phanso b[10]; cout
  • SOLUTION 19:#include #include class matrix;class vector{ private: int v[3]; public: vector(int v1=0,int v2=0,int v3=0) { v[0]=v1; v[1]=v2; v[2]=v3; } void display() { for(int i=0;i
  • for(i=0;i
  • class vector{ private: int n; float *v; public: vector();//ham thiet lap khong tham so vector(int size);//ham thiet lap mot tham so vector(int size,float * a);//ham thiet lap hai tham so void display(); ~vector();//ham huy}; vector::vector(){ cout
  • { cout
  • Vit chng trnh ng dng cc hm trn

    3. Vit mt hm ng thi tm gi tr ln nht v gi tr nh nht ca 1 mng.Vit 1 chng trnh ng dng hm .

    SOLUTION 21:1. Hm tm gi tr ln nht ca 1 mng

    int gtln (int *a,int n){int *q;q=a;int max=*q;while (qmax) max=*q;q++;

    };

    return max;}

    Chng trnh ng dng hm trn:

    #include "stdafx.h"#includeusing namespace std;void nhap (int *a, int n);int gtln (int *a,int n);int _tmain(int argc, _TCHAR* argv[]){ int a[100],n; int *p;

    p=a;

    do { cout

  • //ham nhapvoid nhap (int *a,int n){

    int *p;p=a; cout

  • void nhap (int *a, int n);int diachi (int *a,int n);int main(){ int a[100],n; int *p;p=a;

    do{cout

  • -------------------------------------------------------------------------

    PROGRAM 22: CC TIN CH V CHUI (STRING)

    #include

    #include

    using namespace std;

    class String

    {

    private:char* str;

    char* tmp; //Khai bao cac bien string

    long length;

    long l;

    public://Empty constructor;

    String(){str=""; length=0; tmp=new char[1];} //tmp is created as new as to delete in Destructor

    //String Constructor

    // Assign the string passed

  • String(char* s){ length=strlen(s); l=length+1;

    str=new char[l]; strcpy(str,s);

    *(str+length)='\0'; tmp=new char[1];}

    //Destructor

    ~String() { delete str; delete tmp; }

    //Length of the string

    long Length(){length=strlen(str);return length;}

    //like in Java, toString returns the entire string

    char* toString(){ return str;};

    //Get the substring providing start and length parameters

    char* subString(long stt,long len);

    //Get the wordcount "default delimiter is spaces and CRLF

    long WordCount();

    //Get the location of a particular string or character inside the actual string

    long getCharLoc(char*,long);

    //set this string overriding the initial

    void setString(char* s)

    {

    delete str;

    length=strlen(s); l=length+1 ;

    str=new char[l]; strcpy(str,s);

    *(str+length)='\0'; tmp=new char[1];

    }

    };

  • long String::getCharLoc(char* sch,long stt)

    {

    long i,j;

    long schlen=strlen(sch);

    if (stt< 1 || stt>length)

    return 0;

    else

    {

    for(j=0;j

  • return 0;

    }

    }

    char* String::subString(long stt,long len){

    long a,b;

    if( stt>length || len > length || (length-stt+1)

  • }int main()

    {

    //Define default string

    String x("Hello world This is new C++");

    //show the string to check

    cout

  • Bull ****

    The new string length is 9

    -------------------------------------------------------------------------

    PROGRAM 23: CLASS STRING T NH NGHA

    #include

    #include

    #include

    #include

    class String

    {

    private:

    char *Ptr; //Con tro tro den diem bat dau cua chuoi

    int Length; //Chieu dai chuoi

    public:

    String(const char * = ""); //Constructor chuyen doi

    String(const String &); //Constructor sao chep

    ~String(); //Destructor

    const String &operator=(const String &);

    //Phep gan

    String &operator+=(const String &);

    int operator!() const;

  • int operator==(const String &) const; //So sanh bang`

    int operator!=(const String &) const; //So sanh khong bang

    int operator(const String &) const; //So sanh lon hon

    int operator>=(const String &) const; //So sanh >=

    int operator

  • // cout
  • return *this;

    }

    String &String::operator+=(const String &Right)

    {

    char *TempPtr = Ptr;

    Length += Right.Length;

    Ptr = new char[Length + 1];

    assert(Ptr != 0);

    strcpy(Ptr, TempPtr);

    strcat(Ptr, Right.Ptr);

    delete [] TempPtr;

    return *this;

    }

    int String::operator!() const

    {

    return Length == 0;

    }

    int String::operator==(const String &Right) const

    {

    return strcmp(Ptr, Right.Ptr) == 0;

    }

    int String::operator!=(const String &Right) const

    {

  • return strcmp(Ptr, Right.Ptr) != 0;

    }

    int String::operator(const String &Right) const

    {

    return strcmp(Ptr, Right.Ptr) > 0;

    }

    int String::operator>=(const String &Right) const

    {

    return strcmp(Ptr, Right.Ptr) >= 0;

    }

    int String::operator

  • }

    String &String::operator()(int Index, int SubLength)

    {

    assert(Index >= 0 && Index < Length && SubLength>= 0);

    String *SubPtr = new String;

    assert(SubPtr != 0);

    if ((SubLength == 0) || (Index + SubLength > Length))

    SubPtr->Length = Length - Index + 1;

    else

    SubPtr->Length = SubLength + 1;

    delete SubPtr->Ptr;

    SubPtr->Ptr = new char[SubPtr->Length];

    assert(SubPtr->Ptr != 0);

    strncpy(SubPtr->Ptr, &Ptr[Index], SubPtr->Length);

    SubPtr->Ptr[SubPtr->Length] = '\0';

    return *SubPtr;

    }

    int String::GetLength() const

    {

    return Length;

    }

    ostream &operator

  • return Output;

    }

    istream &operator>>(istream &Input, String &S)

    {

    char Temp[100];

    Input >> setw(100) >> Temp;

    S = Temp;

    return Input;

    }

    int main()

    {

    String S1("happy");

    String S2(" birthday") ;

    String S3;

    cout

  • cout
  • cout
  • return 0;

    }

    PROGRAM 24: To mt lp " a thc mt bin "; bao gm " bc a thc " , " cc h s a thc "; Cc php ton : cng , tr, nhn a thc; tnh gi tr a thc vi gi tr c th ca bin nhp vo, ghi ra mn hnh kt qu cc php ton. Vit chung trnh s dng class trn, trong cha menu la cc php ton.

    SOLUTION 24:

    #include#include#include

    //************************************************************class node{ int heso; int mu; public :

    node *next; node(int hs,int m,node *n ):heso(hs),mu(m),next(n) {} int get_heso() { return heso; } int get_mu() { return mu; }

    };//*******************************************************************

    class dathuc{private :

    node *first,*last; int bac; public :

    dathuc() {

    first=NULL; last=NULL;

    } void chensau(int a,int b) { node *p=new node(a,b,NULL);

    if (first==NULL) { first=p;

  • last=p; } else { last->next=p; last=p; }

    } void nhap() ; void hienthi(); friend dathuc operator+(dathuc ob1,dathuc ob2); friend dathuc operator-(dathuc ob1,dathuc ob2); friend dathuc operator*(dathuc ob1,dathuc ob2);

    };

    //************************************************************

    void dathuc::nhap(){ int n,t; coutbac; for(int i=0;i

  • dathuc operator+(dathuc ob1,dathuc ob2) { dathuc ob3;

    node *p=ob1.first; node *q=ob2.first; int t; while ((p!=NULL) && (q!=NULL)) { if (p->get_mu() == q->get_mu())

    { t= p->get_heso() + q->get_heso(); ob3.chensau(t,p->get_mu()); p=p->next; q=q->next; }

    elseif (p->get_mu() > q->get_mu()){ t= p->get_heso(); ob3.chensau(t,p->get_mu()) ; p=p->next;}else

    { t= q->get_heso(); ob3.chensau(t,q->get_mu()); q=q->next;}

    } while (p!=NULL)

    { t= p->get_heso(); ob3.chensau(t,p->get_mu()); p=p->next; }

    while (q!=NULL) { t= q->get_heso(); ob3.chensau(t,q->get_mu()); q=q->next; }

    return ob3; }//********************************************************************** dathuc operator-(dathuc ob1,dathuc ob2) { dathuc ob3;

    node *p=ob1.first; node *q=ob2.first; int t; while ((p!=NULL) && (q!=NULL)) { if (p->get_mu() == q->get_mu())

    { t= p->get_heso() - q->get_heso(); ob3.chensau(t,p->get_mu()); p=p->next; q=q->next; }

    elseif (p->get_mu() > q->get_mu()){ t= p->get_heso(); ob3.chensau(t,p->get_mu()) ; p=p->next;

  • }else

    { t= q->get_heso(); ob3.chensau(-t,q->get_mu()); q=q->next;}

    } while (p!=NULL)

    { t= p->get_heso(); ob3.chensau(t,p->get_mu()); p=p->next; }

    while (q!=NULL) { t= q->get_heso(); ob3.chensau(t,q->get_mu()); q=q->next; }

    return ob3; }

    //********************************************************************

    void main(){ clrscr(); dathuc ob1,ob2,ob3; ob1.nhap(); ob2.nhap(); cout

  • public: void nhap() { coutx>>y; }

    void xuat() { cout

  • { clrscr(); toado a,b,c,d;// a.nhap();// b.nhap(); cin>>a; cin>>b; c=a+b; d=a-b; cout
  • friend ps operator+(int x, ps a)

    ps operator-(ps a) { ps kq; kq.t= t*a.m - a.t*m; kq.m= m * a.m; return kq; }

    ps operator*(ps a) { ps kq; kq.t= t*a.t; kq.m= m*a.m; return kq; }

    ps operator/(ps a) { ps kq; kq.t= t*a.m; kq.m= m*a.t; return kq; } friend ostream &operator(istream &is, ps &a)};

    ps operator+(int x, ps a){ ps kq; kq.t=a.t + x*a.m; kq.m=a.m; return kq;}

    ostream &operator

  • couta.t>>a.m; return is;}

    void main(){ clrscr(); int x; ps a,b; couta; coutb; cout

  • public: Nguoi(){} ~Nguoi(){}};class Khachhang: public Nguoi{ private: int m_maKH; char* m_nhomKH; public: Khachhang(){} ~Khachhang(){} void In(); void Nhap();};class Mahang{ private: int m_maHang; char* m_tenHang; int m_donGia; public: Mahang(){} ~Mahang(){} void In2(); void Nhap2();};using namespace std;void Khachhang::Nhap(){ cout
  • cout
  • system("cls"); cout