Help with parameter of a function

Question: what is this string promt my teacher keeps using

I just got hired as a firefighter and I would need to take this class again but since I do hope to one day make my own programs for sound engineering i am still trying to learn. I have been reading the book all night and asking my friend who is a senior programmer but he just gets mad at me for not understanding lmao.

So my teacher made this header file with tools prototypes
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
  #include<string>
//using namespace std;

#ifndef TOOLS_LOCK
#define TOOLS_LOCK

namespace tools_namespace
{
	extern const int SCREEN_WIDTH;

	std::string	swab( char value, int howMany );
	void	pause( std::string prompt );
	void	flush(void);
	int		getInt			( std::string prompt );
	float	getFloat		( std::string prompt );
	char	getChar			( std::string prompt );
	std::string	getString	( std::string prompt );
	std::string	getLine		( std::string prompt );
	bool	getBool			( std::string prompt );
	int		getBoundedInt	( std::string prompt,
								int lowerBound,
								int upperBound );
	int getPositiveInt		( std::string prompt );
	int getNonNegativeInt	( std::string prompt );
	void handleInputError	( std::string message );

	int width		( int number );
	int magnitude	( int value );
	int minimum( int a, int b );
	int maximum( int a, int b );

	bool isOdd( int value );
}

#endif 


Now here is the tools.cpp with the actual tools with the math. Im about to take a test later and we have to use his getNonNegativeInt function found at line 123. if someone could explain how this works I would be super greatful. the thing throwing me off is this "string prompt" crap everywhere in this code.

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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#include<string>
#include<iostream>
#include"Tools.h"
#include"CompileSwitches.h"
using namespace std;

namespace tools_namespace
{
	const int SCREEN_WIDTH = 80;

	string swab( char swabValue, int howMany )
	{
		string swabString;
		for ( int charsNeeded = howMany
				; charsNeeded > 0
				; --charsNeeded )
			swabString = swabString + swabValue;
		return swabString;
	}

	void pause( string prompt )
	{
		cout << prompt;
		cin.ignore(999,'\n');
	}

	// clear input garbage
	void flush( void )
	{
		cin.ignore(999,'\n');
	}

	int getInt( string prompt )
	{
		int userInput;
		while (true)
		{
			cout << prompt;
			cin >> userInput;
			flush();
			if ( !cin.fail() ) break;
			handleInputError("Non-Numeric input.");
		}
		return userInput;
	}

	float getFloat( string prompt )
	{
		float userInput;
		while (true)
		{
			cout << prompt;
			cin >> userInput;
			flush();
			if ( !cin.fail() ) break;
			handleInputError("Non-Numeric input.");
		}
		return userInput;
	}

	int magnitude ( int value )
	{
		return (value>=0) ? value : -value;
	}

	int width( int number )
	{
		int digitCount = 0;
		if ( number < 0 )
		{
			++digitCount; // for the sign
			number = -number;
		}
		for ( ; number >= 10 ; number /= 10 )
			++digitCount;
		++digitCount; // for the last digit
		return digitCount;
	}

	int minimum( int a, int b )
	{
		return ( a < b ) ? a : b;
		//if ( a < b )
		//	return a;
		//else
		//	return b;
	}

	int maximum( int a, int b )
	{
		return ( a > b ) ? a : b;
		//if ( a < b )
		//	return a;
		//else
		//	return b;
	}

	int getBoundedInt( string prompt,
						int lowerBound, int higherBound )
	{
		int userInput;
		while (true)
		{
			userInput = getInt( prompt );
			if ( userInput >= lowerBound
					&& userInput <= higherBound )
				break;
			cout << "Value must be in the range "
					<< lowerBound
					<< "..."
					<< higherBound
					<< ". Try again."
					<< endl;
		}
		return userInput;
	}

	int getPositiveInt( string prompt )
	{
		return getBoundedInt( prompt, 1, INT_MAX );
	}

	int getNonNegativeInt( string prompt )
	{
		return getBoundedInt( prompt, 0, INT_MAX );
	}

	char getChar( string prompt )
	{
		char userInput;
		while (true)
		{
			cout << prompt;
			cin >> userInput;
			flush();
			if ( !cin.fail() ) break;
			handleInputError("Input failed.");
		}
		return userInput;
	}

	string getString( string prompt )
	{
		string userInput;
		while (true)
		{
			cout << prompt;
			cin >> userInput;
			flush();
			if ( !cin.fail() ) break;
			handleInputError("Input failed.");
		}
		return userInput;
	}

	void handleInputError( string message )
	{
		cin.clear();
		flush();
		cout << message << " Try again." << endl;
	}

	string getLine( string prompt )
	{
		string userInput;
		while (true)
		{
			cout << prompt;
			getline(cin,userInput);
			if ( !cin.fail() ) break;
			cin.clear();
			flush();
			cout << "Input failed - Try again." << endl;
		}
		return userInput;
	}

	bool getBool( string prompt )
	{
		while (true)
		{
			char userInput = getChar(prompt);
			if ( userInput == 'y' || userInput == 'Y' )
				return true;
			if ( userInput == 'n' || userInput == 'N' )
				return false;
			cout << "Please enter y or n." << endl;
		}
	}

	bool isOdd( int aNumber )
	{
#ifndef GROSS
		return magnitude(aNumber)%2 == 1;
#else
		if ( aNumber < 0 )
			aNumber = -aNumber;
		int remainder = aNumber%2;
		if ( remainder == 1 || remainder == -1)
			return true;
		else if ( remainder != 1 )
			return false;
#endif
	}
}

the thing throwing me off is this "string prompt" crap everywhere in this code.

string prompt is passed as an argument to a number of functions.

In each of these functions, the code does a cout << prompt; This allows the various functions to output a variable prompt. In a few cases, prompt is passed to a lower level function. Example:
1
2
3
  float f1, f2; 
  f1 = get_float ("Enter first float");
  f2 = get_float ("Enter second float");

Last edited on
Topic archived. No new replies allowed.