c 2b 2b give options string

Solutions on MaxInterview for c 2b 2b give options string by the best coders in the world

showing results for - "c 2b 2b give options string"
Niclas
02 May 2016
1string StringOptionsBox(int count, ...)
2{
3   bool bValidSelection = 1;
4
5   do
6   {
7
8      //set the border options
9      char sczCorners = '+';
10      char sczVerticalFillers = '|';
11      char sczHorizontalFillers = '-';
12      char sczGeneralFillers = ' ';
13
14      // set the spacing options
15      int iLineWidth = 50;
16      int iOptionSpace = 25;
17      int iNumberSpace = 3;
18      int iTabSpace = 3;
19
20      int iRightSpace = iLineWidth - iOptionSpace - iNumberSpace - iTabSpace - 1;
21
22      va_list arguments; // A place to store the list of arguments
23
24      va_start(arguments, count); // Initializing arguments to store all values after count
25
26      //////////////////////////////////////////////////////////////////////////////////////
27      //            LAYOUT THE INTERFACE AND PROMPT THE USER'S SELECTION                  //
28      //////////////////////////////////////////////////////////////////////////////////////
29
30      //Top line of the output
31      cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << ""
32           << sczCorners << "\n";
33
34      //Main Lines of the output
35      for (int i = 1; i <= count; i++)
36      {
37         cout << sczVerticalFillers;
38         cout << setw(iNumberSpace) << setfill(sczGeneralFillers) << right << i << ".";
39         cout << setw(iTabSpace) << setfill(sczGeneralFillers) << left << "";
40         cout << setw(iOptionSpace) << setfill(sczGeneralFillers) << left << va_arg(arguments, char *);
41         cout << setw(iRightSpace) << setfill(sczGeneralFillers) << left << "" << sczVerticalFillers << "\n";
42      }
43
44      //Bottom line of the output
45      cout << sczCorners << setw(iLineWidth) << setfill(sczHorizontalFillers) << "" << sczCorners << "\n";
46
47      va_end(arguments); // Cleans up the list
48
49      // User's selection process
50      string sSelected;
51      cout << "\nSelect one of the above options: ";
52	std::getline(cin, sSelected);
53      //////////////////////////////////////////////////////////////////////////////////////
54      //                   RETRIEVE THE STRING THAT WAS SELECTED                          //
55      //////////////////////////////////////////////////////////////////////////////////////
56
57      va_list arguments2; // A place to store the list of arguments
58
59      va_start(arguments2, count); // Initializing arguments to store all values after count
60
61      //Main Lines of the output
62      for (int i = 1; i <= count; i++)
63      {
64         if (i == atoi(sSelected.c_str()))
65         {
66            return va_arg(arguments2, char *); // returns the string that was selected
67         }
68
69         else if (i != count)
70         {
71            va_arg(arguments2, char *);
72         }
73         else
74         {
75            va_arg(arguments2, char *);
76         }
77      }
78      va_end(arguments2);
79
80      //////////////////////////////////////////////////////////////////////////////////////
81      //              MAKE PROVISIONS FOR IF THE SELECTION IS INCORRECT                   //
82      //////////////////////////////////////////////////////////////////////////////////////
83
84      cout << "\nERROR \nThe option that you have selected - " << sSelected << " - does not exist. Please try again. \n\n";
85      bValidSelection = 0;
86
87   } while (bValidSelection != 1);
88}
89