No idea how to properly read object into Constructor or Function

Howdy, so I'm created a class and I either want to have that class constructor take in that an object that was created in another or one of its functions take in the object.
1
2
3
4
  Engineer::Cbros Engineer(newName, newAge, newHeight);
        Engineer.setCharm(3);
        Engineer.setStr(3);
        Engineer.setIntel(6);

This is an example(above) of an object I've created in one of my classes. Id like my Chics Class to take in that Charm, Str, and Intel info from the class above and then use it in functions.
1
2
3
4
5
6
class Chics
{
    public:
    Chics();
    Chics(const Engineer& );
    void judge(Engineer&, int ,int ,int );

My initial idea but this isnt working at all. Theres other information stored in the objects but i just want to take those three ints from the object thats been created already. Help appreciated.
Last edited on
I don't understand the problem. You pass in an const Engineer& as an argument to the Chics class contructor. Then, you use some public interface(e.g. Engineer::GetCharm()) to get these values from Engineer.
@MatthewRock Issue is, I was wanting to use the Chics Object or one its funcions to use the values in inside Engineer, to create some type of score that I can use to decide whether or not a player gets the "Chics numbers". If theres some other way to pass the values already held in Engineer, then im fine with doing that also. Just need to pointed in the direction of how.
As MatthewRock says:

Then, you use some public interface(e.g. Engineer::GetCharm()) to get these values from Engineer.
You haven't really provided enough context. What is missing is an understanding of the relationship between the two classes.

I see that Chics has a constructor that takes an Engineer. This seems to imply that Chics HAS A Engineer member. IS A Chics an Engineer? If so, this would usually imply inheritance.

If there is not a IS A or a HAS A relationship, then you've already been given the suggestion to provide getters in the Engineer class for the three member variables you're interested in and then call those getters to access the member variables.
@MikeyBoy @AbstractionAnon
The Relationship looks like this. I have a Bros Class, and then there are 3 type of Bros class that derive from it, Engineer, Jock, Artsy. I also have a club class where most of the data processing takes place. As shown below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#define CBROS_H

#include <iostream>
#include <string>

class Cbros
{
    public:

        Cbros();
        //default constructor
        Cbros(std::string , int , double );

        std::string getName()const;
        int getAge ()const;
        int getStr()const;
        int getCharm()const;
        int getIntel()const;
        int getHeight ()const;
        void setName(std::string);
        void setAge(int);
        void setHeight(int);
        void setIntel(int);
        void setStr(int);
        void setCharm(int);




       class Wallet{
    public:
        double addMoney(double amount);//Adds  Money to wallet
        double removeMoney(double amount);//removes money from wallet
        int countMoney();//displays money in wallet
    protected:
        int money;

};
    Wallet Mywallet;



    protected:


        std::string newName;
        std::string newRace;
        int newAge;
        double newHeight;
        int newStr;
        int newInt;
        int newCharm;




