answersLogoWhite

0


Best Answer

class Rectangle{

private:

int length;

int width;

public:

void input();

void output();

};

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Declare a class called rectangle which has two private members length and width and two public member functions called input and output?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What if you declare public members rather than private in c plus plus?

Public members in C++ have accessibility to any function that has scope to the instance of the class, whereas private members have accessibility only to functions of that class.


Why private data members or functions are not inherited?

Because that's what private means. Private data members or functions are intended to be usable only in the base class, and the inheriting class can only access protected or public members or functions.


What are the privileges granted to friend function?

Friend functions (and classes) have private access to the classes that declare them as friends. Although they have the same access rights as members of the class itself, friends are not themselves members of the class and cannot be inherited.


Can you make private class in c plus plus?

yes it is possible to make a private class in C++ but this class will not solve any purpose.................


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


What are public and private functions in C?

A private function can be either a nested function, but only if the compiler allows nested functions (ANSI C does not). Or it can be a static global function. Static global functions are just like global functions, but they can only be used in the same module. The naming convention requires that it's name begins with an underscore. Global functions that are not static are public functions in C. See: [[http://groups.google.hu/group/comp.lang.c/browse_thread/thread/8e65b8824709a760/a396eb5a4472a6f8?lnk=gst&q=private+function#a396eb5a4472a6f8]]


If you want to guarantee that the object remains the same after calling a member function on it how would you declare the function?

You would place the const keyword before the function body: class Object { public: Object():m_num(1){} int GetData() const; private: int m_num; }; int Object::GetData() const { return(m_num); } Since GetData() does not alter the instance, it makes sense to declare the function as constant. Note that class instance data members that are declared mutable can still be altered, regardless of constant functions. The use of constant functions only guarantees the non-mutable members cannot be altered.


When class will be used and when structure will be used?

In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.


Which base class member functions are not inherited by a derived class?

Derived classes only inherit the protected and public members of their base classes. Private member functions cannot be inherited by a derived class.


In ANSI C you can hide data by using private access specifier Justify?

One can always declare a datatype as static which will limit the scope to the file only. this way data hiding can be achived. For more clearance on the same please refer 'the C programming language'. Data hiding means only relevant data is visible to the user and all the background information is hidden from the user. In c++, the variables are named as data members and these can be hidden with the help of private access specifier. In procedural languages, variables(global variables) are free to flow from functions to functions and hence they were not secured. But in C++, only the class in which the data members are being declared can access them by using private specifier. As, the data members and also member functions of a class cannot be accessed outside the class if they have private access so, they get hidden from the user and hence the data hiding is achieved. Also in inheritance when we derive a class from the base class then the derived class cannot access the private members of the base class. In addition, if a class is derived from another class privately i.e. for example syntax : class B : private A , is used then all the public and protected members (not private) becomes private to class B and cannot be accessed outside the class B, even by using the object of class B. Hence, data hiding is achieved in C++ through private access specifier.


Sample code of typedefstruct in c plus plus?

You don't need a typedef to declare a struct in C++. A struct is declared exactly the same way that you would declare a class, the only difference being that struct members are public by default, while class members are private by default. Aside from that the class and struct keywords are completely interchangeable.


How do you access private variable in flex?

In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }