heLppp

This is a discussion on heLppp within the C++ Programming forums, part of the General Programming Boards category; hi.. Here is my c++ code: how can i access Average member in main().. Can I access it ▀y a ...

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    9

    Angry heLppp

    hi..
    Here is my c++ code:
    how can i access Average member in main()..
    Can I access it ▀y a class mem▀er function?

    Code:
    #include <iostream>
    using namespace std;
    class Soru1{
        public:
        void data();
        int min();
        int max();
        void print();
        Soru1();
    
       double Average();
        int *dondur();
        int size_dondur();
    
        private:
        int size,*q,int Average;
    };
    int *Soru1::dondur()
    {
        return q;
    }
    int Soru1::size_dondur()
    {
        return size;
    }
    void Soru1::data()
    {
        cout<<"size\n";
        cin>>size;
        q=new int[size];
        cout<<"Dizi elemanlari\n";
        for(int i=0;i<size;i++)
        cin>>q[i];
    }
    Soru1::Soru1()
    {
        size=0;
        q=0;
    }
    int Soru1::min()
    {
        int min=q[0];
        for(int i=1;i<size;i++)
        if(q[i]<min)
        min=q[i];
    
        return min;
    }
    double Soru1::Average()
    {
        int sum=0;
        for(int i=0;i<size;i++)
        sum+=q[i];
        return sum/size;
    }
    int Soru1::max()
    {
        int max=q[0];
        for(int i=1;i<size;i++)
        if(q[i]>max)
        max=q[i];
        return max;
    }
    
    void Soru1::print()
    {
        cout<<"dizi elemanlari\n";
        for(int i=0;i<size;i++)
        cout<<q[i]<<"\t";
        cout<<endl;
    }
    class Soru2:public Soru1{
        public:
        int Data_Size();
        void Offset(int,int);
        private:
        int *k,size2;
    };
    void Soru2::Offset(int a,int b)
    {
       k=Soru1::dondur();
    
    
        k[a]+=b;
    }
    int Soru2::Data_Size()
    {
          size2=Soru1::size_dondur();
          return size2;
    }
    void test(Soru1& T)
    {T.Average();}
    
    int main()
    {
        Soru1 B;
        Soru2 A;
        A.data();
        B.data();
        for(int i=0;i<A.Data_Size();i++)
        if(A.Average<B.Average)
        A.Offset(i,10);
        else
        A.Offset(i,5);
        A.print();
    test(A);
        system("pause");
    }

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Listen to your compiler:

    Code:
    test.cpp:16: error: declaration of `int Soru1::Average'
    test.cpp:11: error: conflicts with previous declaration `double Soru1::Average()
    You can't have two class members with the same name (except with function overloading). Rename the int or the function.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    9
    I used A.Average() and B.Average() instead of Average which is private.. And It run.. ▀ut now I want to use private Average instead of function Average().... This is one of my exam question..
    Code:
    int main()
    {
        Soru1 B;
        Soru2 A;
        A.data();
        B.data();
        for(int i=0;i<A.Data_Size();i++)
        if(A.Average()<B.Average())
        A.Offset(i,10);
        else
        A.Offset(i,5);
        A.print();
    test(A);
        system("pause");
    }

  4. #4
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,239
    Quote Originally Posted by MoraL View Post
    ▀ut now I want to use private Average instead of function Average
    You can't. That's the entire point of private. Perhaps the exam question is asking you to explain why this is, not asking you to make a call to a private function (because that's impossible).
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    9
    ok Thanks..
    Sorry I have another question.. I want to compare two array which have diffrent sizes.. and If some of second array's elemenths is not in fisrt array then I want to add them in fisrt.. how can I do it? such as:
    [code] for(int i=0;i<size1;i++)
    for(int j=0;j<size2;j++)
    if(q[i]!=p[i])
    //add second array's elemenths to first.. I coulnd't go on after here:S

  6. #6
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    I dunno what you mean by that, but you can't change the size of an array after the declaration
    Currently research OpenGL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. cin.get() Helppp!!!
    By yukapuka in forum C++ Programming
    Replies: 6
    Last Post: 05-03-2008, 11:57 AM
  2. helppp in bank databse
    By neha007 in forum C++ Programming
    Replies: 1
    Last Post: 06-02-2007, 09:43 AM
  3. Helppp
    By GQgirl in forum C Programming
    Replies: 6
    Last Post: 11-23-2006, 04:03 PM
  4. Modem programming helppp amateur!!
    By Siagal in forum Windows Programming
    Replies: 4
    Last Post: 10-12-2001, 03:02 AM
  5. Modem programming helppp amateur!!
    By Siagal in forum C Programming
    Replies: 4
    Last Post: 10-10-2001, 05:12 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21