    private:

};



#endif // CBROS_H

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "Club.h"
#include "Engineer.h"
#include "Cbros.h"
#include "Artsy.h"
#include "Jock.h"
#include "Chics.h"
#include <iostream>
#include <string>

Club::Club()
{}


int Club::displayMenu(){
std::cout<<"Welcome Meet a Girl Game!"<<std::endl;
std::cout<<"The goal is to use your inherent skills to earn a girl's phone number\n\n";
std::cout<<"Please enter the number of your choice:\n\n";
std::cout<<"1. Go the Club\n";
std::cout<<"2. Stay at Home\n";

std::cin>>menuSelection;
return menuSelection;





}
void Club::processInput(){
   while (menuSelection!=1&&menuSelection!=2){
        std::cout<<"invalid choice\n"<<displayMenu();

   }
    if (menuSelection==1){
        std::cout<<"Are you a\n";
        std::cout<<"1. Engineer Bro?\n";
        std::cout<<"2. Artsy Bro?\n";
        std::cout<<"3. Jock Bro?\n";
        std::cin>>menuSelection;

        switch(menuSelection){

    case 1:{
        std::cout<<"Welcome Engineer Bro\n";
        std::cout<<"Please enter your name:";
        std::cin.ignore();
        std::getline(std::cin, newName);
        std::cout<<"Please enter your Height(in inches):";
        std::cin>>newHeight;
        std::cout<<"Please enter your Age:";
        std::cin>>newAge;
        Engineer::Cbros Engineer(newName, newAge, newHeight);
        Engineer.setCharm(3);
        Engineer.setStr(3);
        Engineer.setIntel(6);
        std::cout<<"Class: Engineer\n";
        std::cout<<"Name: "<<Engineer.getName()<<std::endl;
        std::cout<<"Height: "<<Engineer.getHeight()<<std::endl;
        std::cout<<"Age "<<Engineer.getAge()<<std::endl;
        std::cout<<"Initial Stats"<<std::endl;
        std::cout<<"Charm: "<<Engineer.getCharm()<<std::endl;
        std::cout<<"Strength: "<<Engineer.getStr()<<std::endl;
        std::cout<<"Intelligence: "<<Engineer.getIntel()<<std::endl;


        break;
        }

    case 2:{
        std::cout<<"Welcome Artsy Bro!\n";
        std::cout<<"Please enter your name:";
        std::cin.ignore();
        std::getline(std::cin, newName);
        std::cout<<"Please enter your Height(in inches):";
        std::cin>>newHeight;
        std::cout<<"Please enter your Age:";
        std::cin>>newAge;
        Artsy::Cbros Artsy(newName, newAge, newHeight);
        Artsy.setCharm(6);
        Artsy.setStr(3);
        Artsy.setIntel(3);
        std::cout<<"Artsy Bro's Name: "<<Artsy.getName()<<std::endl;
        std::cout<<"Height: "<<Artsy.getHeight()<<std::endl;
        std::cout<<"Age "<<Artsy.getAge()<<std::endl;
        std::cout<<"Initial Stats"<<std::endl;
        std::cout<<"Charm: "<<Artsy.getCharm()<<std::endl;
        std::cout<<"Strength: "<<Artsy.getStr()<<std::endl;
        std::cout<<"Intelligence: "<<Artsy.getIntel()<<std::endl;

        break;
        }
    case 3: {

        std::cout<<"Welcome Jock Bro!\n";
        std::cout<<"Please enter your name:";
        std::cin.ignore();
        std::getline(std::cin, newName);
        std::cout<<"Please enter your Height(in inches):";
        std::cin>>newHeight;
        std::cout<<"Please enter your Age:";
        std::cin>>newAge;
        Jock::Cbros Jock(newName, newAge, newHeight);
        Jock.setCharm(3);
        Jock.setStr(6);
        Jock.setIntel(3);
        std::cout<<"Jock Bro's Name: "<<Jock.getName()<<std::endl;
        std::cout<<"Height: "<<Jock.getHeight()<<std::endl;
        std::cout<<"Age "<<Jock.getAge()<<std::endl;
        std::cout<<"Initial Stats"<<std::endl;
        std::cout<<"Charm: "<<Jock.getCharm()<<std::endl;
        std::cout<<"Strength: "<<Jock.getStr()<<std::endl;
        std::cout<<"Intelligence: "<<Jock.getIntel()<<std::endl;


        break;
        }
    default:


        break;
        }
}
    else if(menuSelection==2){
        std::cout<<"Enjoy Netflix Bro";}
}





In my main I have this below. My goal was to use the information already stored in the Engineer, Jock, or Artsy Objects inside of Chics. Clearer??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <string>
#include "Cbros.h"
#include "Engineer.h"
#include "Club.h"
#include "Chics.h"
using namespace std;

int main(){
Club Club1;
Club1.displayMenu();
Club1.processInput();

return 0;

}
Last edited on
Topic archived. No new replies allowed.