school/cs142/smcquay/lab08/menu.cc

31 lines
734 B
C++
Raw Normal View History

2016-04-06 20:45:34 -07:00
#include <iostream>
using namespace std;
#include "menu.h"
void get_index(people & p, unsigned int & a, string msg="") {
cout << msg;
cin >> a;
if(a >= p.size()) {
throw string("Not in range!!");
}
}
void get_two_indices(people & p, unsigned int & a, unsigned int & b) {
if(p.size() < 2) {
throw string("Not enough people to perform this operation.");
}
get_index(p, a, "enter first index: ");
get_index(p, b, "enter second index: ");
if(a == b) {
throw string("indices need to be different");
}
}
ostream & operator<<(ostream & os, const menu & m) {
for(auto i: menu_items) {
os << " " << i << endl;
}
os << "your selection: ";
return os;
}