Practical_11 (1).docx - UECS1643 Fundamentals Of Programming Practical 11 \u2013 refer to Topics 20 and 21 Part A(Understanding Concepts 1 Open notepad

Practical_11 (1).docx - UECS1643 Fundamentals Of...

This preview shows page 1 - 4 out of 11 pages.

UECS1643 Fundamentals Of Programming Practical 11 – refer to Topics 20 and 21 Part A (Understanding Concepts) 1. Open notepad, type the following content and save it as “ inputstring.txt ” to the same folder where your source file is placed. Copy and paste the following code as the source file and run it. #include <iostream> #include <fstream> #include <cstring> using namespace std; int main() { char line[51]; ifstream inFile( "inputstring.txt" ); ofstream outFile( "outputstring.txt" ); if (!inFile || !outFile) { if (!inFile) cout << "Error opening input file\n" ; if (!outFile) cout << "Error opening output file\n" ; } else { inFile.getline(line, 51); while (inFile) { int len = strlen(line); for ( int i = 0; i < len; i++) line[i] = toupper(line[i]); outFile << line << endl; inFile.getline(line, 51); } inFile.close(); outFile.close(); } return 0; } An apple a day keeps the doctor away. A stitch in time saves nine. More haste less speed. 1
Image of page 1
UECS1643 Fundamentals Of Programming (a) Where is the output file “outputstring.txt” stored to? (b) Modify the highlighted code so that the output file is saved to your thumb drive instead. (c) What is stored in the output file? (d) Modify the code inside the whileloop so that you will get the following output file content (the case of the letters is inverted and the punctuation marks are discarded and replaced by whitespaces): ; 2
Image of page 2
UECS1643 Fundamentals Of Programming }
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 11 pages?

  • Spring '15
  • Input/output

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture