#include #include using namespace std; ofstream fout; void print_beginning() { fout << "#include \n"; fout << "\n"; fout << "void order(int & x, int & y)\n"; fout << "{ if (x > y)\n"; fout << " { int t = x;\n"; fout << " x = y;\n"; fout << " y = t; } }\n"; fout << "\n"; fout << "int main()\n"; } void print_declarations(int n) { fout << "{ int a"; for (char i = 'b'; i < 'a' + n; i += 1) fout << ", " << i; fout << ";\n"; } void print_cins(int n) { fout << " cin"; for (char i = 'a'; i < 'a' + n; i += 1) fout << " >> " << i; fout << ";\n"; } void print_couts(int n) { fout << " cout << \"sorted = \"\n"; for (char i = 'a'; i < 'a' + n - 1; i += 1) fout << " << " << i << " << \", \"\n"; fout << " << " << (char)('a' + n - 1) << " << \"\\n\"; }\n"; } void print_order_line(char d) { fout << " "; for (char x = 'a'; x <= d; x += 1) fout << " order(" << x << ", " << (char)(x + 1) << ");"; fout << "\n"; } void main() { fout.open("test.cpp"); cout << "How many varibales to sort? "; int n; cin >> n; print_beginning(); print_declarations(n); fout << " cout << \"enter the values \";\n"; print_cins(n); for (char last = 'a' + n - 2; last >= 'a'; last -= 1) print_order_line(last); print_couts(n); fout.close(); }