Advertisement
Guest User

Homework 3

a guest
Feb 8th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //initiate variables
  10.     int choice, num;
  11.     string name, art;
  12.  
  13.     //print instructions to console
  14.     cout << "Please choose:" << endl;
  15.     cout << "(1)Create acii art" << endl;
  16.     cout << "(2)Create instructions" << endl;
  17.     cout << "<";
  18.     //user input for choice
  19.     cin >> choice;
  20.     //distinguish between creating art or instr.
  21.     switch (choice)
  22.     {
  23.         //Creating Art
  24.         case 1:
  25.         {
  26.             //Retrieving input file
  27.             cout << "File Name: ";
  28.             cin >> name;
  29.             ifstream infile(name.c_str());
  30.             //Creating output file
  31.             name = name.substr(0,name.length()-4);
  32.             name = name.append("_art.txt");
  33.             ofstream outfile(name.c_str());
  34.             //Loop through file
  35.             while(!infile.eof())
  36.             {
  37.                     //Ignore characters that describe # of line
  38.                     infile >> art;
  39.                     infile >> art;
  40.                     //Loop through line
  41.                     infile >> num;
  42.                     infile >> art;
  43.                     //loop for writing art to file
  44.                     for (int i =0; i < num; i++)
  45.                     {
  46.                         //if "sp" print space
  47.                         if (art.substr(0, art.length()-1) == "sp")
  48.                         {
  49.                             outfile << " ";
  50.                         }
  51.                         //otherwise print the given char
  52.                         else
  53.                         {
  54.                             outfile << art;
  55.                         }
  56.                     }
  57.                 }
  58.                 break;
  59.             }
  60.         }
  61.         //Creating Instr
  62.         case 2:
  63.         {
  64.            
  65.             break;
  66.         }
  67.     }
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement