#include ofstream fout; void make_swap_if() { fout << "void swap_if(int & x, int & y)\n"; fout << "{ if (x > y)\n"; fout << " { int temp = x;\n"; fout << " x = y;\n"; fout << " y = temp; } }\n\n"; } char variable_name(int n) { const string alphabet = "abcdefghijklmnopqrstuvwxyz"; return alphabet[n - 1]; } void make_one_swap(int v1, int v2) { fout << "swap_if(" << variable_name(v1) << ", " << variable_name(v2) << "); "; } void make_one_swap_line(int n) { fout << " "; int v = 1; while (v <= n) { make_one_swap(v, v+1); v = v + 1; } fout << "\n"; } void main() { int num; cout << "How many variables to be sorted? "; cin >> num; fout.open("sorting.cpp"); fout << "#include \n\n"; make_swap_if(); fout << "void main()\n"; fout << "{\n"; int v = 1; while (v <= num) { fout << " int " << variable_name(v) << " = random_in_range(1, 99);\n"; v = v + 1; } v = num - 1; while (v >= 1) { make_one_swap_line(v); v = v - 1; } fout << "\n"; v = 1; while (v <= num) { fout << " cout << " << variable_name(v) << " << \" \";\n"; v = v + 1; } fout << " cout << \"\\n\";\n"; fout << "}\n\n"; fout.close(); }