-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion4_Final_.cpp
More file actions
89 lines (76 loc) · 2.72 KB
/
Question4_Final_.cpp
File metadata and controls
89 lines (76 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//declare variables for in stream and outstream
ifstream reading;
ofstream writing;
//declare character variables to hold input and output file names
char readFilename[11];
char writeFileName[11];
//ask user to enter the input and output file names
cout <<"Enter the name of the file to open (maximum 10 characters): ";
cin >> readFilename;
cout <<"\nEnter the name of the file to write to (maximum of 10 characters): ";
cin >> writeFileName;
//open the requested files and test whether they were opened successfully. If not, abort program
reading.open(readFilename);
if (reading.fail())
{
cout<<"\nError opening "<<readFilename<<". Program will close now.";
exit(1);
}
writing.open(writeFileName);
if (writing.fail())
{
cout << "\nError opening "<<writeFileName<<". Program will close.";
exit(1);
}
//Get the first character and make it into upper case and write to new file
char ch;
reading.get(ch);
writing<<static_cast<char>(toupper(ch));
//while loop to read the input file until end of file is reached
while(!reading.eof())
{
//get each character
reading.get(ch);
//if the character is a '5', convert it to an 's' and write to the file
if (ch == '5')
{
ch='s';
writing<<ch;
}
//check for the end of sentences
else if (ch=='.')
{
//write the period to the new file, then get the next character
writing<<ch;
reading.get(ch);
//if the next character is a space, then write it to the new file and get the next character
if(ch==' ')
{
writing<<ch;
reading.get(ch);
//if that character is a five, convert it to an 's'
if (ch == '5')
{
ch='s';
}
//convert the character to an upper case letter and write to the new file
writing<<static_cast<char>(toupper(ch));
}
}
else
//if it is neither a 5 nor the start of a new sentence, simply write to a new file as is
writing<<ch;
}
//close the files
reading.close();
writing.close();
return 0;
}