I need help (write and read function) c++ - c++

The program is working in this way. But I need to change the price system. I need to use priceRead and priceWrite.
priceRead (): double
priceWrite (in _price: double): void
priceRead: price is a function to read the property.
priceWrite (double): price property is a function of writing.
Sorry for bad english. :(
#include <iostream>
#include <string.h>
using namespace std;
class shoes{
protected:
int size;
string colour;
char sex;
string brand;
public: shoes(int _size, string _colour, char _sex, string _brand)
:size(_size),colour(_colour), sex(_sex), brand(_brand)
{cout << "shoe configurator" << endl;}
~shoes(){ }
void shoesInf();
};
class storage{
protected:
int number;
int maxsize;
int minsize;
public: storage(int _number, int _maxsize, int _minsize)
:number(_number),maxsize(_maxsize),minsize(_minsize)
{cout << "store configurator" << endl;}
~storage(){ }
void storageInf();
};
void shoes::shoesInf()
{
cout << "Size :" << size << endl;
cout << "Colour :" << colour << endl;
cout << "Sex :" << ((sex=='M')?"Man":"Woman") << endl;
cout << "Brand:" << brand << endl;
}
void storage::storageInf()
{
cout << "Number :" << number << endl;
cout << "Max size :" << maxsize << endl;
cout << "Min size :" << minsize << endl;
}
class Store: public storage{
private: int number;
int maxsize;
int minsize;
public: Store(int _number, int _maxsize, int _minsize)
:storage(_number,_maxsize,_minsize)
{cout << "storage INF" << endl;}
};
class Nike: public shoes{
private: double price;
public: Nike(int _size, string _colour, char _sex, string _brand,
double _price):shoes(_size,_colour,_sex,_brand),price(_price)
{cout << "Shoes INF" << endl;}
void shoesInf()
{
((shoes*)this)->shoesInf();
cout << "Price :" << price << endl;
}
};
class Lacoste: public shoes{
private: double price;
public: Lacoste(int _size, string _colour, char _sex, string _brand,
double _price):shoes(_size,_colour,_sex,_brand),price(_price)
{cout << "Shoes INF" << endl;}
void shoesInf()
{
((shoes*)this)->shoesInf();
cout << "Price:" << price<< endl;
}
};
int main(int argc, char** argv) {
Store*sh=new Store(1,50,15);
sh->storageInf();
Nike *sh2=new Nike(38,"Blue",'F',"Nike",100);
sh2->shoesInf();
Lacoste *sh3=new Lacoste(40,"Yellow",'M',"Lacoste",350);
sh3->shoesInf();
return 0;
}

class Shoes
{
private:
int size;
string colour;
char sex;
string brand;
double price;
public:
Shoes(int _size, string _colour, char _sex, string _brand, double _price) :
size(_size), colour(_colour), sex(_sex), brand(_brand), price(_price)
{}
void writePrice(double newPrice)
{
price = newPrice;
}
void readPrice()
{
cout << price << endl;
}
};
Notes:
All shoes have a price, so why not just put it in the base class?
Brand is defined by the brand string, all shoes are the same, so no need to derive a new class for each brand.
No need to have an empty destructor.
Also, without this redefinition of price when deriving, you don't have to redefine shoeInf everytime you want to derive from Shoe.
One more thing: Start class names with CapitalLetters (in that style!).

Related

How do I use have a constructor with another class object in c++?

I've got a simple program where I have two classes which are Hat and Person. Each Person has a string name, a int idNum and a hat object. Each hat simply has a string of hatType and a char of hatSize. In the main method I want to simply declare 2 people and use a display method to show the information. Here's my current code, please go easy on me I'm still new to OOP in c++.
Person Class
class Person
{
private:
string name;
unsigned int idNum;
Hat myHat;
public:
Person(string, unsigned int, Hat);
void display();
};
Person::Person(string personName, unsigned int personID)
{
name = personName;
idNum = personID;
myHat = hat;
}
void Person::display()
{
cout << "Given name : " << name << endl;
cout << "Id. number : " << idNum << endl;
hat.display();
}
Hat Class
class Hat
{
private:
string hatType;
char hatSize; // S, M, L
public:
Hat(string,char);
void display();
};
Hat::Hat(string _type, char _size){
hatType = _type;
hatSize = _size;
}
void Hat::display()
{
cout << "Hat type : " << hatType << endl;
cout << "Hat size : " << hatSize << endl;
}
Main
int main()
{
Person personA("Alice",12321, Hat("Trilbee",'M'));
Person personB("Bob",2324, Hat("Ferret",'S'));
personA.display();
personB.display();
return 0;
}
your Person class here:
Person::Person(string personName, unsigned int personID)
{
. ...
is not fully implemented just add the hat parameter...
Person::Person(string personName, unsigned int personID, Hat hat)
{....
Below is the complete corrected(working) version. I have added some comments to show the changes i made.
#include <iostream>
#include <string>
using namespace std;
class Hat
{
private:
string hatType;
char hatSize; // S, M, L
public:
Hat(string,char);
//Added this default constructor since it won't be synthesized automatically
Hat()
{
std::cout<<"Default constructor"<<std::endl;
}
void display();
};
Hat::Hat(string _type, char _size){
hatType = _type;
hatSize = _size;
}
void Hat::display()
{
cout << "Hat type : " << hatType << endl;
cout << "Hat size : " << hatSize << endl;
}
class Person
{
private:
string name;
unsigned int idNum;
Hat myHat;
public:
Person(string, unsigned int, Hat);
void display();
};
//added the 3rd parameter of type Hat
Person::Person(string personName, unsigned int personID, Hat hat)
{
name = personName;
idNum = personID;
myHat = hat;
}
void Person::display()
{
cout << "Given name : " << name << endl;
cout << "Id. number : " << idNum << endl;
myHat.display();//changed hat.display() to myHat.display();
}
int main()
{
Person personA("Alice",12321, Hat("Trilbee",'M'));
Person personB("Bob",2324, Hat("Ferret",'S'));
personA.display();
personB.display();
return 0;
}

To convert multi level to hierarchy inheritance in c++

When I tried to convert it the class result can't get the data from class marks even if I made the data variables of marks public I don't know why. I also declared a object of class marks in result and then tried to access it but failed again I am new to coding so don't know all the syntax correctly your help will be of great use
#include <string.h>
#include <iostream>
using namespace std;
class student {
private:
int rl;
char nm[20];
public:
void read();
void display();
};
class marks : public student {
protected:
int s1;
int s2;
int s3;
public:
void getmarks();
void putmarks();
};
class result : public marks {
private:
int t;
float p;
char div[10];
public:
void process();
void printresult();
};
void student::read() {
cout << "enter Roll no and Name " << endl;
cin >> rl >> nm;
}
void student::display() {
cout << "Roll NO:" << rl << endl;
cout << "name : " << nm << endl;
}
void marks ::getmarks() {
cout << "enter three subject marks " << endl;
cin >> s1 >> s2 >> s3;
}
void marks ::putmarks() {
cout << "subject 1:" << s1 << endl;
cout << "subject 2 :" << s2 << endl;
cout << "subject 3:" << s3 << endl;
}
void result::process() {
t = s1 + s2 + s3;
p = t / 3.0;
p >= 60 ? strcpy(div, "first")
: p >= 50 ? strcpy(div, "second")
: strcpy(div, "third");
}
void result::printresult() {
cout << "total = " << t << endl;
cout << "per = " << p << "%" << endl;
cout << "div = " << div << endl;
}
int main(){
result x;
x.read();
x.getmarks();
x.process();
x.display();
x.putmarks();
x.printresult();
}
#include<iostream>
#include<string.h>
using namespace std;
class marks // parent class
{
protected:
int s1;
int s2;
int s3;
public:
void getmarks();
void putmarks();
};
class student : public marks // child class
{
private:
int rl;
char nm[20];
public:
void read();
void display();
};
class result : public marks// child class
{
private:
int t;
float p;
char div[10];
public:
void process();
void printresult();
};
void student::read()
{
cout<<"enter Roll no and Name "<<endl;
cin>>rl>>nm;
}
void student:: display()
{
cout <<"Roll NO:"<<rl<<endl;
cout<<"name : "<<nm<<endl;
}
void marks ::getmarks()
{
cout<<"enter three subject marks "<<endl;
cin>>s1>>s2>>s3;
}
void marks ::putmarks()
{
cout <<"subject 1:"<<s1<<endl;
cout<<"subject 2 :"<<s2<<endl;
cout <<"subject 3:"<<s3<<endl;
}
void result::process()
{
t= s1+s2+s3;
p = t/3.0;
p>=60?strcpy(div,"first"):p>=50?strcpy(div, "second"): strcpy(div,"third");
}
void result::printresult()
{
cout<<"total = "<<t<<endl;
cout<<"per = "<<p<<"%"<<endl;
cout<<"div = "<<div<<endl;
}
int main()
{
result x;
student y;
y.read();
x.getmarks();
x.process();
y.display();
x.putmarks();
x.printresult();
}

How to Initialize objects with overloaded constructors using different files

I have tried literally everything to try to initialize the constructor so that when I create an object and pass the parameters in, it wont give me a crazy negative number, but it's still not working!
To test that it works I used the getHp and attack function. So for example, if I say Hero Hi(100, 200, 300, 400), then I say Hi.getHP(), it should be 100(the first parameter)...
//main.cpp
int main()
{
Hero Me(100,20,30,40);//Created using overloaded constructor
Monsters m(100,16,18,20);//creates a monster object and uses overloaded constructor
to initialize
cout << "\ntest1\n";
Me.getHp();//expecting 100
Me.getAttack();//expecting w.e is in parameters
m.getHp();//expecting 100
m.getAttack();//same as hero
cin.sync();
cin.get();
return 0;
}
Here is the rest of my code, in case you need it. I also left out headers and such for simpler code.
//Characters.h
class Characters
{
private:
int level;
int hp;
int attack;
int defense;
protected:
Characters(); // zero everything by default
Characters(int, int, int, int); // populate explicitly
~Characters();
public:
int getAttack() const { return attack; }
int getDefense() const { return defense; }
int getHp() const { return hp; }
int getlevel() const { return level; }
void setAttack(int);
void setDefense(int);
void setStrength(int);
void setHp(int);
void setlevel(int);
void damageTaken(int);
};
//Characters.cpp
Characters::Characters() : level(0), hp(0), attack(0), defense(0) {}
//
//Characters::Characters(int seed)
//{
// // NB. your code still doesn't initialize hp, strength etc.
// // it also logs level before initializing it, so that will be garbage
//}
//Characters::Characters(int hit, int lvl, int att, int def)
// : level(lvl), hp(hit), attack(att), defense(def){}
Hero::Hero(int newHp, int newLevel, int newAttack, int newDef)
: Characters(newHp, newLevel, newAttack, newDef)
{
cout << "Hero created using Overloaded function!\n";
HeroHp = newHp;
cout << "Hp is: "<< HeroHp << endl;
Herolevel = newLevel;
cout << "level is: " << Herolevel << endl;
HeroAttack = newAttack;
cout << "Attack is: " << HeroAttack << endl;
HeroDefense = newDef;
cout << "Defense is: " << HeroDefense << endl;
// logging goes here
// note that you don't need HeroLevel etc. at all any more, just use level
}
Monsters::Monsters(int newHp, int newLevel, int newAttack, int newDef)
: MonsterHp(newHp), Monsterlevel(newLevel), MonsterAttack(newAttack)
, MonsterDefense(newDef)//initialize list
{
cout << "Monster created using Overloaded function!\n";
MonsterHp = newHp;
cout << "Hp is: "<< MonsterHp << endl;
Monsterlevel = newLevel;
cout << "level is: " << Monsterlevel << endl;
MonsterAttack = newAttack;
cout << "Attack is: " << MonsterAttack << endl;
MonsterDefense = newDef;
cout << "Defense is: " << MonsterDefense << endl;
}
Characters::~Characters()
{
cout << "Character has been destroyed!\n";
}
void Characters::setAttack(int att)
{
attack = att;
}
void Characters::setDefense(int def)
{
defense = def;
}
void Characters::setHp(int health)
{
hp = health;
}
void Characters::damageTaken(int damage)
{
hp -= damage;
}
void Characters::setlevel(int lvl)
{
level = lvl;
}
//Monsters.h
class Monsters:
public Characters //Hero
{
private:
int Monsterlevel;
int MonsterHp;
int MonsterStrength;
int MonsterAttack;
int MonsterDefense;
public:
Monsters(int, int, int, int); //explicit
~Monsters();
};
//Monsters.cpp
Monsters::~Monsters()
{
cout << "\nMonster Destroyed";
}
//Hero.h
class Hero:
public Characters
{
private:
int Herolevel;
int HeroHp;
int HeroStrength;
int HeroAttack;
int HeroDefense;
public:
//Hero();
Hero(int, int, int, int);
~Hero();
};
//Hero.cpp
Hero::~Hero()
{
cout << "Hero destroyed!\n";
}
HeroHp in the Hero class and hp in the Characters class are separate variables. The constructor for Hero never intializes hp, which is the variable that is returned by getHp.
You probably want to eliminate the HeroXXX variables in the Hero class and use the corresponding ones in the Characters base class.
It works fine if I uncomment Characters constructor: http://coliru.stacked-crooked.com/view?id=261944b9b1304c3ed9d76e69b2318ee2-ad7854d9cfd7979d567ca413f0830b65
Are you sure you were compiling with success? You left some warnings around that might have deceived you... A very good reason for removing always all of your warnings.

How to initialize instances of classes?

//main.cpp
#include "Monsters.h"
#include "Hero.h"
#include "Monsters.h"
#include "Characters.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
When i created my object it took those parameters and initialised them to it right?
So why when i called their methods, it returned a different value?
For example, I initialized them here while created my object at the same time:
Hero Me(100,20,30,40);
Monsters m(100,16,18,20);//creates a monster object and uses overloaded constructor to initialize
Me.getHp();//expected 100, but got a long negative random number
m.getHp();//expected 100, but got a long negative random number also
//Why must i use setHp() and setAttack() when i already initialized them with the constructor?
Me.setAttack(89);
Me.setHp(100);
m.setAttack(40);
m.setHp(100);
cout << "\nAttacking!\n";
while ((Me.getHp() > 0) && (m.getHp() > 0))
{
cout << "\nYour hp is: " << Me.getHp() << endl;
cout << "The enemy's hp is: "<< m.getHp() << endl;
cout << "\nThe monster has attacked you!\n";
cout << "You received " << m.getAttack() << " damage;" << endl;
Me.damageTaken(m.getAttack());
if(Me.getHp() > 0)//Check if still alive
{
cout << "\nYour hp is now: " << Me.getHp() << endl;
//cout << "Enemy hp is: "<< m.getHp() << endl;
cout << "\nNow you attacked!\nYou have dealt "<< Me.getAttack() << " Damage" << endl;
m.damageTaken(Me.getAttack());
if(m.getHp() > 0)//Check if still alive
{
cout << "Enemy hp is now: " << m.getHp() << endl;
cout << "\nAttacking again!\n";
}
}
}
if ((Me.getHp() > 0) && (m.getHp() <= 0))
cout <<"\nCongratulations! You killed the enemy!" << endl;
else if ((Me.getHp() <= 0) && (m.getHp() > 0))
cout << "You have died!" << endl;
cin.sync();
cin.get();
return 0;
}
Here's the rest of the code in case you need it:
//Hero.h
#pragma once
#include "Characters.h"
class Hero:
public Characters
{
private:
int Herolevel;
int HeroHp;
int HeroStrength;
int HeroAttack;
int HeroDefense;
public:
//Hero();
Hero(int, int, int, int);
~Hero();
};
//Hero.cpp
#include "Monsters.h"
#include "Hero.h"
#include "Characters.h"
#include <iostream>
using namespace std;
//Hero::Hero()
//{
// cout << "HOLA! Hero Created using normal constructor\n";
//}
Hero::Hero(int newHp, int newLevel, int newAttack, int newDef)
: HeroHp(newHp), Herolevel(newLevel), HeroAttack(newAttack), HeroDefense(newDef)
{
cout << "Hero created using Overloaded function!\n";
HeroHp = newHp;
cout << "Hp is: "<< HeroHp << endl;
Herolevel = newLevel;
cout << "level is: " << Herolevel << endl;
HeroAttack = newAttack;
cout << "Attack is: " << HeroAttack << endl;
HeroDefense = newDef;
cout << "Defense is: " << HeroDefense << endl;
}
Hero::~Hero()
{
cout << "Hero destroyed!\n";
}
//Monsters.h
#pragma once
#include "Characters.h"
class Monsters:
public Characters //Hero
{
private:
int Monsterlevel;
int MonsterHp;
int MonsterStrength;
int MonsterAttack;
int MonsterDefense;
public:
//Monsters();
Monsters(int, int, int, int);
//Monsters(int);
~Monsters();
};
//Monsters.cpp
#include "Monsters.h"
#include "Hero.h"
#include "Characters.h"
#include <iostream>
using namespace std;
Monsters::Monsters(int newHp, int newLevel, int newAttack, int newDef)
: MonsterHp(newHp), Monsterlevel(newLevel), MonsterAttack(newAttack), MonsterDefense(newDef)
{
cout << "Monster created using Overloaded function!\n";
MonsterHp = newHp;
cout << "Hp is: "<< MonsterHp << endl;
Monsterlevel = newLevel;
cout << "level is: " << Monsterlevel << endl;
MonsterAttack = newAttack;
cout << "Attack is: " << MonsterAttack << endl;
MonsterDefense = newDef;
cout << "Defense is: " << MonsterDefense << endl;
}
Monsters::~Monsters()
{
cout << "\nMonster Destroyed";
}
//Characters.h
#pragma once
class Characters
{
private:
int level;
int Hp;
int Strength;
int Attack;
int Defense;
public:
Characters();
Characters(int);
Characters(int, int, int, int);
~Characters();
int getAttack();
int getDefense();
int getStrength();
int getHp();
int getLevel();
void setAttack(int);
void setDefense(int);
void setStrength(int);
void setHp(int);
void setlevel(int);
void damageTaken(int);
};
//Characters.cpp
#include "Characters.h"
#include "Hero.h"
#include "Monsters.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
Characters::Characters()
{
cout << "\nCharacter has been created!\n";
}
Characters::Characters(int random)
{
cout << "Level " << level << " character created with: \n";
srand ((unsigned)time(0));
random = rand() % 10 + 1;
//setlevel(int random);
level = random;
}
Characters::~Characters()
{
cout << "Character has been destroyed!\n";
}
void Characters::setAttack(int att)//get Character left over hp
{
Attack = att;
}
void Characters::setDefense(int def)//get Character left over hp
{
Defense = def;
}
void Characters::setStrength(int str)//get Character left over hp
{
Strength = str;
}
void Characters::setHp(int health)//get Character left over hp
{
Hp = health;
}
void Characters::damageTaken(int damage)//get Character left over hp
{
Hp -= damage;
}
void Characters::setlevel(int lvl)//get Character left over hp
{
level = lvl;
}
int Characters::getAttack()
{
//cout << "Your attack is: " << Attack << endl;
return Attack;
}
int Characters::getDefense()
{
//cout << "Your defense is: " << Defense << endl;
return Defense;
}
int Characters::getStrength()
{
//cout << "Your strength is: " << Strength << endl;
return Strength;
}
int Characters::getHp()
{
//cout << "Your hp is: " << Hp << endl;
return Hp;
}
int Characters::getLevel()
{
//cout << "Your level is: " << level << endl;
return level;
}
How to initialize instances of classes?
You need to correctly initialize your base classes by calling their constructor, passing on the relevant arguments. Maybe it is easier to illustrate this with a simpler example:
class Foo
{
public:
explicit Foo(int i) : foo_i(i) {}
int getFoo() const { return foo_i; }
private:
};
class Bar : public Foo
{
public:
explicit Bar(int i) : Foo(i) // calls Foo(int) constructor, setting Foo::foo_i
{}
};
#include <iostream>
int main()
{
Bar b(42);
b.getFoo(); // prints 42
}
Hero inherits Characters, including all its data members (level, hp, etc.).
So, it doesn't need to add its own HeroLevel, HeroHP etc. You're just duplicating data (and work).
Now, it also doesn't initialize the base class members - the default constructor for Characters doesn't even zero them, so their values are undefined.
You should be looking for something like this:
class Characters
{
private:
int level;
int hp;
int strength;
int attack;
int defense;
protected:
Characters(); // zero everything by default
Characters(int); // randomly generate everything
Characters(int, int, int, int); // populate explicitly
public:
int getAttack() const { return Attack; }
// etc.
};
Characters::Characters() : level(0), hp(0), strength(0), attack(0), defense(0) {}
Characters::Characters(int seed) {
// NB. your code still doesn't initialize hp, strength etc.
// it also logs level before initializing it, so that will be garbage
}
Characters::Characters(int hit, int lvl, int att, int def)
: level(lvl), hp(hit), attack(att), defense(def)
{
// you only pass 4 attributes, what should strength be?
}
and finally:
Hero::Hero(int newHp, int newLevel, int newAttack, int newDef)
: Characters(newHp, newLevel, newAttack, newDef)
{
// logging goes here
// note that you don't need HeroLevel etc. at all any more, just use level
}
You should really try to understand the basics of this before designing an entire class hierarchy - see juanchopanza's answer for a clear example. A smaller example would also have been much easier to paste, read and understand.

Resolve ambiguity resulting from multiple inheritance of classes which share a common template class

I am trying to create a base class which is a template class and accepts, as a templace, some class. This base class in the parent class of two other classes which are themselves the parents of the final class. Thus, I have the traditional diamond problem in c++ with the addition that the root base class is a template class. Using virtual inheritance here does not quite do the trick.
Edit: Included some code (and corrected typos)
#include<iostream>
#include<string>
using namespace std;
template<class TemplateT>
class MainMaster {
protected:
std::string name;
int number;
TemplateT variableProp;
public:
explicit MainMaster(std::string, int);
void setName(std::string);
std::string getName();
void printName();
void setNumber(int);
int getNumber();
void printNumber();
void printMasterProperties(std::string);
void setVarProp(TemplateT);
TemplateT getVarProp();
};
template<class TemplateT>
MainMaster<TemplateT>::MainMaster(std::string nameIn, int numIn){
setName(nameIn);
setNumber(numIn);
}
template<class TemplateT>
void MainMaster<TemplateT>::setName(std::string nameIn){ name = nameIn; }
template<class TemplateT>
std::string MainMaster<TemplateT>::getName(){ return name; }
template<class TemplateT>
void MainMaster<TemplateT>::printName(){ cout << "Master's name is " << name << endl; }
template<class TemplateT>
void MainMaster<TemplateT>::setNumber(int numIn){ number = numIn; }
template<class TemplateT>
int MainMaster<TemplateT>::getNumber(){ return number; }
template<class TemplateT>
void MainMaster<TemplateT>::printNumber(){ cout << name << "'s number is " << number << endl; }
template<class TemplateT>
void MainMaster<TemplateT>::printMasterProperties(std::string pre = ""){
cout << pre << "Master Properties" << endl
<< pre << "-Number: " << number << endl;
}
class ChildOne: public virtual MainMaster<std::string>{
protected:
std::string propOne;
public:
// using MainMaster::MainMaster;
ChildOne(std::string nameIn, int numIn, std::string p1);
void printName();
void setPropOne(std::string);
std::string getPropOne();
void printOnesProps(std::string);
};
ChildOne::ChildOne(std::string nameIn, int numIn, std::string p1): MainMaster<std::string>(nameIn,numIn){
setPropOne(p1);
}
void ChildOne::printName(){ cout << "ChildOne's name is " << name << endl; }
void ChildOne::setPropOne(std::string propIn){ propOne = propIn; }
std::string ChildOne::getPropOne(){ return propOne; }
void ChildOne::printOnesProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << "One Properties" << endl
<< pre << "-PropOne: " << propOne << endl;
}
class ChildTwo: public virtual MainMaster<int>{
protected:
std::string propTwo;
public:
ChildTwo(std::string nameIn, int numIn, std::string p2);
void printName();
void setPropTwo(std::string);
std::string getPropTwo();
void printTwosProps(std::string);
};
ChildTwo::ChildTwo(std::string nameIn, int numIn, std::string p2): MainMaster<int>(nameIn,numIn){
setPropTwo(p2);
}
void ChildTwo::printName(){
cout << "ChidTwo's name is " << name << endl;
}
void ChildTwo::setPropTwo(std::string propIn){ propTwo = propIn; }
std::string ChildTwo::getPropTwo(){ return propTwo; }
void ChildTwo::printTwosProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << "Two Properties" << endl
<< pre << "-PropTwo: " << propTwo << endl;
}
class FinalChild: public ChildOne, public ChildTwo{
protected:
double finalProp;
public:
FinalChild(std::string nameIn, int num, std::string prop1 ,std::string prop2, double pFinal);
void printFinalProps(std::string);
};
FinalChild::FinalChild(std::string nameIn, int num, std::string prop1 ,std::string prop2, double pFinal):
ChildOne(nameIn, num, prop1),
ChildTwo(nameIn, num, prop2),
MainMaster(nameIn, num){
finalProp = pFinal;
}
void FinalChild::printFinalProps(std::string pre = ""){
printMasterProperties("-");
cout << pre << name << "'s Final Properties" << endl;
cout << pre << "-Number: " << number << endl;
cout << pre << "-PropOne: " << propOne << endl;
cout << pre << "-PropTwo: " << propTwo << endl;
cout << pre << "-finalProp " << finalProp << endl;
}
int main () {
MainMaster<char> master("Master", 0);
ChildOne child1("Child1",1,"P1One");
ChildTwo child2("Child2",2,"P2Two");
FinalChild finalC("FinalChild", 3, "P1Final", "P2Final", 3.0);
master.printMasterProperties();
child1.printOnesProps();
child2.printTwosProps();
finalC.printFinalProps();
}