Question: Help!!! C++ programming How to convert into template classes Test each with Implicit int, float, double, long int. Test each with explicit int, float, double,

Help!!! C++ programming How to convert into template classes

Test each with Implicit int, float, double, long int.

Test each with explicit int, float, double, long int.

Header.h

#ifndef Header_h

#define Header_h

class Rectangle // Defination of Class Rectangle

{

public: //public variables and functions

void set_values(int x, int y); // public function with variables x and y, they are ints

int area(); //public function area

~Rectangle()

{

cout << "This is a deconstructor." << endl; //This defines the deconstructor of the class.

}

private:

int width, height;

};

#endif /* Header_h */

Source.cpp

#include

#include

using namespace std;

#include "Header.h"

void Rectangle::set_values(int x, int y)// Implementation of function Rectangle with input variable x and y

{

width = x; // parameter transmission, transmite formal parameter to pratical parameter width

height = y; // parameter transmission, transmite formal parameter to pratical parameter height

}

int Rectangle::area() // Implementation of function Rectangle

{

int answer; // Set parameter

answer = width * height;// Calculate the area of the rectangle

return answer; // return the result of calculation

}

Main.cpp

#include

#include

using namespace std;

#include "Header.h"

int main() // Testing program

{

Rectangle rect1; // DECLARATION - USE the new datatype / class 'Rectangle' in a Declaration statement to create 'rect1'

rect1.set_values(5, 6); // Use set_values function to set values

cout << "area: " << rect1.area() << endl; // Output the result

Rectangle rect2; // DECLARATION

rect2.set_values(3, 4); // Use set_values function to set values

cout << "area: " << rect2.area() << endl; // Output the result

// system("pause"); // Mac not support

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!