-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt.h
More file actions
86 lines (73 loc) · 2.94 KB
/
prompt.h
File metadata and controls
86 lines (73 loc) · 2.94 KB
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
#pragma once
#ifndef _PROMPT_H
#define _PROMPT_H
#include <string>
// facilitates prompting for int, double or string
//
// each function has a PromptlnXXX equivalent that reads a line of
// text
//
// PromptRange: used for int or double entry
//
// int PromptRange(const string & prompt,int low, int high)
// -- returns int in range [low..high]
// Example:
// int x = PromptRange("enter weekday",1,7);
//
// generates prompt: enter weekday between 1 and 7
//
// double PromptRange(const string & prompt,double low, double high)
// -- returns int in range [low..high]
// Example:
// double d = PromptRange("enter value",0.5,1.5);
//
// generates prompt: enter value between 0.5 and 1.5
//
// const string & promptString(const string & prompt)
// -- returns a string
// Example:
// string filename = PromptString("enter file name");
//
// bool PromptYesNo(const string & prompt)
// -- returns true iff user enter yes
// (or any string beginning with y, only strings beginning with y or
// n are accepted)
//
// Example:
// if (PromptYesNo("continue?"))
// DoStuff();
// else
// Quit();
long int PromptRange(const std::string & prompt,long int low, long int high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
long int PromptlnRange(const std::string & prompt,long int low, long int high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
// reads an entire line
int PromptRange(const std::string & prompt,int low, int high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
int PromptlnRange(const std::string & prompt,int low, int high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
// reads an entire line
double PromptRange(const std::string & prompt,double low, double high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
double PromptlnRange(const std::string & prompt,double low, double high);
// precondition: low <= high
// postcondition: returns a value between low and high (inclusive)
// reads an entire line
std::string PromptString(const std::string & prompt);
// postcondition: returns string entered by user
std::string PromptlnString(const std::string & prompt);
// postcondition: returns string entered by user, reads entire line
bool PromptYesNo(const std::string & prompt);
// postcondition: returns true iff user enters "yes" (any string with
// 'y' as first letter, only 'y' and 'n' strings accepted)
bool PromptlnYesNo(const std::string & prompt);
// postcondition: returns true iff user enters "yes" (any string with
// 'y' as first letter, only 'y' and 'n' strings accepted)
// reads entire line
#endif