• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

Can someone help me ?

Status
Not open for further replies.

lexir

Enthusiast
can you help me to write In C++ a class that contains private members, some of which are externally available, and a method (inside the class) that uses these members.
 

Tommy

Founder
You can't access private members on the outside of it's class, only on the inside (internally) of the class; however, variables can be used within a function, publicly, inside of the class to have it's value changed. Here's an example of that:

Code:
/*
      CLASS 1
*/
class MyClass
{
    MyClass();
    ~MyClass();
public:
    void MyStringFunction(std::string val) { mystring = val; }
	
private:
    std::string mystring;
};

MyClass::MyClass()
{
    mystring = "Test";
}

MyClass::~MyClass() { }

/*
      CLASS 2
*/
class OtherClass
{
    OtherClass();
    ~OtherClass();
public:
    void ChangeMyString() { }
};

OtherClass::OtherClass() { }

OtherClass::~OtherClass() { }

void OtherClass::ChangeMyString()
{
    MyClass myClass = new MyClass();
	myClass->MyStringFunction("Test Change");
}
 

lexir

Enthusiast
Well thanks Tommy !

- - - Updated - - -

But what about that ?

C++ a function which outputs multiples of 5, excluding 15.
 

lexir

Enthusiast
No problem :)
Can you help me to write an function which outputs multiples of five , excluding Fifteen
Like an c++ application.
 

Tommy

Founder
No problem :)
Can you help me to write an function which outputs multiples of five , excluding Fifteen
Like an c++ application.

You just wrote the same thing but changed it's size, that doesn't explain it better..

which outputs multiples of five , excluding Fifteen

Five what?

Excluding Fifteen what?

Makes no sense.
 

Hyperion

Founder
This will output multiples of 5 in console:
Code:
#include <cstdio>
int main()
{
	int max=1000;
	int i=1,result=0;

	while(result!=max && i!=200)
	{
		result=5*i;
		printf("\n %d",result);
		i++;
	}       
	std::getchar();
}

OAUskbO.png


I'm not sure how to exclude '15' from the list, if that's what you're referring to..
 

hampros2

Banned
This will output multiples of 5 in console:
Code:
#include <cstdio>
int main()
{
	int max=1000;
	int i=1,result=0;

	while(result!=max && i!=200)
	{
		result=5*i;
		printf("\n %d",result);
		i++;
	}       
	std::getchar();
}

OAUskbO.png


I'm not sure how to exclude '15' from the list, if that's what you're referring to..

Code:
#include <stdio.h>

int main()
{
	int rs = 1;
	for (int i = 0; ; i++)
	{
		rs = 5 * i;
		if (rs == 15)
			continue;
		printf("%i\n", rs);
	}
	return 0;
}
 
Last edited:
Status
Not open for further replies.
Top