Question

l. Write a new program (hw6-prl) meeting at least the following minimum requirements Opens the text version of this file hw6-Spring2017.txt) and searches thru the file for the first occurrence of each of the 26 uppercase characters of the alphabet (A-Z), then each the 10 digits (0-9), and finally each of the 26 lowercase characters of the alphabet (a-z). As it finds each of these characters it should also record its position in the file (assume the first character in the file is in position 1). If the character or digit is not found in the file then it should be recorded a Not Found [HINT!! Use location 0 to indicate Not Found). Display (5 per line) each of the alphanumeric characters (in the same order the search was done) immediately followed by its location in the file. Use exactly 10 columns to display e character/location pair as follows: character, l space, 6 digit location with no leading zeros, 2 spaces. For Not Found characters display location as NotFnd. NOTE!!!! You MUST specify in your testing doc how you are handling Whitespace in the file (i.e. skipping or counting) EXTRA CREDIT (20 points): Display (5 per line each of the alphanumeric characters (in the order they were found in the file) immediately followed by its location in the file. Use exactly 10 columns to display each character location pair as follows: character, 1 space, 6 digit location with no leading zeros, 2 spaces. Not Found characters should be displayed at the beginning of the list with location shown as NotFnd 2. Write a new program (hw6-pr2) meeting at least the following minimum requirements: Prompt the user to enter a string of 9 characters consisting of 4 digits (0-9), followed by a period 0, followed by 4 more digits (0-9), e.g. 1234.5678 Be sure to check for a correctly formatted input. Convert the input string into two integers (one from the first 4 digits and one from the last 4 digits) and one double (from the entire string). [HINT!! ostringstream could play a role in doing this]. Display the resulting values (all on one line) Display each of the two integers in the following formats: decimal, octal (starting with 0) and hexadecimal (starting with 0x). Put all 3 versions of each integer on the same line in columns 10 characters wide (i.e. use two lines of display for the two integers) Display the double in the following formats: defaultfloat, fixed and scientific. Put all 3 versions of the double on the same line in columns 20 characters wide. Do this twice, first with the default precision, and then using a precision of 8 Capture each of the four lines displayed above (two integer version lines and two double version lines) into a string and then display the string. The displayed lines should be identical to those previously displayed. [HINT!! eam could play a role in doing th
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream in("hw6-Spring2017.txt");
if(!in)
{
cout << "Cannot open input file.\n";
return 1;
}
char str[255][255];
int i=0;
while(in)
{
in.getline(str[i++], 255); // delim defaults to '\n'
}

for(int j=65; j<=90; j++)
{
bool status = false;
int pos = 0;
for(int k=0; k<i; k++)
{
for(int l=0; str[k][l] != '\0'; l++)
{
pos++;
int temp = str[k][l];
if(temp == j)
{
status = true;
break;
}
}
if(status == true)
break;
}
char ch = j;
cout<<"Character: "<<ch;
if(status)
cout<<" Position: "<<pos<<endl;
else
cout<<" Position: 0"<<endl;
}
  
  
for(int j=48; j<=57; j++)
{
bool status = false;
int pos = 0;
for(int k=0; k<i; k++)
{
for(int l=0; str[k][l] != '\0'; l++)
{
pos++;
int temp = str[k][l];
if(temp == j)
{
status = true;
break;
}
}
if(status == true)
break;
}
char ch = j;
cout<<"Character: "<<ch;
if(status)
cout<<" Position: "<<pos<<endl;
else
cout<<" Position: 0"<<endl;
}
  

for(int j=97; j<=122; j++)
{
bool status = false;
int pos = 0;
for(int k=0; k<i; k++)
{
for(int l=0; str[k][l] != '\0'; l++)
{
pos++;
int temp = str[k][l];
if(temp == j)
{
status = true;
break;
}
}
if(status == true)
break;
}
char ch = j;
cout<<"Character: "<<ch;
if(status)
cout<<" Position: "<<pos<<endl;
else
cout<<" Position: 0"<<endl;
}
in.close();
return 0;
}

***Please note: Blank space and other special characters are skipped.

Sample input file:

Sabrina Sidney (1757–1843) was a British foundling girl taken in when she was 12 by the author Thomas Day,
who wanted to mould her into his perfect wife. As an adult she worked with the schoolmaster Charles Burney,
managing his schools. In 1769 Day took Sabrina to France to begin methods of education inspired by Rousseau's Emile,
or On Education. When she reached her teenage years, Day's friend Richard Lovell Edgeworth persuaded him that his
ideal-wife experiment had failed. In 1783 Sabrina was told the truth about Day's experiment and confronted him
in a series of letters. In 1804, Anna Seward published a book about Sabrina's upbringing. In his 1820 memoirs,
Edgeworth said that Sabrina and Day made a good match and that she loved him. Sabrina countered that Day had
made her miserable, and that she had effectively been a slave. The story of Sabrina's life has been told in Wendy
Moore's 2013 book How to Create the Perfect Wife and dramatised in the 2015 BBC Radio 4 play The Imperfect Education of Sabrina Sidney.

Sample output:

Character: A Position: 157
Character: B Position: 36
Character: C Position: 202
Character: D Position: 105
Character: E Position: 328
Character: F Position: 268
Character: G Position: 0
Character: H Position: 912
Character: I Position: 240
Character: J Position: 0
Character: K Position: 0
Character: L Position: 409
Character: M Position: 894
Character: N Position: 0
Character: O Position: 338
Character: P Position: 930
Character: Q Position: 0
Character: R Position: 317
Character: S Position: 1
Character: T Position: 98
Character: U Position: 0
Character: V Position: 0
Character: W Position: 352
Character: X Position: 0
Character: Y Position: 0
Character: Z Position: 0
Character: 0 Position: 589
Character: 1 Position: 17
Character: 2 Position: 82
Character: 3 Position: 27
Character: 4 Position: 26
Character: 5 Position: 19
Character: 6 Position: 245
Character: 7 Position: 18
Character: 8 Position: 25
Character: 9 Position: 246
Character: a Position: 2
Character: b Position: 3
Character: c Position: 148
Character: d Position: 11
Character: e Position: 13
Character: f Position: 44
Character: g Position: 52
Character: h Position: 42
Character: i Position: 5
Character: j Position: 0
Character: k Position: 61
Character: l Position: 49
Character: m Position: 101
Character: n Position: 6
Character: o Position: 45
Character: p Position: 143
Character: q Position: 0
Character: r Position: 4
Character: s Position: 32
Character: t Position: 39
Character: u Position: 46
Character: v Position: 411
Character: w Position: 30
Character: x Position: 461
Character: y Position: 14
Character: z Position: 0

Scareenshot:

Default Term +Browser Character: 6 Position: 245 Character: 7 Position: 18 Character: 8 Position: 25 Character: 9Position: 24

Add a comment
Know the answer?
Add Answer to:
Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT