Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert problems 3 and 5 in to template classes, of week 5 and week 4. Test each with Implicit int, float, double, long int. Test

Convert problems 3 and 5 in to template classes, of week 5 and week 4.

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

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

Please help me with these C++ questions.

Q.1.

//Main.cpp

#include "aThing.h"

#include "aThing.cpp"

int main(){

aThing *ThingOne = new aThing();

ThingOne->setWeight(110);

cout << "Default constructor.. Weight is: " << ThingOne->getWeight() << endl;

aThing *ThingTwo = new aThing(120);

cout << " Parameterized constructor.. Weight is: " << ThingTwo->getWeight() << endl;

aThing ThingThree;

ThingThree.setWeight(130);

cout << " Without using constructor.. Weight is: " << ThingThree.getWeight() << endl;

return 0;

}

---------------------------------------------------------

//aThing.cpp

#include "aThing.h"

#include

#include

using namespace std;

aThing::aThing(){}

aThing::aThing(double wt){

weight = wt;

}

double aThing::getWeight(){

return weight;

}

void aThing::setWeight(double wt){

weight = wt;

}

-------------------------------------

//aThing.h

#ifndef aTHING

#define aTHING

class aThing {

public:

aThing();

aThing(double weight);

double getWeight();

void setWeight(double weight);

private:

double weight;

};

#endif

----------------------------------

Q.2.

//Main.cpp

#include "Rectangle.h"

#include

using namespace std;

int main()

{

Rectangle rect, rectb(5,6); // test default and parameterized constructor

rect.set_values (3,4);

cout << "rect area: " << rect.area() << endl;

cout << "rectb area: " << rectb.area() << endl;

return 0;

}

---------------------------------------------------------

//Rectangle.cpp

#include "Rectangle.h"

Rectangle::Rectangle()

{

width = 0;

height = 0;

}

Rectangle::Rectangle(int inWidth, int inHeight)

{

width = inWidth;

height = inHeight;

}

void Rectangle::set_values (int x, int y) {

width = x;

height = y;

}

int Rectangle::area()

{

return width*height;

}

-------------------------------------

//Rectangle.h

#ifndef RECTANGLE_H_

#define RECTANGLE_H_

class Rectangle

{

int width, height;

public:

Rectangle();

Rectangle(int inWidth, int inHeight);

void set_values (int,int);

int area () ;

};

#endif /* RECTANGLE_H_ */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is behavior modification and how is it used in organizations?

Answered: 1 week ago