1 Replies - 221 Views - Last Post: 14 October 2012 - 10:11 PM Rate Topic: -----

#1 amyceres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 88
  • Joined: 11-October 12

Protected and Private Classes

Posted 14 October 2012 - 09:48 PM

I need guidances on getting this working ..to show what what's is on the gif.
#include <iostream> 
using namespace std;
class MyClass 
{ 
   protected: 
   int Value; 
}
class x: MyClass
}
    public:  
   void setValue(int Val);
   int getValue(void);
   int x;
   void showMe() { cout << value << endl; } 
}; // MyClass 
// Nothing is wrong before this line. 
//Member function definitions
int x::getValue(void)
{
	return Value;
}
void x::setValue( int Val)
{
	Value=Val;
}
//Main Function for this program.
int main() 
{   
	{
    int k[4] = {3, 5};// An int array of size 2
	cout<< "The value of k[0] is "<<k[0]<<endl;
	cout<< "The value of k[1] is "<<k[1]<<endl;
    
    }

	{
    int k[4] = {8, 10, 6, 20};
    for (k[4]=0;k[4]< 4;k[4]++)
	   {
	cout<<"/n Now changing the values of the array:"<<endl;
	cout<<"the value of k[0]"<<k<<endl;
	    }

	{

        MyClass   x[2];   // declares x2 as an array of MyClass 
         x[0] = x[0] + x[1];  // assigns the sum of x[0] and x[1] into x[0] 
         x.showMe();

	}
	system("pause");
	
	
	return 0; 
} // main

There's a gif attachment. There's a lot of mistakes and etc and I am not done with it. Just need to be pointed in a direction.

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Protected and Private Classes

#2 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Protected and Private Classes

Posted 14 October 2012 - 10:11 PM

You need to focus on placing your curly braces right. I notice that

class x: MyClass
}//this should be {
   public: 
   void setValue(int Val);
   int getValue(void);
   int x;
   void showMe() { cout << value << endl; }
}; // MyClass 



Next, there are unnecessary '{'s on line 29, 34, 36,44 and 50. You may want to remove that.

Then, your for loop that you have used here should not be used like this. Please think on how to change the for loop to accept new values. You would probably want to use something like this.

for(int i=0;i<=4;i++)
{
//cout<<"Please Enter new elements";
//then enter the elements in array k[];
}



Please do the following changes and repost your modified code after the changes. Once you do that, we can move forward.

regards,
Raghav

This post has been edited by raghav.naganathan: 14 October 2012 - 10:13 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1