help with fruits!

How can I get the main() to accept all of the class members so I can use their attributes?

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
  
#include <iostream>
using namespace std;

class fruit
{
public:
    int taste;
    int smell;
    int feel;
    
    void make(int t, int s, int f);   
};

void fruit::make(int t, int s, int f)
{
    t = taste;
    s = smell;
    f = feel;
}
void bananamake(fruit & banana);
void bananamake(fruit & banana)
{
    banana.make(7,2,8);
}
void applemake(fruit & apple);
void applemake(fruit & apple)
{
    apple.make(9,5,1);
}

void pearmake(fruit & pear);
void pearmake(fruit & pear)
{
    pear.make(10,10,10);
}

int main (/*fruit & pear, fruit & apple, fruit & banana*/)
{
    cout << "pear's taste is a " << /* pear's taste */ << endl;
    cout << "apple's feel is a " << /* apple's feel */ << endl;
    cout << "banana's smell is a " << /* banana's smell */ << endl;
}
First reread the following.

http://www.cplusplus.com/doc/tutorial/classes/
http://www.cplusplus.com/doc/tutorial/classes2/

Then follow along.

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
#include <iostream>

class fruit
{
public:
	int taste;
	int smell;
	int feel;

	void make(int, int, int);
};

void fruit::make(int t, int s, int f){
	taste = t;
	smell = s;
	feel = f;
}


int main(){
	fruit banana, apple, pear;

	banana.make(7, 3, 8);
	apple.make(9, 5, 1);
	pear.make(10, 10, 10);
	
	std::cout << "Pear's taste is a " << pear.taste << std::endl;
	std::cout << "Apple's feel is a " << apple.feel << std::endl;
	std::cout << "Banana's smell is a " << banana.smell << std::endl;
	
	return 0;
}
Topic archived. No new replies allowed.