Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer in C++ programing language: The Problem: In class you saw how to create a dynamic list of property names. This time we are

Please answer in C++ programing language:

The Problem:

In class you saw how to create a dynamic list of property names. This time we are going to extend that by making a class that keeps track of both properties and values (e.g., property: color, value: green). Write a class Thing. It should have these private variables: int props_ct_ to count how many properties we have, int props_max_ to return the maximum number or properties, string *properties_ containing the names of the properties, string *values_ containing the values of the properties. Your class should have the following methods: Thing(int size) a constructor that takes the max size of the properties and values arrays. Thing(const Thing &) a copy constructor. The other two methods you need because of the Rule of Three. Make your own private copy_ and destroy_ methods to assist with this. int set_property(string name, string value) Takes a property name and value, and inserts them into the arrays. Returns the index into the array if successul, and -1 if the array was full. If the property name already exists, replace the value. string get_property(string name) Returns the corresponding value for a given property name, or else an empty string if that property is not found. You may want to have a _copy(const Thing &) method, but that is optional. Sample Output Kermit is Green Kermit is Green Grover is Blue

Thing.h:

#pragma once

#include

namespace potd {

class Thing {

public:

Thing(int);

Thing(const Thing &);

Thing & operator=(const Thing &);

~Thing();

int set_property(std::string,std::string);

std::string get_property(std::string);

private:

void _copy(const Thing &);

void _destroy();

std::string *properties_;

std::string *values_;

int props_ct_;

int props_max_;

};

}

main.cpp:

#include

#include "Thing.h"

int main() {

potd::Thing * t1 = new potd::Thing(5);

potd::Thing * t2 = new potd::Thing(5);

t1->set_property("name","Kermit");

t1->set_property("color","Green");

std::cout << t1->get_property("name") << " is " << t1->get_property("color") << std::endl;

*t2 = *t1;

t1->set_property("name","Grover");

t1->set_property("color","Blue");

std::cout << t2->get_property("name") << " is " << t2->get_property("color") << std::endl;

std::cout << t1->get_property("name") << " is " << t1->get_property("color") << std::endl;

delete t1;

delete t2;

}

WHAT I HAVE TO IMPLEMENT - Thing.cpp:

#include "Thing.h"

using namespace potd;

Thing::Thing(int size) { }

Thing::Thing(const Thing &) { }

Thing::Thing & operator=(const Thing &) { }

Thing::~Thing() { }

int Thing::set_property(std::string name,std::string value) { }

std::string Thing::get_property(std::string name) { }

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions