137k views
4 votes
Look at the code below and use the following comments to indicate the scope of the static variables or functions. Place the comment below the relevant line.

Module scope
Class scope
Function scope

#include
2
3 static const int MAX_SIZE=10;
4
5 // Return the max value
6 static double max(double d1)
7 {
8 static double lastMax = 0;
9 lastMax = (d1 > lastMax) ? d1 : lastMax;
10 return lastMax;
11 }
12
13 // Singleton class only one instance allowed
14 class Singleton
15 {
16 public:
17 static Singleton& getSingleton() { return theOne; }
18 // Returns the Singleton
19

1 Answer

7 votes

Answer:

Step-by-step explanation:

#include

static const int MAX_SIZE=10; //Class scope

// Return the max value

static double max(double d1) //Function scope

{

static double lastMax = 0; //Function scope

lastMax = (d1 > lastMax) ? d1 : lastMax; //Function scope

return lastMax; //Module Scope

}

// Singleton class only one instance allowed

class Singleton

{

public:

static Singleton& getSingleton() //Function scope

{

return theOne; //Module Scope

}

// Returns the Singleton

User Pirate X
by
3.6k points