²é¿´: 2066  |  »Ø¸´: 8

lhy317409772

Òø³æ (³õÈëÎÄ̳)

[ÇóÖú] Çó´óÉñ°ïæ½â´ð£¡ ÒÑÓÐ1È˲ÎÓë

À§ÈÅÁËÂù¾ÃÁË....Çó´óÉñ°ïæ½â´ð³ÌÐò´íÔÚÄÄÀï....ÒÉÎʶ¼ÔÚ³ÌÐòÅÔ±ß×¢ÊͳöÀ´ÁË¡£
ÐÂÊÖÌù£¬Ã»Ê²Ã´½ð±Ò£¬±§Ç¸....½ñºóŬÁ¦×¬½ð±Ò¡£
·Ç³£¸Ðл.....
Ô´³ÌÐòÈçÏ£º
//Í·Îļþ
#include<iostream>

class Port
{
private:
        char* brand;
        char style[20];
        int bottles;
public:
        Port(const char* br="none", const char* st="none", int b=0);
        Port(const Port& p);
        virtual ~Port() {delete [] brand;}
        Port& operator =(const Port& p);
        Port& operator+=(int b);
        Port& operator-=(int b);
        int BottleCount() const {return bottles;}
        virtual void Show() const;
        friend std:stream& operator<< (std:stream& os, const Port& p);
};

class VintagePort: public Port
{
private:
        char* nickname;
        int year;
public:
        VintagePort();
        VintagePort(const char* br, int b, const char* nn, int y);
        VintagePort(const VintagePort& vp);
        ~VintagePort() {delete [] nickname;}
        VintagePort& operator= (const VintagePort& vp);
        virtual void Show() const;
        friend std:stream& operator<< (std:stream& os, const VintagePort& vp);
};


//ʵÏÖÎļþ
#include<iostream>
#include<cstring>
#include"Port.h"

Port:ort(const char* br, const char* st, int b)
{
   brand=new char[strlen(br)+1];
   strcpy(brand, br);
   strncpy(style, st, 20);
   bottles=b;
}

Port:ort(const Port& p)
{
   brand=new char[strlen(p.brand)+1];
   strcpy(brand, p.brand);
   strncpy(style, p.style, 20);
   bottles=p.bottles;
}

Port& Port:perator = (const Port& p)
{
   if (this==&p)
           return *this;
   delete [] brand;
   brand=new char[strlen(p.brand)+1];
   strcpy(brand, p.brand);
   strncpy(style, p.style, 20);
   bottles=p.bottles;
   return *this;
}

Port& Port:perator += (int b)
{
   bottles+=b;
   return *this;
}

Port& Port:perator -=(int b)
{
   if (b<=bottles)
           bottles-=b;
   else
           std::cout<< "You can't take more bottles than we have!\n"
                    << "Operation cancelled!\n";
   return *this;
}

void Port::Show ()const
{
        std::cout<< "Brand: "<< brand
                     << "\nKind: "<< style
                         << "\nBottles: "<< bottles
                         <<std::endl;
}

std:stream& operator<< (std:stream& os, const Port& p)
{
   os << p.brand  << ", " << p.style << ", " << p.bottles;
   return os;
}

VintagePort::VintagePort()
ort()
{
   nickname=new char[5];
   strcpy(nickname, "none";
   year=0;
}

VintagePort::VintagePort(const char* br, int b, const char* nn, int y)
ort(br, "vintage", b)
{
   nickname=new char[strlen(nn)+1];
   strcpy(nickname, nn) ;
   year=y;
}

VintagePort::VintagePort(const VintagePort& vp)
ort(vp)
{
   nickname=new char[strlen(vp.nickname)+1];
   strcpy(nickname, vp.nickname);
   year=vp.year;
}

VintagePort& VintagePort:perator = (const VintagePort& vp)
{
   Port:perator = (vp);
   delete [] nickname;
   nickname=new char[strlen(vp.nickname)+1];
   strcpy(nickname, vp.nickname);
   year=vp.year;
   return *this;
}

void VintagePort::Show () const
{
        Port::Show ();
        std::cout<< "Nickname: " << nickname
                     << "\nYear: "  << year
                         << std::endl;
}

std:stream& operator<< (std:stream& os, const VintagePort& vp)
{
   os << (const Port& vp;         
   os << ", " << vp.nickname << ", " << vp.year;
   return os;
}


//Ö÷³ÌÐò
#include<iostream>
#include"Port.h"

int main()
{
        using std::cout;
        using std::cin;
        using std::endl;

        Port* pointer[10];
        pointer[0]=&Port("Lafite", "tawny", 27);
        pointer[1]=&Port("Latour", "ruby", 23);
        pointer[2]=&VintagePort("Haut-Brion", 35, "The Noble", 1875);
        pointer[3]=&VintagePort("Margaux", 56, "Old Velvet", 1898);

        for (int k=0;k<4;k++)       //Õâ¸ö²»ÊÇÖ÷³ÌÐòµÄ²¿·Ö£¬ÎÒÊÇÏëÓÃÀ´²âÊÔ£¬ÎÒÓûùÀàÖ¸Õëµ÷ÓÃShow()º¯ÊýµÄ½á¹û£¬
                                        //½á¹ûÓëÎÒÔ¤ÏëµÄ²»Ò»Ñù£¬ÎÒµÄShow£¨£©º¯ÊýÊÇÐéÄâµÄ£¬ÎÒÓûùÀàÖ¸Õ루Port*£©Ö¸ÏòÅÉÀà¶ÔÏó
        {
           pointer[k]->Show ();     //ÓÃpointer[0]->Show()µÄʱºò£¬Ó¦¸ÃÊǵ÷ÓÃPort::Show(),Õâ¸öµ÷ÓÃÊÇÕýÈ·µÄ£¬µ«ÊÇÎÒµÄbrand³ÉÔ±ÏÔʾȴ³öÏÖÁËÂÒÂ룬Õâ¸ö²»Ã÷°×ÊÇÔõô»ØÊ¡£
           cout << endl;            //ÓÃpointer[2]->Show()µÄʱºò£¬Ó¦¸ÃÊǵ÷ÓÃVintagePort::Show(),Õâ¸öµ÷ÓÃÊÇ´íµÄ£¬½á¹ûµ÷ÓõÄÊÇPort::Show()£¬¶øÇÒÓëÉÏÃæÒ»Ñùbrand³ÉÔ±ÏÔʾȴ³öÏÖÁËÂÒÂë¡£
        }

        Port& b=Port("Lafite", "tawny", 27);   //ÎÒÕâÀïÓûùÀàÒýÓÃÖ¸Ïò»ùÀà¶ÔÏó£¬ÓÃÒýÓõ÷ÓõÄʱºò£¬¾Í²»³öÏÖÂÒÂ룬ËùÒÔÎÒ¾õµÃÓ¦¸ÃÎÊÌâ³öÏÖÔÚÖ¸ÕëÉÏ
        b.Show ();                             //µ«ÊÇ£¬ÊµÔÚÏë²»µ½ÊÇΪʲô£¿  Çó½â´ð¡£
        cout << b <<endl;

        Port& a=VintagePort("Margaux", 56, "Old Velvet", 1898);
    a.Show();                  //»¹ÓÐÕâÀÎÒÓûùÀàÒýÓÃÖ¸ÏòÅÉÉú¶ÔÏó£¬ÔÚµ÷ÓÃShow()µÄʱºò£¬¾Íµ÷ÓõÄÊÇVintagePort::Show()£¬ÊÇÕýÈ·µÄ¡£
        cout << a << endl;          //µ«ÊÇÕâÀïÓÖ³öÏÖÁËÎÊÌ⣬ÎÒÖØÔØµÄcout << a£¬Ó¦¸ÃÐèÒªÏÔʾnicknameºÍyearµÄ£¬µ«ÊÇÈ´Óëcout << bÊÇÒ»ÑùµÄ,ÊÇÎÒµÄÖØÔØ³öÏÖÎÊÌâÁËô£¿£¿

        int choice,i=4;
        cout << "Do you want to take or save port(s)? (1 to take/2 to save/q to quit)";
        while (cin >> choice)
        {
           if (choice==1)
           {
              int kind=0,num=0;
                  cout << "Which brand do you need?(1:Lafite, 2:Latour, 3:Haut-Brion, 4:Margaux)";
                  cin >> kind;
                  cin.get();
                  switch (kind)
                  {
                  case 1:
                          {
                             cout << "How many bottles do you need?\n";
                                 cout << "There're " << pointer[0]->BottleCount() << " saved.\n";
                                 cin >> num;
                                 *pointer[0]-=num;
                                 pointer[0]->Show();
                                 break;
                          }
                  case 2:
                          {
                             cout << "How many bottles do you need?\n";
                                 cout << "There're " << pointer[1]->BottleCount() << " saved.\n";
                                 cin >> num;
                                 *pointer[1]-=num;
                                 pointer[1]->Show();
                                 break;
                          }
                  case 3:
                          {
                             cout << "How many bottles do you need?";
                                 cout << "There're " << pointer[2]->BottleCount() << " saved.\n";
                                 cin >> num;
                                 (Port&*pointer[2]-=num;    //»òÕßÖ±½ÓÓÃ*pointer[2]-=num;ÒòΪ-=µÄº¯²ÎΪPort&,¿ÉÒÔÖ¸ÏòVintagePort¡£
                                 pointer[2]->Show();
                                 break;
                          }
                  case 4:
                          {
                             cout << "How many bottles do you need?";
                                 cout << "There're " << pointer[3]->BottleCount() << " saved.\n";
                                 cin >> num;
                                 *pointer[3]-=num;
                                 pointer[3]->Show();
                                 break;
                          }
                  default: cout << "That's not a choice!\n";
                  }
           }
           else
           {
                  int num=0;
              cout << "Please enter the brand:";    //ÕâÀïÎÒÎÞ·¨½øÐÐÊäÈë¡£
                  char temp[50];
                  cin.getline(temp, 50);
                  cin.get();
          if (temp=="Lafite"     //ÎÒÕâÀïµÄ×Ö·û´®µÄ±È½ÏÓ¦¸ÃÊÇÓÐÎÊÌâµÄ£¬²»ÄÜÓÃ==Åжϡ£
                  {
                     cout << "Save bottles: ";
                         cin >> num;
             *pointer[0]+=num;
                         pointer[0]->Show();
                  }
                  else if (temp=="Latour"
                  {
                     cout << "Save bottles: ";
                         cin >> num;
             *pointer[1]+=num;
                         pointer[1]->Show();  
                  }
                  else if (temp=="Haut-Brion"
                  {
                     cout << "Save bottles: ";
                         cin >> num;
             *pointer[2]+=num;
                         pointer[2]->Show();
                  }
                  else if (temp=="Margaux"
                  {
                     cout << "Save bottles: ";
                         cin >> num;
             *pointer[3]+=num;
                         pointer[3]->Show();
                  }
                  else
                  {
                     cout << "Enter the style: ";
                         char s_temp[10];
                         cin.getline(s_temp, 10);
                         if (s_temp=="vintage"       //ÕâÀïµÄÅжÏÒ²ÓÐÎÊÌâ¡£
                         {
                            cout << "Enter the nickname: ";
                                char n_temp[20];
                                cin.getline(n_temp, 20);
                                cout << "Enter the year: ";
                                int y_temp;
                                cin >> y_temp;
                                cout << "Enter the bottles: ";
                                int b_temp;
                                cin >> b_temp;
                                pointer=&VintagePort(temp, b_temp, n_temp, y_temp);
                         }
                         else
                         {
                                cout << "Enter the bottles: ";
                int b_temp;
                                cin >> b_temp;
                           pointer=&Port(temp, s_temp, b_temp);
                         }
                  }
           }
           ++i;
           cout << "Do you want to take or save port(s)? (1 to take/2 to save/q to quit)";
        }
    char ch;
        cin.get();
        cout << "Do you want to see all the Port's information?(y/n) ";  //×îºó»¹ÓÐÕâÀÎÞ·¨½øÐÐÊäÈë....
        cin.get(ch);
        if (ch=='y'||ch=='Y')
           for (int c=0;c<i;++c)
                   cout << *pointer[c] << endl;
    cout << "Bye!\n";

        return 0;   

}

[ Last edited by lhy317409772 on 2014-1-8 at 22:49 ]
»Ø¸´´ËÂ¥

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

lhy317409772

Òø³æ (³õÈëÎÄ̳)

ÀïÃæµÄ·ûºÅÓеıä³ÉÁ˱íÇé....º¹....
   µ«ÊÇÖ±½Ó¸´ÖƵϰ£¬Ó¦¸ÃÊÇ¿ÉÒﱊȯÀ´µÄ°É£¡£¿
»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
2Â¥2014-01-08 22:50:57
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ľҶÇå·ç

ľ³æ (ÕýʽдÊÖ)

¡¾´ð°¸¡¿Ó¦Öú»ØÌû

¡ï ¡ï ¡ï ¡ï ¡ï
¸Ðл²ÎÓ룬ӦÖúÖ¸Êý +1
lhy317409772: ½ð±Ò+5, ¡ï¡ï¡ï¡ï¡ï×î¼Ñ´ð°¸, ÒѾ­½â¾öÁ˴󲿷ÖÎÊÌâ¡£ 2014-01-12 23:03:16
CODE:
#include<iostream>

class Port
{
private:
        char* brand;
        char style[20];
        int bottles;
public:
        Port(const char* br = "none", const char* st = "none", int b = 0);
        Port(const Port& p);
        virtual ~Port() { delete[] brand; }
        Port& operator =(const Port& p);
        Port& operator+=(int b);
        Port& operator-=(int b);
        int BottleCount() const { return bottles; }
        virtual void Show() const;
        friend std::ostream& operator<< (std ::ostream& os, const Port& p);
};

class VintagePort : public Port
{
private:
        char* nickname;
        int year;
public:
        VintagePort();
        VintagePort(const char* br, int b, const char* nn, int y);
        VintagePort(const VintagePort& vp);
        ~VintagePort() { delete[] nickname; }
        VintagePort& operator= (const VintagePort& vp);
        virtual void Show() const;
        friend std::ostream& operator<< (std::ostream& os, const VintagePort& vp);
};

CODE:
//ʵÏÖÎļþ
#include<iostream>
#include<cstring>
#include"Port.h"

Port::Port(const char* br, const char* st, int b)
{
        brand = new char[strlen(br) + 1];
        strcpy(brand, br);
        strncpy(style, st, 20);
        bottles = b;
}

Port::Port(const Port& p)
{
        brand = new char[strlen(p.brand) + 1];
        strcpy(brand, p.brand);
        strncpy(style, p.style, 20);
        bottles = p.bottles;
}

Port& Port::operator = (const Port& p)
{
        if (this == &p)
                return *this;
        delete [] brand;
        brand = new char[strlen(p.brand) + 1];
        strcpy(brand, p.brand);
        strncpy(style, p.style, 20);
        bottles = p.bottles;
        return *this;
}

Port& Port::operator += (int b)
{
        bottles += b;
        return *this;
}

Port& Port::operator -= (int b)
{
        if (b <= bottles)
                bottles -= b;
        else
                std::cout << "You can't take more bottles than we have!\n"
                << "Operation cancelled!\n";
        return *this;
}

void Port::Show()const
{
        std::cout << "Brand: " << brand
                << "\nKind: " << style
                << "\nBottles: " << bottles
                << std::endl;
}

std::ostream& operator<< (std::ostream& os, const Port& p)
{
        os << p.brand << ", " << p.style << ", " << p.bottles;
        return os;
}

VintagePort::VintagePort()
:Port()
{
        nickname = new char[5];
        strcpy(nickname, "none");
        year = 0;
}

VintagePort::VintagePort(const char* br, int b, const char* nn, int y)
:Port(br, "vintage", b)
{
        nickname = new char[strlen(nn) + 1];
        strcpy(nickname, nn);
        year = y;
}

VintagePort::VintagePort(const VintagePort& vp)
:Port(vp)
{
        nickname = new char[strlen(vp.nickname) + 1];
        strcpy(nickname, vp.nickname);
        year = vp.year;
}

VintagePort& VintagePort::operator = (const VintagePort& vp)
{
        Port::operator = (vp);
        delete [] nickname;
        nickname = new char[strlen(vp.nickname) + 1];
        strcpy(nickname, vp.nickname);
        year = vp.year;
        return *this;
}

void VintagePort::Show() const
{
        Port::Show();
        std::cout << "Nickname: " << nickname
                << "\nYear: " << year
                << std::endl;
}

std::ostream& operator<< (std::ostream& os, const VintagePort& vp)
{
        os << (const Port&) vp;
        os << ", " << vp.nickname << ", " << vp.year;
        return os;
}

CODE:
//Ö÷³ÌÐò
#include<iostream>
#include"Port.h"

int main()
{
        using std::cout;
        using std::cin;
        using std::endl;

        Port* pointer[10];
        //pointer[0] = &Port("Lafite", "tawny", 27);
        //pointer[1] = &Port("Latour", "ruby", 23);
        //pointer[2] = &VintagePort("Haut-Brion", 35, "The Noble", 1875);
        //pointer[3] = &VintagePort("Margaux", 56, "Old Velvet", 1898);
        Port pa = Port("Lafite", "tawny", 27);
        Port pb = Port("Latour", "ruby", 23);
        VintagePort va = VintagePort("Haut-Brion", 35, "The Noble", 1875);
        VintagePort vb = VintagePort("Margaux", 56, "Old Velvet", 1898);
        pointer[0] = &pa; // Ö»ÄܶÔ×óֵȡµØÖ·£¬ÏñÄãÄÇÑùÈ¡µØÖ·ÊÇ·Ç·¨µÄ£¬ÆäʵPortµÄÎö¹¹º¯Êý¶¼ÒѾ­µ÷ÓÃ
        pointer[1] = &pb;
        pointer[2] = &va;
        pointer[3] = &vb;

        for (int k = 0; k<4; k++)
        {
                pointer[k]->Show();
                cout << endl;
        }

        //Port& b = Port("Lafite", "tawny", 27);
        Port prefb = Port("Lafite", "tawny", 27);
        Port &b = prefb;
        // »òÕßÄã¿ÉÒÔÖ±½ÓÓÃPort &&b = Port("Lafite", "tawny", 27);
        // »òÕßconst Port &b = Port("Lafite", "tawny", 27);
        // Ö»Óг£Á¿ÒýÓúÍÓÒÖµÒýÓÿÉÒÔ°ó¶¨ÔÚÒ»¸öÁÙʱ±äÁ¿ÉÏ£¬Äã¿´µ½Ã»¸øÄ㱨´í²»´ú±íÄãµÄд·¨
        // ¾ÍÕæµÄûÓдíÎó£¬Ö»ÊÇ΢ÈíµÄ±àÒëÆ÷ûÓÐÖ§³Ö±ê×¼¶øÒÑ
        b.Show();
        cout << b << endl;

        Port&& a = VintagePort("Margaux", 56, "Old Velvet", 1898);//ͬÉÏ
        a.Show();
        cout << a << endl;// ûÃ÷°×ÄãÕâÔõÃ´ÖØÔØÁË£¬operator(ostream, const Port&)Ö±½Ó´Ó·Çconstµ½constת»»µÄÆ¥Å䣬ûÓÐÈκÎÎÊÌâ
       
        int choice, i = 4;
        cout << "Do you want to take or save port(s)? (1 to take/2 to save/q to quit)";
        while (cin >> choice)
        {
                if (choice == 1)
                {
                        int kind = 0, num = 0;
                        cout << "Which brand do you need?(1:Lafite, 2:Latour, 3:Haut-Brion, 4:Margaux)";
                        cin >> kind;
                        cin.get();
                        switch (kind)
                        {
                        case 1:
                        {
                                          cout << "How many bottles do you need?\n";
                                          cout << "There're " << pointer[0]->BottleCount() << " saved.\n";
                                          cin >> num;
                                          *pointer[0] -= num;
                                          pointer[0]->Show();
                                          break;
                        }
                        case 2:
                        {
                                          cout << "How many bottles do you need?\n";
                                          cout << "There're " << pointer[1]->BottleCount() << " saved.\n";
                                          cin >> num;
                                          *pointer[1] -= num;
                                          pointer[1]->Show();
                                          break;
                        }
                        case 3:
                        {
                                          cout << "How many bottles do you need?";
                                          cout << "There're " << pointer[2]->BottleCount() << " saved.\n";
                                          cin >> num;
                                          (Port*)pointer[2] -= num;    //»òÕßÖ±½ÓÓÃ*pointer[2]-=num;ÒòΪ-=µÄº¯²ÎΪPort&,¿ÉÒÔÖ¸ÏòVintagePort¡£
                                          pointer[2]->Show();
                                          break;
                        }
                        case 4:
                        {
                                          cout << "How many bottles do you need?";
                                          cout << "There're " << pointer[3]->BottleCount() << " saved.\n";
                                          cin >> num;
                                          *pointer[3] -= num;
                                          pointer[3]->Show();
                                          break;
                        }
                        default: cout << "That's not a choice!\n";
                        }
                }
                else
                {
                        int num = 0;
                        cout << "Please enter the brand:";// << endl;    //ÕâÀïÎÒÎÞ·¨½øÐÐÊäÈë¡£
                        char temp[50];
                        cin.get();
                        cin.getline(temp, 50);// ÄãԭʼµÄ×ö·¨ÊÇÖ±½Ó»ñȡеÄÒ»ÐУ¬µ±È»µÃµ½µÄ¾ÍÊÇ'\n'£¬Ã»ÓÐʲô²»ÄÜÊäÈëµÄ
                        //cin.get();
                        if (strcmp(temp,"Lafite") == 0)     //ÎÒÕâÀïµÄ×Ö·û´®µÄ±È½ÏÓ¦¸ÃÊÇÓÐÎÊÌâµÄ£¬²»ÄÜÓÃ==Åжϡ£
                        {
                                cout << "Save bottles: ";
                                cin >> num;
                                *pointer[0] += num;
                                pointer[0]->Show();
                        }
                        else if (strcmp(temp,"Latour") == 0)
                        {
                                cout << "Save bottles: ";
                                cin >> num;
                                *pointer[1] += num;
                                pointer[1]->Show();
                        }
                        else if ( strcmp(temp,"Haut-Brion") == 0)
                        {
                                cout << "Save bottles: ";
                                cin >> num;
                                *pointer[2] += num;
                                pointer[2]->Show();
                        }
                        else if ( strcmp(temp,"Margaux") == 0)
                        {
                                cout << "Save bottles: ";
                                cin >> num;
                                *pointer[3] += num;
                                pointer[3]->Show();
                        }
                        else
                        {
                                cout << "Enter the style: ";
                                char s_temp[10];
                                cin.getline(s_temp, 10);
                                if ( strcmp(s_temp,"vintage") == 0)       //ÕâÀïµÄÅжÏÒ²ÓÐÎÊÌâ¡£
                                {
                                        cout << "Enter the nickname: ";
                                        char n_temp[20];
                                        cin.getline(n_temp, 20);
                                        cout << "Enter the year: ";
                                        int y_temp;
                                        cin >> y_temp;
                                        cout << "Enter the bottles: ";
                                        int b_temp;
                                        cin >> b_temp;
                                        pointer[5] =  new VintagePort(temp, b_temp, n_temp, y_temp);//²»ÖªµÀÄãÏëÓÃÄÄÒ»¸öpointer£¬ÔÝʱÓÃ5£¬×Ô¼º¸Ä
                                }
                                else
                                {
                                        cout << "Enter the bottles: ";
                                        int b_temp;
                                        cin >> b_temp;
                                        pointer[5] = new Port(temp, s_temp, b_temp);//²»ÖªµÀÄãÏëÓÃÄÄÒ»¸öpointer
                                }
                        }
                }
                ++i;
                cout << "Do you want to take or save port(s)? (1 to take/2 to save/q to quit)";
        }
        char ch;
        cin.get();
        cout << "Do you want to see all the Port's information?(y/n) ";  //×îºó»¹ÓÐÕâÀÎÞ·¨½øÐÐÊäÈë....
        cin.get(ch);
        if (ch == 'y' || ch == 'Y')
        for (int c = 0; c<i; ++c)
                cout << *pointer[c] << endl;
        cout << "Bye!\n";
       
        return 0;

}

www.cvdelver.com
3Â¥2014-01-09 22:29:39
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

lhy317409772

Òø³æ (³õÈëÎÄ̳)

ÒýÓûØÌû:
3Â¥: Originally posted by ľҶÇå·ç at 2014-01-09 22:29:39
#include<iostream>

class Port
{
private:
        char* brand;
        char style;
        int bottles;
public:
        Port(const char* br = "none", const char* st = "none", int b = 0);
        Por ...

·Ç³£¸Ðл£¬ÎÊÌâÒѾ­½â¾öÁ˾ø´ó²¿·Ö....
ÕâÀﻹÓÐһЩÒÉÎÊ£¬Ï£ÍûÄܵõ½½â¾ö£º
1.ÈçºÎ·¢´úÂëÌû×Ó£¬ÎҵķûºÅ±ä³É±íÇéÁË£¬×¢Òâµ½ÄúµÄ´úÂëÍâÃæ´©ÁËÂí¼×£ºcode,ÇëÎÊÔõô×öµ½µÄ....ÎÒÊÇÐÂÈË£¬ºÙºÙ¡£
2.Port &&b = Port("Lafite", "tawny", 27);    ÕâÀïºÃÏñÓдíÎ󣬱¨´í ÒýÓÃÎÞ·¨¸³Öµ¸øÒýÓÃ.....
Äú˵£¬Ö»Óг£Á¿ÒýÓúÍÓÒÖµÒýÓÿÉÒÔ°ó¶¨ÔÚÒ»¸öÁÙʱ±äÁ¿ÉÏ£¬ÎÒдµÄÊÇPort& b = Port("Lafite", "tawny", 27);ÎÒ°Ñ×óÖµÒýÓðó¶¨ÔÚÁËÁÙʱ±äÁ¿ÉÏ(ÇëÎÊ£¬Äú˵ÊDz»¹æ·¶µÄ£¬ÕâÀïÊÇΪʲô²»¹æ·¶£¿)£¬const Port &b = Port("Lafite", "tawny", 27);Õâ¸öÊǰѳ£Á¿ÒýÓðó¶¨ÔÚÁÙʱ±äÁ¿ÉÏ£¬µ«ÊÇÇëÎÊһϰÑÓÒÖµÒýÓðó¶¨ÔÚÁÙʱ±äÁ¿ÉÏÊÇʲôÀý×Ó£¿
3. pointer[5] =  new VintagePort(temp, b_temp, n_temp, y_temp);  ÕâÀïΪʲôҪnewÒ»¸öVintagePort£¿ »¹ÊÇÒòΪֻÄܶÔ×óÖµ½øÐÐÈ¡µØÖ·²Ù×÷£¿Èç¹û½ö½öÊÇ Port("Lafite", "tawny", 27);ÕâÀï´´½¨µÄÊÇÁÙʱ±äÁ¿Ã´£¿£¿
4.        cout << "Do you want to see all the Port's information?(y/n) ";  //×îºó»¹ÊÇÎÞ·¨ÊäÈë¡£
        char infor;
        cin.get();//ÎÒÔÚÕâÀïÒѾ­ÓÃÕâ¸ö°Ñcin >> choice;ÁôϵÄ\n¸øÏú»ÙÁË£¬µ«ÊÇÏÂÃæÒ»¸ö¶ÁÈ¡»¹ÊDz»Äܹ¤×÷¡£
        cin.get(infor);
        if (infor=='y'||infor=='Y')
           for (int c=0;c<i;++c)
                   cout << *pointer[c] << endl;
        else
        cout << "Bye!\n";
Ê®·Ö¸Ðл¡£
»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
4Â¥2014-01-12 23:00:23
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

lhy317409772

Òø³æ (³õÈëÎÄ̳)

ÒýÓûØÌû:
4Â¥: Originally posted by lhy317409772 at 2014-01-12 23:00:23
·Ç³£¸Ðл£¬ÎÊÌâÒѾ­½â¾öÁ˾ø´ó²¿·Ö....
ÕâÀﻹÓÐһЩÒÉÎÊ£¬Ï£ÍûÄܵõ½½â¾ö£º
1.ÈçºÎ·¢´úÂëÌû×Ó£¬ÎҵķûºÅ±ä³É±íÇéÁË£¬×¢Òâµ½ÄúµÄ´úÂëÍâÃæ´©ÁËÂí¼×£ºcode,ÇëÎÊÔõô×öµ½µÄ....ÎÒÊÇÐÂÈË£¬ºÙºÙ¡£
2.Port && ...

ßÀ...ÁíÍâ.....×îºóÒ»¸öÊä³öËùÓÐÐÅÏ¢£¬ÎÒ·¢¾õËÆºõÓÐÎÊÌâ...ÎÒÓõÄÊÇ
<<*pointer[c] ,ÕâÀïËùÓеͼӦ¸Ãµ÷ÓõÄÊÇ<< (Port)£¬ËùÒÔÎÒµÄVintagePortµÄÐÅÏ¢¹À¼Æ»áÏÔʾ²»ÍêÈ«...ÕâÀïÓÐûÓа취Äܹ»½â¾ö£¿£¿
»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
5Â¥2014-01-12 23:12:01
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ľҶÇå·ç

ľ³æ (ÕýʽдÊÖ)

ÒýÓûØÌû:
4Â¥: Originally posted by lhy317409772 at 2014-01-12 23:00:23
·Ç³£¸Ðл£¬ÎÊÌâÒѾ­½â¾öÁ˾ø´ó²¿·Ö....
ÕâÀﻹÓÐһЩÒÉÎÊ£¬Ï£ÍûÄܵõ½½â¾ö£º
1.ÈçºÎ·¢´úÂëÌû×Ó£¬ÎҵķûºÅ±ä³É±íÇéÁË£¬×¢Òâµ½ÄúµÄ´úÂëÍâÃæ´©ÁËÂí¼×£ºcode,ÇëÎÊÔõô×öµ½µÄ....ÎÒÊÇÐÂÈË£¬ºÙºÙ¡£
2.Port && ...

1 ¸ß¼¶»Ø¸´¿ÉÒÔ²åÈë´úÂë
2 ÓÒÖµÒýÓÃÐèÒªc++11Ö§³Ö£¬±àÒëµÄʱºò´øÉÏÑ¡Ïvs2012ºÍ2013¶¼ÊÇÖ±½Ó±àÒë¾ÍÐÐÁË£¬ÒªÊÇûÓÐÕâô¸ß°æ±¾µÄ±àÒëÆ÷ÓÖ²»ÏëÓÃg++£¬ÄÇÖ±½Ó¸Ä³Éconst Port&¾ÍÐÐÁË£»ÖÁÓÚÁÙʱ±äÁ¿µÄÎÊÌâÎÒÖ»ÄÜ˵ºÃºÃµÄÕÒ±¾c++µÄÊé¿´¿´£»
3 ÎÒÖ»ÄÜ˵ÄÇȷʵÊǸöÁÙʱ±äÁ¿£¬ÎÒ´úÂëÀïÃæÃ»ÓÐдÊÍ·ÅÄÚ´æµÄ²¿·Ö£¬ÒòΪÎÒ²»ÖªµÀÄãµ½µØÊÇÏëÓÃ5»¹ÊǶàÉÙ£¬ÐèÒª×Ô¼º°ÑÕⲿ·Ö´úÂë²¹ÉÏ£»
4 °ÑquitµÄ²¿·ÖÖ±½Ó¸Ä³É3»òÕ߯äËüÊý×Ö£¬cin >> choice£¬ ÄãÊäÈëÒ»¸ö×ÖĸËãʲôѽ£»
5 °ÑÊä³öµÄ²¿·Öд³ÉÐ麯Êý£¬»òÕßÓÃRTTI²é¿´ÊDz»ÊÇÅÉÉúÀ࣬Êǵϰ½øÐÐת»»ÔÙÊä³ö¡£
www.cvdelver.com
6Â¥2014-01-13 13:41:00
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

lhy317409772

Òø³æ (³õÈëÎÄ̳)

ÒýÓûØÌû:
6Â¥: Originally posted by ľҶÇå·ç at 2014-01-13 13:41:00
1 ¸ß¼¶»Ø¸´¿ÉÒÔ²åÈë´úÂë
2 ÓÒÖµÒýÓÃÐèÒªc++11Ö§³Ö£¬±àÒëµÄʱºò´øÉÏÑ¡Ïvs2012ºÍ2013¶¼ÊÇÖ±½Ó±àÒë¾ÍÐÐÁË£¬ÒªÊÇûÓÐÕâô¸ß°æ±¾µÄ±àÒëÆ÷ÓÖ²»ÏëÓÃg++£¬ÄÇÖ±½Ó¸Ä³Éconst Port&¾ÍÐÐÁË£»ÖÁÓÚÁÙʱ±äÁ¿µÄÎÊÌâÎÒÖ»ÄÜ˵ ...

àÅ....ÎÒ×Ô¼ºÓóÌÐò²âÊÔÁËһϣ¬Õâ¸öÊǸöÁÙʱ±äÁ¿£¬´´½¨ºóÂíÉϵ÷ÓÃÁËÎö¹¹º¯Êý......
ßÀ£¬ÎÒÕâÀïÓÃcin >> choiceÊÇÏë°ÑcinµÄ·µ»ØÖµµ±×÷ÅжÏÌõ¼þ£¬ÒòΪµ±ÎÒÊäÈëÊý×ÖµÄʱºòcin·µ»Ø1½øÈëÑ­»·£¬ÊäÈë·ÇÊý×ÖµÄʱºò¾Í¶Áȡʧ°Ücin·µ»Ø0£¬Í˳öÑ­»·¡£   ÎÒ°´×ÅÄúµÄÌáʾÐÞ¸ÄÁ˳ÌÐò£¬ÓÃbreakÀ´Ìø³öÑ­»·....³ÌÐòȷʵÊÇ¿ÉÒÔÔËÐÐÁË£¬×îºóÒ²¿ÉÒÔ½øÐÐÊäÈëÁË...µ«ÊÇÎÒ²»Ã÷°×ÓÃcin >> choiceÀ´½øÐÐÊäÈ룬Ϊʲô»áÓ°Ïìµ½ºóÃæÒ»¸ö×Ö·ûµÄÊäÈ룬ÎÒ¾õµÃÕâÀïÓ¦¸ÃÊÇ×îºóÒ»¸öÊäÈë¶ÁÈ¡ÁËǰ·½µÄq»òÕß\n£¬ËùÒÔÖ±½ÓÅжÏΪ·ÇyËùÒÔÎÞ·¨ÏÔʾËùÓÐÐÅÏ¢.....
È»ºó£¬Ö»ÓгÉÔ±º¯Êý²Å¿ÉÒÔд³ÉÐ麯Êý£¬Èç¹ûÎÒÕâÀïд³ÉÐ麯ÊýÁ˾ÍÖ»ÄÜÓÐÒ»¸öº¯²Î£¬Õâôд£ºvirtual std:stream& operator << (std:stream & os) {os << *this;£¨ps:Ô­À´µÄ<<û±ä£¬ÕâÀïµ÷ÓÃÔ­À´µÄÓÑÔª£© return os;}£¬ËùÒÔÎÒÔÚÊä³öµÄʱºòÕâôµ÷ÓÃ*pointer[c]<< cout << endl;¿´ÆðÀ´Âù±ðŤ£¬µ«Êǽá¹ûȷʵÊÇÕýÈ·µÄ....ÇëÎÊ£¬Õâ¸ö·½·¨Äܲ»ÄܸĽøÊ¹µÃÓà cout << *opinter[c]£»À´µ÷Óã¿£¿
»¹ÓÐÄú˵µÄRTTI×Ô¼º»¹Ã»ÓÐÉæ¼°µ½£¬µ«ÊÇÎÒÔÚÏëÈç¹û¼ì²é³öÊÇÅÉÉú¶ÔÏ󣬰ѻùÀà*pointer[c]½øÐÐת»»ÁËÊä³ö£¬Õâ¸öÆñ²»ÊÇÏòÏÂת»»£¬ÀíÂÛÉÏÊDz»ÔÊÐíµÄ£¬ÒòΪ¿ÉÄܶªÊ§Êý¾Ý£¬ÄѵÀÕâÀïµÄ¿ÉÒÔô£¿£¿
×îºó£¬ÎÒĿǰ²ÅѧϰC++²»¾Ã£¬Ê¹ÓõĽ̲ÄÊÇ¡¶C++ primer Plus£¨µÚÎå°æ£©¡·£¬¾õµÃ»¹²»´í£¬¼´½«°ÑÕâ±¾Êé¿´Í꣬ÕâÀïÏ£ÍûÄúÄܸøµãÖ¸µ¼£¬ÏëÖªµÀ¿´ÍêÕâ±¾Êéºó¿ÉÒÔ¼ÌÐø¿´¿´±ðµÄʲô±È½ÏºÃµÄ½Ì²ÄÀ´ÉîÈëѧϰ....
·Ç³£¸ÐлÄú²»ÑáÆä·³µÄÖ¸µ¼....
»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
7Â¥2014-01-13 15:19:12
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

ľҶÇå·ç

ľ³æ (ÕýʽдÊÖ)

ÒýÓûØÌû:
7Â¥: Originally posted by lhy317409772 at 2014-01-13 15:19:12
àÅ....ÎÒ×Ô¼ºÓóÌÐò²âÊÔÁËһϣ¬Õâ¸öÊǸöÁÙʱ±äÁ¿£¬´´½¨ºóÂíÉϵ÷ÓÃÁËÎö¹¹º¯Êý......
ßÀ£¬ÎÒÕâÀïÓÃcin >> choiceÊÇÏë°ÑcinµÄ·µ»ØÖµµ±×÷ÅжÏÌõ¼þ£¬ÒòΪµ±ÎÒÊäÈëÊý×ÖµÄʱºòcin·µ»Ø1½øÈëÑ­»·£¬ÊäÈë·ÇÊý×ÖµÄʱºò ...

дÐ麯Êý£¬È»ºóÔÚÖØÔØµÄÊä³ö²Ù×÷·ûÖе÷Óã»
ÖªµÀÕýÈ·µÄÀàÐÍÇé¿öÏÂÏòÏÂת»»Ö¸ÕëûÓÐʲôÎÊÌâµÄ£¬ÀíÂÛÉÏÔõô²»»á²»ÔÊÐí£»
ºÃºÃµÄ¿´<C++ Primer, 5th> ºÍаæµÄ¡¶C++ Programming Language¡·£¬¿´¶®ÕâÁ½±¾¶ÔÓÚÓïÑÔÌØÐÔÀ´Ëµ×ãÒÓ¡£ÔÙÍùºó¾ÍÊÇÉè¼ÆÄ£Ê½£¬×¨Òµ¿âµÄʹÓÃÕâЩÌá¸ßµÄ²¿·ÖÁË¡£ÎÒ»¹ÊÇÄǾ仰£¬Ò»ÈºÈË·Å×ÅÕâÁ½±¾×î¾­µäµÄ²»¿´£¬µ½´¦Ëµ²»ÖªµÀÔõôѧC++¡£ÈκÎÓïÑÔ¶¼Ò»Ñù£¬ÒªÏëѧ£¬ÏȰѾ­µä¿´ÁËÔÙ˵¡£
www.cvdelver.com
8Â¥2014-01-14 16:39:07
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

lhy317409772

Òø³æ (³õÈëÎÄ̳)

ÒýÓûØÌû:
8Â¥: Originally posted by ľҶÇå·ç at 2014-01-14 16:39:07
дÐ麯Êý£¬È»ºóÔÚÖØÔØµÄÊä³ö²Ù×÷·ûÖе÷Óã»
ÖªµÀÕýÈ·µÄÀàÐÍÇé¿öÏÂÏòÏÂת»»Ö¸ÕëûÓÐʲôÎÊÌâµÄ£¬ÀíÂÛÉÏÔõô²»»á²»ÔÊÐí£»
ºÃºÃµÄ¿´<C++ Primer, 5th> ºÍаæµÄ¡¶C++ Programming Language¡·£¬¿´¶®ÕâÁ½±¾¶ÔÓÚ ...

Okay....ллָµ¼...¿´À´ÎÒµÎѧϰ·½Ïò»¹ÊǶԵΣ¡  ºÇºÇ
»ñµÃ֪ʶµÄΨһ°ì·¨£¬¾ÍÊÇ¿¿Çഺȥ»»È¡¡£
9Â¥2014-01-27 18:01:01
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ lhy317409772 µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 290Çóµ÷¼Á +5 ¿×Ö¾ºÆ 2026-03-12 10/500 2026-03-16 09:01 by ÓàêÍ&
[¿¼ÑÐ] Ò»Ö¾Ô¸985£¬±¾¿Æ211£¬0817»¯Ñ§¹¤³ÌÓë¼¼Êõ319Çóµ÷¼Á +4 Liwangman 2026-03-15 4/200 2026-03-16 08:01 by wang_dand
[¿¼ÑÐ] 327Çóµ÷¼Á +6 ʰ¹âÈÎȾ 2026-03-15 11/550 2026-03-15 22:47 by ʰ¹âÈÎȾ
[¿¼ÑÐ] ÖпÆÔº²ÄÁÏ273Çóµ÷¼Á +3 yzydy 2026-03-15 3/150 2026-03-15 21:15 by ms629
[¿¼ÑÐ] 0703 ÎïÀí»¯Ñ§µ÷¼Á +3 ÎÒ¿ÉÒÔÉϰ¶µÄ¶Ô 2026-03-13 3/150 2026-03-15 17:32 by СÎïÀí»¯Ñ§
[¿¼ÑÐ] 289Çóµ÷¼Á +5 ²½´¨¿á×Ï123 2026-03-11 5/250 2026-03-15 00:45 by kruisytel
[¿¼ÑÐ] 080500£¬²ÄÁÏѧ˶302·ÖÇóµ÷¼ÁѧУ +4 ³õʶ¿ÉÀÖ 2026-03-14 5/250 2026-03-14 21:08 by peike
[¿¼ÑÐ] 304Çóµ÷¼Á +5 СÐÜjoy 2026-03-14 5/250 2026-03-14 21:07 by peike
[¿¼ÑÐ] ±¾¿ÆÄϾ©´óѧһ־Ը´¨´óҩѧ327 +3 ÂóÌï¸ûÕß 2026-03-14 3/150 2026-03-14 20:04 by ÍâÐÇÎÄÃ÷
[¿¼ÑÐ] Öпƴó²ÄÁÏר˶319Çóµ÷¼Á +3 ÃÏöβÄÁÏ 2026-03-13 3/150 2026-03-14 18:10 by houyaoxu
[¿¼ÑÐ] 331Çóµ÷¼Á£¨0703Óлú»¯Ñ§ +5 ZY-05 2026-03-13 6/300 2026-03-14 10:51 by Jy?
[¿¼ÑÐ] ²ÄÁÏר˶288·ÖÇóµ÷¼Á Ò»Ö¾Ô¸211 +4 ÔÚ¼ÒÏëÄã 2026-03-11 4/200 2026-03-13 22:49 by JourneyLucky
[¿¼ÑÐ] 085600µ÷¼Á +5 ÑúÑú123sun 2026-03-12 5/250 2026-03-13 22:06 by ÐÇ¿ÕÐÇÔÂ
[¿¼ÑÐ] 0703»¯Ñ§Ò»Ö¾Ô¸211 ×Ü·Ö320Çóµ÷¼Á +5 Â꿨°Í¿¨°¡¹þ 2026-03-11 5/250 2026-03-13 21:40 by JourneyLucky
[¿¼ÑÐ] 274Çóµ÷¼Á0856²ÄÁÏ»¯¹¤ +12 z2839474511 2026-03-11 13/650 2026-03-13 10:39 by peike
[¿¼ÑÐ] Çóµ÷¼Á ×ÊÔ´Óë»·¾³ 285 +3 δÃû¿¼Éú 2026-03-10 3/150 2026-03-13 10:31 by houyaoxu
[¿¼ÑÐ] »¯¹¤Ñ§Ë¶306Çóµ÷¼Á +9 42838695 2026-03-12 9/450 2026-03-13 10:16 by houyaoxu
[¿¼ÑÐ] 283Çóµ÷¼Á£¬²ÄÁÏ¡¢»¯¹¤½Ô¿É +8 ËÕ´òË®7777 2026-03-11 10/500 2026-03-13 09:06 by Linda Hu
[¿¼ÑÐ] 333Çóµ÷¼Á +3 152697 2026-03-12 4/200 2026-03-13 07:08 by Iveryant
[¿¼ÑÐ] Êý¶þÓ¢¶þ309·ÖÇëÇóµ÷¼Á +3 dtdxzxx 2026-03-09 4/200 2026-03-09 19:56 by yuningshan
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û