// Sample program that prompts for an int and a double and that produces output // files named using the int and double that have a list of primes. #include #include #include #include #include using namespace std; // returns a string version of the given int string int_to_string(int n) { ostringstream out; out << n; return out.str(); } // returns a string version of the given double string double_to_string(double n) { ostringstream out; out << n; return out.str(); } // returns a string version of the given vector as a comma-separated, // bracketed, list string vector_to_string(const vector & v) { ostringstream out; out << "["; if (v.size() > 0) { out << v[0]; for (int i = 1; i < v.size(); i++) { out << ", " << v[i]; } } out << "]"; return out.str(); } int main() { vector primes = {2, 3, 5, 7, 11}; // constructs vector with values cout << "give me an int: "; int n1; cin >> n1; cout << "give me a double: "; double n2; cin >> n2; ofstream out1(int_to_string(n1) + ".txt"); ofstream out2(double_to_string(n2) + ".txt"); out1 << "primes = " << vector_to_string(primes) << endl; primes.push_back(13); primes.push_back(17); out2 << "primes = " << vector_to_string(primes) << endl; return 0; }