HELP! This program is due on Monday. I've been at it for a week now. Can seem to get it running correctly. Tne program reads text from a file and uses functions to make a substring, check which string is larger, if they are the same, what character types are in each string and if the word in the first string is in the seond string. Please help me I'm lost.Sorry for this long code.
This is the data in my file:
Feliz Navidad!!
Happy BIRTHDAy
!my sunshine%
love love
won $500
33 today
sage message
No refun%*
chest orchestra
This is my code so far:
[code][///This program will read strings from a file.
//It will use a function to split each sctring.
//It will use a function to evaluate if the strings are the same
//It will use a function test each character in each string and check what kind
//of character it is.
//It will use a function to get the larger of two strings
//Finally it will use a function to determine if one string is a substring of another
#include<iostream>
#include<string>
#include<fstream>
#include<cctype>
using namespace std;
void split(string, string &);
bool same(string, string);
void chartype(string);
string is_larger(string, string);
bool snipsame(string, string &);
int main()
{
string first;
string second;
if(!textin.is_open()){
cout<<"unable to open the file stream textin" <<endl;
exit(1);
}
if(!textout.is_open()){
cout<<"unable to open the file stream textout" <<endl;
exit(1);
}
getline(textin, first);
while(textin){
for (string first; getline(textin,first); ) {
if ( !textin.eof() )
textout << "\n";
textout<<"the original string is "<<first<<endl;
string::size_type len;
len=first.length();
textout<<"the length of the string is "<<len<<" characters"<<endl;}
return;
}
//Function to compare the strings
bool same(string first, string second)
{
if(first==second)
return true;
return false;
}
//Function to determine the character type of each character in the string
void chartype(string first)
{
char ch;
ifstream textin("program7.txt");
ofstream textout ("program7.out");
if(!textin.is_open()){
cout<<"unable to open the file stream textin" <<endl;
exit(1);
}
if(!textout.is_open()){
cout<<"unable to open the file stream textout" <<endl;
exit(1);
}
ch=textin.get();
while(textin){
if(isalpha(ch))
textout<<ch<<" is an alphabetic character"<<endl;
else if(isdigit(ch))
textout<<ch<<" is a digit"<<endl;
else if(ispunct(ch))
textout<<ch<<" is a punctuation"<<endl;
ch=textin.get();
}
return;
}
//Function to determine which is larger. I.e which string is closer to the alphabet
string is_larger(string first, string second)
{
if(first>second)
return first;
else
return second;
}
//Function to determine if the first word of the original string is found
//in the second string for example if 'sage' is found in 'message'
bool snipsame(string first, string &second)
{
string::size_type pos;
int len;
This is my output:
F is an alphabetic character
e is an alphabetic character
l is an alphabetic character
i is an alphabetic character
z is an alphabetic character
N is an alphabetic character
a is an alphabetic character
v is an alphabetic character
i is an alphabetic character
d is an alphabetic character
a is an alphabetic character
d is an alphabetic character
! is a punctuation
! is a punctuation
H is an alphabetic character
a is an alphabetic character
p is an alphabetic character
p is an alphabetic character
y is an alphabetic character
B is an alphabetic character
I is an alphabetic character
R is an alphabetic character
T is an alphabetic charThe larger string is Feliz Navidad!!
is an alphabetic character
A is an alphabetic character
y is an alphabetic character
! is a punctuation
m is an alphabetic character
y is an alphabetic character
s is an alphabetic character
u is an alphabetic character
n is an alphabetic character
s is an alphabetic character
h is an alphabetic character
i is an alphabetic character
n is an alphabetic character
e is an alphabetic character
% is a punctuation
l is an alphabetic character
o is an alphabetic character
v is an alphabetic character
e is an alphabetic character
l is an alphabetic character
o is an alphabetic character
v is an alphabetic character
e is an alphabetic character
w is an alphabetic character
o is an alphabetic character
n is an alphabetic character
$ is a punctuation
5 is a digit
0 is a digit
0 is a digit
3 is a digit
3 is a digit
t is an alphabetic character
o is an alphabetic character
d is an alphabetic character
a is an alphabetic character
y is an alphabetic character
s is an alphabetic character
a is an alphabetic character
g is an alphabetic character
e is an alphabetic character
m is an alphabetic character
e is an alphabetic character
s is an alphabetic character
s is an alphabetic character
a is an alphabetic character
g is an alphabetic character
e is an alphabetic character
N is an alphabetic character
o is an alphabetic character
r is an alphabetic character
e is an alphabetic character
f is an alphabetic character
u is an alphabetic character
n is an alphabetic character
% is a punctuation
* is a punctuation
c is an alphabetic character
h is an alphabetic character
e is an alphabetic character
s is an alphabetic character
t is an alphabetic character
o is an alphabetic character
r is an alphabetic character
c is an alphabetic character
h is an alphabetic character
e is an alphabetic character
s is an alphabetic character
t is an alphabetic character
r is an alphabetic character
a is an alphabetic character
It's supposed to print the original string on one line with the length of the string. Then after calling function split(). Main will print the two strings. After calling function same() main will print if they match . If they don't then main calls function chartype() to check the character type for each character in the string, it will also call is_larger to see which string is larger i.e closer to the end of the alphabet. Function snipsame () will check if the word in the first string is part of the second string. If the function returns true, it will remove the substring from the second. IF the function returns true main should print the second string otherwise main will print ;no changes made. Finally main should concatenate the strings in reverse of the original order and print the result. My output is nowhere near this. I don't even know where to start. Please help