Question

In: Computer Science

C++: Write the following function prototypes that would be declared for the Cplx class (you don't...

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

Solutions

Expert Solution

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.


Related Solutions

Create a header file, iofunctions.h, containing the following function prototypes. (don't forget to follow the coding...
Create a header file, iofunctions.h, containing the following function prototypes. (don't forget to follow the coding style) int readfile( struct pokemon pokearray[ ], int* num, char filename[ ] ); int writefile( struct pokemon pokearray[ ], int num, char filename[ ] ); Then, create a source file, iofunctions.c, defining the functions above. Specifications The readfile function will read the data from a text file and store it in the array called by pokearray. It must not load the pokemons more than...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType...
Write a C++ PROGRAM: Add the function min as an abstract function to the class arrayListType to return the smallest element of the list. Also, write the definition of the function min in the class unorderedArrayListType and write a program to test this function.
C++ Please read the question carefully and make sure that the function prototypes given are used...
C++ Please read the question carefully and make sure that the function prototypes given are used correctly for both parts. This is one whole programming assignment so please make sure that it;s answered entirely not just one part. The output example is provided at the end of the question. First , write a program to create an array and fill it up with 20 randomly generated integers between 0 to 10 and output the array. Part 1: Write a function...
Complete the definitions for the following prototypes in the Time class: Time(std::string) – a constructor that...
Complete the definitions for the following prototypes in the Time class: Time(std::string) – a constructor that will take in a string with the format h:m:s and parse the h, m and s into separate int values that can be used to set the time of a new time object. int getSecond() const - return the value of the second void setSecond() - set the value of the second, making sure the new second value is valid before changing it. std::string...
C++ Programming 19.2 Operator Overloading practice Write the prototypes and functions to overload the given operators...
C++ Programming 19.2 Operator Overloading practice Write the prototypes and functions to overload the given operators in the code main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() { rectangleType rectangle1(23, 45); //Line 1 rectangleType rectangle2(12, 10); //Line 2 rectangleType rectangle3; //Line 3 rectangleType rectangle4; //Line 4 cout << "Line 5: rectangle1: "; //Line 5 rectangle1.print(); //Line 6 cout << endl; //Line 7 cout << "Line 8: rectangle2: "; //Line...
DO THIS IN C++: Question: Write a function “reverse” in your queue class (Codes are given...
DO THIS IN C++: Question: Write a function “reverse” in your queue class (Codes are given below. Use and modify them) that reverses the whole queue. In your driver file (main.cpp), create an integer queue, push some values in it, call the reverse function to reverse the queue and then print the queue. NOTE: A humble request, please don't just copy and paste the answer from chegg. I need more specific answer. Also I don't have much question remaining to...
In C++ write a program with a base class thet has a pure virtual function SALARY,...
In C++ write a program with a base class thet has a pure virtual function SALARY, and two derived classes. In the first derived class salary is increased by 20%, in the second derived class salary is increased by 30%
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
For this computer assignment, you are to write a C++ program to implement a class for...
For this computer assignment, you are to write a C++ program to implement a class for binary trees. To deal with variety of data types, implement this class as a template. Most of the public member functions of the BinaryTree class call private member functions of the class (with the same name). These private member functions can be implemented as either recursive or non-recursive, but clearly, recursive versions of these functions are preferable because of their short and simple implementations...
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );...
Write C++ program Consider the following SimpleString class: class simpleString {     public:          simpleString( );                                 // Default constructor          simpleString(int mVal );                    // Explicit value constructor          ~simpleString() { delete [ ] s;}          // Destructor void readString();                              // Read a simple string          void writeString() const;                    // Display a simple string char at(int pos) const;                       // Return character at (pos)          int getLength() const;                        // Return the string length          int getCapacity() const;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT