In: Computer Science
C++: Write the following function prototypes that would be declared for the Cplx class (you don't need to write the function definitions or write the rest of the class). Cplx class is a complex class with lots of data. Remember to show the return type, and const where needed. For all your parameters, call them lval or rval to show that you understand where they would be in the operation. // << function // + as a non-member function // + as a member function // = as a member function
The most important features of c++ are the classes and objects.A class is a way to bind the data describing an entity and its associated function together.in c++ class makes a data type that is used to create objects of this type.
Classes are needed to represent real world entities that not only have data type properties (their characterstics)but also assciated operations.
Declaration of a class involves declaration of its four associated attributes.
1. Data members are the data type properties that describe the characteristics.there may be zeroor more data members of any type in a class.
2.Member functions are the set of operations that may be applied to object of that class.there may be zero or more member functions of a class.
3.Program Acess levels that control acessto members from within the program.These acess levels are private,protected,or public.Depending upon the access level of a class member,access to it is allowed or denied.
4.class tagname that serves as a type specifier for the class using which objects of this class type can be created.The class specification takes place in two parts:
a.class definition.which describes the component members of the class.
b.class method definitions which describe how certain class member functions are implemented.
The general form of a class definition is as given below:
class class-name
{
private:
variable declaration;
function declaration;
public:
variable declarations:
function declarations:
};
The class body contains the declarations of its members (data and functions).There are generally two types of members in a class :private and public(protected also but that we'll learn about which are grouped under two sections namely private:and public.
Member functions can be defined into two places:
1.Out side the class definition.
2.Inside the class definition.
A member function definition outside the class definition is much the same as that of function definitions you are familiar with.The only difference is that the name of the function is the full name of the function.The full name of a function is written as :
class-name::function-name.
where the class -name indicates that the functions specified by function-name is a member of the class specified by class name .The symbol::,called the scope resolution operator,specifies that the scope of the function is restricted to the class class-name.
The general form of a member function definition outside the class definition is :
return-type class-name::function-name(parameter list)
{
function body
}
Only those member functions can be defined inside a class that qualify for becoming in line functions.
A class in c++ represents a group of data and associated functions divided into one or more of these parts :public,private and protected.
1.public members:
This are the members ( data members and function members)that can be used by any function.
class X
{
public:
int a;
int sqr(int a)
{
return a*a;
}
};
X o1;
int main ()
{
int b;
o1.a=10;
b=o1.sqr(15);
}
2.Private members:
This are the clss members that are hidden from the outside world.The private members implement the oop concept of data hiding .the private members of a class can be used only by member functions of the class in which it is declared.
3.protected members:
This are the members that can be used only by member functions other class in which it is declared.The protected members are similar to private members that they cannot be accessed by non members functions.
If a member function of a class does not alter any data in the class ,then this member function may be declared as a constant member function using the keyword const.
int maxi (it,int)const;
void prn(void)const;
When a member function is called by another member function,it is called nesting of member functions.
The member functions of a class can be friend functions of another class.