Results 1 to 7 of 7

Thread: tolong c++

  1. #1
    Senior Member peaceout's Avatar
    Join Date
    Jun 2009
    Posts
    160
    Post Thanks / Like

    tolong c++

    minta tolong otai2 syok semua. saya ada try buat satu c++ programming ni. sample output seperti di bawah :



    masalah yang saya hadapi sekarang ialah, saya tak berapa nak tahu la macam mana nak dapat kan GRAND TOTAL tu, ada siapa-siapa yang baik hati lagi permurah boleh tolong saya x? ni coding yang saya dah pun buat:


    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class contributor
    {
          protected:
                  string name, cname;
                  float payment, paper, metal, plastic;
          public:
                contributor()
                {
                         cout << "";
                         //cout << "                     = RECYCLE WEEK =                     " << endl;
                         //cout << "==========================================================" << endl;     
                }
                
    };
    
    class recycle : public contributor
    {
          private:
                  float total;
                  
          public:
                 recycle() : total(0) {}
                 
                 void getname()
                 {
                      cout << "\nEnter name         : ";
                      fflush(stdin);
                      getline(cin, name);
                     
                      cout << "Enter company name : ";
                      getline(cin, cname);
                 }
                
                void getkilo()
                {
                     cout << "\nEnter " << name << " contributions (kilo) under category :" << endl;
                      
                     cout << "        Paper    : ";
                     cin >> paper;
                      
                     cout << "        Metal    : ";
                     cin >> metal;
                      
                     cout << "        Plastics : ";
                     cin >> plastic;
                } 
                 
                void calc()
                {
                     payment = (paper * 0.20) + (metal * 0.50) + (plastic * 0.30); 
                }
                
                float calc_grandtotal(float tot)
                {
                      total = tot;
                      
                      return total = total + payment;
                }
                 
                void display()
                {
                     cout << name << "     " << cname  << "     " << paper << "     " << metal <<  "        " << plastic << "           " << payment  << endl;
                }
                
                void display_grandtotal()
                {
                     cout << "\nGRAND TOTAL: RM " << total << endl;     
                }
    };
    
    class recycleweek : public recycle
    {
          public:
                recycleweek()
                {
                         cout << "==============================================================" << endl;
                         cout << "                     = RECYCLE WEEK =                         " << endl;
                         cout << "==============================================================" << endl;
                }
    };
    
    class test : public recycle
    {
          public:
                 test()
                 {
                       cout << "==============================================================" << endl;
                       cout << "=                              RECEIPT                           =" << endl;
                       cout << "= Name       Company     Paper   Metal    Plastics   Payment(RM) =" << endl;
                       cout << "==============================================================" << endl;
                 }
    };
    
    int main()
    {
        float total;
        
        /*int no;
        
        cout << "How many contributor(s)? ";
        cin >> no;
            
        contributor *c;
        c = new contributor[no];
        
        for(int i = 0; i <= no - 1; i++)
        {
                (*(c+ +i)).getname();
                (*(c+ +i)).getkilo();        
        }
        
        delete [] c;*/
        recycleweek c;
        
        int no;
        
        cout << "How many contributor(s)? ";
        cin >> no;
        
        contributor cont;
        
        recycle *r;
        r = new recycle[no];
        
        for(int i = 0; i <= no - 1; i++)
        {
                cout << "\nContributor #" << i+1 << endl;
                cout << "--------------" << endl;
                
                (*(r+ +i)).getname();
                (*(r+ +i)).getkilo();
                (*(r+ +i)).calc();
                
                //(*(r+ +i)).calc_grandtotal();            
        }
        
        test t;
        
        for(int j = 0; j <= no - 1; j++)
        {
                (*(r+ +j)).display();
                
                (*(r+ +j)).calc_grandtotal(total);
        }
        
        (*(r)).display_grandtotal();
        
        
        
        
        
        //recycle tot;
        
        //tot.display_grandtotal();
        
        delete [] r;
                     
        system("PAUSE");
        return 0;
    }
    Last edited by peaceout; 04-01-13 at 05:08 PM.

  2. Likes iz_mal liked this post
  3. 29-12-12, 05:08 PM

  4. #2
    Senior Member peaceout's Avatar
    Join Date
    Jun 2009
    Posts
    160
    Post Thanks / Like
    alamak saya cuba masuk kan code saya, tapi asyik tak jadi je, kepada siapa-siapa yang sudi menolong, nanti saya akan pm kn apa yang dah pun saya buat. terima kasih.

  5. #3
    Senior Member iz_mal's Avatar
    Join Date
    Jul 2009
    Location
    Changkat lada~ :D
    Posts
    1,039
    Post Thanks / Like
    email kt aq..code nye..aq try tgk.. izmal91@gmail.com~


  6. #4
    Senior Member peaceout's Avatar
    Join Date
    Jun 2009
    Posts
    160
    Post Thanks / Like
    ok bro. da send da. klu ade pape yg x btl ke pape bgtau la ye. thnx bro.

  7. 29-12-12, 06:43 PM

  8. #5
    Senior Member private's Avatar
    Join Date
    Oct 2006
    Location
    ᶫᵒᵛᵉᵧₒᵤ
    Posts
    1,134
    Post Thanks / Like
    masukkan code dlm tag [code]...[ / c ode]

  9. #6
    Senior Member peaceout's Avatar
    Join Date
    Jun 2009
    Posts
    160
    Post Thanks / Like
    ak da try byk da bro letak [code] tu, tp xbole2. xp2. nnt ak try blek

  10. 04-01-13, 05:07 PM

  11. #7
    Senior Member peaceout's Avatar
    Join Date
    Jun 2009
    Posts
    160
    Post Thanks / Like

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com

    Server sponsored by SyokHost.Com
    Quote Originally Posted by private View Post
    masukkan code dlm tag [code]...[ / c ode]
    orait bro, da berjaya. haha. sblm2 ni ak try xdpt xtau la npe. haha

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •