Methods

I am working on an assigment for school, and I not getting how to do methods, I am to write a printFruit method that takes in 0 arguments, and simply prints out typeOfFruit, the color, and the count. Provide default values for all three fields. Also, provide a default constructor, a constructor that lets you specify all 3 arguments, and a destructor.

Can any help me Understand this in simple terms...I'm not good at C++ or Programming in general so I need all the help I can get. Please and Thank you.

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

using namespace std;

class Fruit 
{
public:

      Fruit(string typeOfFruit, string color, int count) 
	  {

             this->typeOfFruit = typeOfFruit;
	    this->color = color;
	    this->count = count;
	  }

      string gettypeOfFruit() 
	  {
  	    return typeOfFruit;
	  }

	  string getcolor() 
	  {
	    return color;
	  }

      int getcount() 
	  {
	    return count;
	  }

private:
	string typeOfFruit;
	string color;
	int count;
};
Last edited on
closed account (zb0S216C)
A function/method (depending on the context), can contain more than one statement. A function/method doesn't even have to return anything. A function/method can also contain std::cout statements as well (nudge, nudge).

Wazzak
I got nothing out of Your statement...I Started programming in C++ just last week.
You might want to look over Object Oriented stuff in the tutorial. You might even want to review the whole tutorial until you hit object orientation, to be honest.

Look, I even linked it for you!

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



Honestly, though, we might be a little... "unhelpful" when it comes to doing your homework for you. After all, it is you who needs to learn, not us. Not to be mean or anything, but learning HOW to learn is the most important skill to have, and it's the only one that can't be taught.

closed account (zb0S216C)
Shirako wrote:
I got nothing out of Your statement...I Started programming in C++ just last week. (sic)

If you didn't know what I was talking about, then maybe you should back up and relearn the basics. I'm not being harsh or anything, but I think it's best. I personally think that you're too far ahead since you started last week.

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