code concept

Need help pointing out where/if these are applied:
The heap
Constructor overloading
Private/protected data members/functions
Functions, parameters, return values

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

using namespace std;

class RandomNumberGenerator
{
	int secretNumber;
	int tries;
	int guess;

public:
	RandomNumberGenerator()
	{
		tries=0;
		secretNumber=randomNumber(100); 
	}

	int randomNumber(int max)
	{
		return (rand() % max + 1); // random number between 1 and 100
	}

	void guessprocedure()
	{
		cout << "\tWelcome to Guess My Number\n\n";
		do
		{
			cout << "Enter a guess: ";
			cin >> guess;
			++tries;
			if (guess > secretNumber)
			{
				cout << "Too high!\n\n";
			}
			else if (guess < secretNumber)
			{
				cout << "Too low!\n\n";
			}
			else
			{
				cout << "\nThat's it! You got it in " << tries << "guesses!\n";
			}
		} while (guess != secretNumber);
	}
};

int main()
{
	RandomNumberGenerator rng;		
	rng.guessprocedure();
	return 0;
}
chris222 wrote:
The heap
Constructor overloading
Nowhere
chris222 wrote:
Private/protected data members/functions
Lines 9-11
chris222 wrote:
Functions, parameters, return values
Everywhere
Constructor overloading - no
Private/protected member variables/functions - yes
Functions, parameters, return values - yes

Note: any variable whose memory is allocated dynamically, is kept on the heap.

Aceix.
Last edited on
any static, global variable, and any variable whose memory is allocated dynamically, is kept on the heap.


Static and global variables do not reside on the heap.
@cire
Ok edited that

Aceix.
Topic archived. No new replies allowed.